title: How to receive the message from stomp websocket with spring boot on android?
body: <p>I've got the simple WebSocket example from <a href="https://spring.io/guides/gs/messaging-stomp-websocket/" rel="nofollow noreferrer">https://spring.io/guides/gs/messaging-stomp-websocket/</a></p>
  <pre class="lang-java prettyprint-override"><code>package com.example.chatservice.message;
  
  import org.springframework.context.annotation.Configuration;
  import org.springframework.messaging.simp.config.MessageBrokerRegistry;
  import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
  import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
  import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
  
  @Configuration
  @EnableWebSocketMessageBroker
  public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
  
      @Override
      public void configureMessageBroker(MessageBrokerRegistry config) {
          config.enableSimpleBroker(&quot;/topic&quot;);
          config.setApplicationDestinationPrefixes(&quot;/app&quot;);
      }
  
      @Override
      public void registerStompEndpoints(StompEndpointRegistry registry) {
          registry.addEndpoint(&quot;/gs-guide-websocket&quot;).withSockJS();
      }
  }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>@Controller
  public class ChatController {
      @MessageMapping(&quot;/hello&quot;)
      @SendTo(&quot;/topic/greetings&quot;)
      public Greeting greeting(HelloMessage message) throws Exception {
          return new Greeting(&quot;Hello from chat!&quot;);
      }
  }
  </code></pre>
  <p>and I'd like to receive the <code>Greeting</code> message from the spring server to an android app. I use <a href="https://github.com/NaikSoftware/StompProtocolAndroid" rel="nofollow noreferrer">https://github.com/NaikSoftware/StompProtocolAndroid</a> as a stomp client</p>
  <pre class="lang-java prettyprint-override"><code>package com.example.chatapp;
  
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.Button;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import org.java_websocket.WebSocket;
  
  import ua.naiksoftware.stomp.Stomp;
  import ua.naiksoftware.stomp.client.StompClient;
  
  public class MainActivity extends AppCompatActivity {
      private StompClient mStompClient;
      public static  final String TAG=&quot;StompClient&quot;;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Button view = (Button) findViewById(R.id.send_message);
          view.setOnClickListener(e-&gt;  new StompTask().execute(&quot;&quot;));
      }
  
      private static class StompTask extends AsyncTask&lt;String, Void, String&gt; {
          private StompClient mStompClient;
          String TAG=&quot;LongOperation&quot;;
  
          @Override
          protected String doInBackground(String... params) {
              mStompClient = Stomp.over(WebSocket.class, &quot;http://10.0.2.2:8080/gs-guide-websocket/websocket&quot;);
              mStompClient.connect();
  
              mStompClient.topic(&quot;/topic/greetings&quot;).subscribe(topicMessage -&gt; {
                  Log.d(TAG, topicMessage.getPayload());
              });
  
              mStompClient.lifecycle().subscribe(lifecycleEvent -&gt; {
                  switch (lifecycleEvent.getType()) {
  
                      case OPENED:
                          Log.d(TAG, &quot;Stomp connection opened&quot;);
                          break;
  
                      case ERROR:
                          Log.e(TAG, &quot;Error&quot;, lifecycleEvent.getException());
                          break;
  
                      case CLOSED:
                          Log.d(TAG, &quot;Stomp connection closed&quot;);
                          break;
                  }
              });
  
              return &quot;Executed&quot;;
          }
      }
  }
  </code></pre>
  <p>and the connection to the</p>
  <p><code>http://10.0.2.2:8080/gs-guide-websocket/websocket</code></p>
  <p>works, because the log shows it's connected</p>
  <p><code>2022-01-18 14:04:56.486 23717-23752/com.example.chatapp D/LongOperation: Stomp connection opened</code></p>
  <p>but it does not subscribe to the topic:</p>
  <pre class="lang-java prettyprint-override"><code>mStompClient.topic(&quot;/topic/greetings&quot;).subscribe(topicMessage -&gt; {
      Log.d(TAG, topicMessage.getPayload());
  });
  </code></pre>
  <p>because when I set the breakpoint it doesn't ever hit it.</p>
  <p>how can I receive this message?</p>