@@ -25,37 +25,50 @@ dependencies {
2525** WebSocketConfig.groovy**
2626``` groovy
2727@Configuration
28+ @EnableWebSocket
2829@EnableWebSocketMessageBroker
29- public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
30+ class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
3031
3132 @Override
32- public void configureMessageBroker(MessageBrokerRegistry config) {
33- config.enableSimpleBroker("/topic");
34- config.setApplicationDestinationPrefixes("/app");
33+ void configureMessageBroker(MessageBrokerRegistry config) {
34+ config.enableSimpleBroker("/topic", "/queue", "/exchange");
35+ // config.enableStompBrokerRelay("/topic", "/queue", "/exchange"); // Uncomment for external message broker (ActiveMQ, RabbitMQ)
36+ config.setApplicationDestinationPrefixes("/topic", "/queue"); // prefix in client queries
37+ config.setUserDestinationPrefix("/user");
3538 }
3639
3740 @Override
38- public void registerStompEndpoints(StompEndpointRegistry registry) {
39- registry.addEndpoint("/hello")/*.setAllowedOrigins('*')*/. withSockJS();
41+ void registerStompEndpoints(StompEndpointRegistry registry) {
42+ registry.addEndpoint("/example-endpoint"). withSockJS()
4043 }
4144
45+ @Override
46+ void configureWebSocketTransport(WebSocketTransportRegistration registration) {
47+ registration.setMessageSizeLimit(8 * 1024);
48+ }
4249}
4350```
4451
45- ** HelloSockController .groovy**
52+ ** SocketController .groovy**
4653``` groovy
54+ @Log4j
4755@RestController
48- class HelloSockController {
56+ class SocketController {
57+
58+ @Autowired
59+ SocketService socketService
4960
50- @MessageMapping(" /hello" )
51- @SendTo(" /topic/greetings" )
52- def greeting (String msg) throws Exception {
53- println("Receive greeting ${ msg} ")
54- "ECHO: " + msg;
61+ @MessageMapping(' /hello-msg-mapping' )
62+ @SendTo(' /topic/greetings' )
63+ EchoModel echoMessageMapping (String message) {
64+ log.debug("React to hello- msg-mapping ")
65+ return new EchoModel(message.trim())
5566 }
5667}
5768```
5869
70+ Check out the full example server https://github.com/NaikSoftware/stomp-protocol-example-server
71+
5972## Example library usage
6073
6174** Basic usage**
@@ -64,21 +77,23 @@ class HelloSockController {
6477
6578 // ...
6679
67- mStompClient = Stomp . over(WebSocket . class, " ws://localhost :8080/app/hello /websocket" );
80+ mStompClient = Stomp . over(WebSocket . class, " ws://10.0.2.2 :8080/example-endpoint /websocket" );
6881 mStompClient. connect();
6982
7083 mStompClient. topic(" /topic/greetings" ). subscribe(topicMessage - > {
7184 Log . d(TAG , topicMessage. getPayload());
7285 });
7386
74- mStompClient. send(" /app /hello" , " My first STOMP message!" ). subscribe();
87+ mStompClient. send(" /topic /hello-msg-mapping " , " My first STOMP message!" ). subscribe();
7588
7689 // ...
7790
7891 mStompClient. disconnect();
7992
8093```
8194
95+ See the full example https://github.com/NaikSoftware/StompProtocolAndroid/tree/master/example-client
96+
8297Method ` Stomp.over ` consume class for create connection as first parameter.
8398You must provide dependency for lib and pass class.
8499At now supported connection providers:
0 commit comments