MCPcopy Index your code
hub / github.com/NaikSoftware/StompProtocolAndroid

github.com/NaikSoftware/StompProtocolAndroid @1.6.6

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.6.6 ↗ · + Follow
146 symbols 322 edges 20 files 35 documented · 24%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

STOMP protocol via WebSocket for Android

Release

Overview

This library provide support for STOMP protocol https://stomp.github.io/ At now library works only as client for backend with support STOMP, such as NodeJS (stompjs or other) or Spring Boot (SockJS).

Add library as gradle dependency

repositories { 
    jcenter()
    maven { url "https://jitpack.io" }
}
dependencies {
    implementation 'com.github.NaikSoftware:StompProtocolAndroid:{latest version}'
}

Example backend (Spring Boot)

WebSocketConfig.groovy

@Configuration
@EnableWebSocket
@EnableWebSocketMessageBroker
class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic", "/queue", "/exchange");
//        config.enableStompBrokerRelay("/topic", "/queue", "/exchange"); // Uncomment for external message broker (ActiveMQ, RabbitMQ)
        config.setApplicationDestinationPrefixes("/topic", "/queue"); // prefix in client queries
        config.setUserDestinationPrefix("/user");
    }

    @Override
    void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/example-endpoint").withSockJS()
    }
}

SocketController.groovy

@Slf4j
@RestController
class SocketController {

    @MessageMapping('/hello-msg-mapping')
    @SendTo('/topic/greetings')
    EchoModel echoMessageMapping(String message) {
        log.debug("React to hello-msg-mapping")
        return new EchoModel(message.trim())
    }
}

Check out the full example server https://github.com/NaikSoftware/stomp-protocol-example-server

Example library usage

Basic usage


 private StompClient mStompClient;

 // ...

 mStompClient = Stomp.over(Stomp.ConnectionProvider.OKHTTP, "ws://10.0.2.2:8080/example-endpoint/websocket");
 mStompClient.connect();

 mStompClient.topic("/topic/greetings").subscribe(topicMessage -> {
     Log.d(TAG, topicMessage.getPayload());
 });

 mStompClient.send("/topic/hello-msg-mapping", "My first STOMP message!").subscribe();

 // ...

 mStompClient.disconnect();

See the full example https://github.com/NaikSoftware/StompProtocolAndroid/tree/master/example-client

Method Stomp.over consume class for create connection as first parameter. You must provide dependency for lib and pass class. At now supported connection providers: - org.java_websocket.WebSocket.class ('org.java-websocket:Java-WebSocket:1.3.0') - okhttp3.WebSocket.class ('com.squareup.okhttp3:okhttp:3.8.0')

You can add own connection provider. Just implement interface ConnectionProvider. If you implement new provider, please create pull request :)

Subscribe lifecycle connection

mStompClient.lifecycle().subscribe(lifecycleEvent -> {
    switch (lifecycleEvent.getType()) {

        case OPENED:
            Log.d(TAG, "Stomp connection opened");
            break;

        case ERROR:
            Log.e(TAG, "Error", lifecycleEvent.getException());
            break;

        case CLOSED:
             Log.d(TAG, "Stomp connection closed");
             break;
    }
});

Library support just send & receive messages. ACK messages, transactions not implemented yet.

Extension points exported contracts — how you extend this code

PathMatcher (Interface)
(no doc) [6 implementers]
lib/src/main/java/ua/naiksoftware/stomp/pathmatcher/PathMatcher.java
ExampleRepository (Interface)
Created by Naik on 24.02.17.
example-client/src/main/java/ua/naiksoftware/stompclientexample/ExampleRepository.java
ConnectionProvider (Interface)
Created by naik on 05.05.16. [2 implementers]
lib/src/main/java/ua/naiksoftware/stomp/provider/ConnectionProvider.java
SendCallback (Interface)
(no doc) [1 implementers]
lib/src/main/java/ua/naiksoftware/stomp/HeartBeatTask.java
FailedListener (Interface)
(no doc)
lib/src/main/java/ua/naiksoftware/stomp/HeartBeatTask.java

Core symbols most depended-on inside this repo

emitLifecycleEvent
called by 7
lib/src/main/java/ua/naiksoftware/stomp/provider/AbstractConnectionProvider.java
toast
called by 6
example-client/src/main/java/ua/naiksoftware/stompclientexample/MainActivity.java
send
called by 6
lib/src/main/java/ua/naiksoftware/stomp/provider/ConnectionProvider.java
getConnectionStream
called by 5
lib/src/main/java/ua/naiksoftware/stomp/StompClient.java
findHeader
called by 4
lib/src/main/java/ua/naiksoftware/stomp/dto/StompMessage.java
getValue
called by 4
lib/src/main/java/ua/naiksoftware/stomp/dto/StompHeader.java
disconnect
called by 4
lib/src/main/java/ua/naiksoftware/stomp/provider/ConnectionProvider.java
resetSubscriptions
called by 3
example-client/src/main/java/ua/naiksoftware/stompclientexample/MainActivity.java

Shape

Method 121
Class 18
Interface 5
Enum 2

Languages

Java100%

Modules by API surface

lib/src/main/java/ua/naiksoftware/stomp/StompClient.java20 symbols
lib/src/main/java/ua/naiksoftware/stomp/HeartBeatTask.java19 symbols
lib/src/main/java/ua/naiksoftware/stomp/provider/OkHttpConnectionProvider.java13 symbols
lib/src/main/java/ua/naiksoftware/stomp/provider/AbstractConnectionProvider.java13 symbols
lib/src/main/java/ua/naiksoftware/stomp/provider/WebSocketsConnectionProvider.java11 symbols
example-client/src/main/java/ua/naiksoftware/stompclientexample/MainActivity.java11 symbols
lib/src/main/java/ua/naiksoftware/stomp/dto/StompMessage.java9 symbols
lib/src/main/java/ua/naiksoftware/stomp/dto/LifecycleEvent.java8 symbols
example-client/src/main/java/ua/naiksoftware/stompclientexample/SimpleAdapter.java8 symbols
lib/src/main/java/ua/naiksoftware/stomp/provider/ConnectionProvider.java5 symbols
lib/src/main/java/ua/naiksoftware/stomp/dto/StompHeader.java5 symbols
lib/src/main/java/ua/naiksoftware/stomp/Stomp.java4 symbols

For agents

$ claude mcp add StompProtocolAndroid \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact