Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

STOMP protocol via WebSocket for Android

License

NotificationsYou must be signed in to change notification settings

NaikSoftware/StompProtocolAndroid

Repository files navigation

Release

Overview

This library provide support for STOMP protocolhttps://stomp.github.io/At now library works only as client for backend with support STOMP, such asNodeJS (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@EnableWebSocketMessageBrokerclassWebSocketConfigextendsAbstractWebSocketMessageBrokerConfigurer {@OverridevoidconfigureMessageBroker(MessageBrokerRegistryconfig) {        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");    }@OverridevoidregisterStompEndpoints(StompEndpointRegistryregistry) {        registry.addEndpoint("/example-endpoint").withSockJS()    }}

SocketController.groovy

@Slf4j@RestControllerclassSocketController {@MessageMapping('/hello-msg-mapping')@SendTo('/topic/greetings')EchoModelechoMessageMapping(Stringmessage) {        log.debug("React to hello-msg-mapping")returnnewEchoModel(message.trim())    }}

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

Example library usage

Basic usage

privateStompClientmStompClient;// ...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 examplehttps://github.com/NaikSoftware/StompProtocolAndroid/tree/master/example-client

MethodStomp.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 interfaceConnectionProvider.If you implement new provider, please create pull request :)

Subscribe lifecycle connection

mStompClient.lifecycle().subscribe(lifecycleEvent -> {switch (lifecycleEvent.getType()) {caseOPENED:Log.d(TAG,"Stomp connection opened");break;caseERROR:Log.e(TAG,"Error",lifecycleEvent.getException());break;caseCLOSED:Log.d(TAG,"Stomp connection closed");break;    }});

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

About

STOMP protocol via WebSocket for Android

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors12


[8]ページ先頭

©2009-2025 Movatter.jp