title: Spring Web Socket - notify the client from the MQ Listener
body: <p>I am using web-sockets using Spring.</p>
  
  <p>Here is my controller. A simple controller, which would accept a result object and return a result object with populated values. It would publish message to the STOMP topic subscribers "/topic/update".</p>
  
  <pre><code>@Controller
  public class ReportController {
  
      @MessageMapping("/charthandler")
      @SendTo("/topic/update")
      public Result pushMessage(Result r) throws Exception {
          Thread.sleep(3000); // simulated delay
          Result result = new Result();
          result.setTitle("ChartsPage");
          return result;
      }
  
  }
  </code></pre>
  
  <p>My Spring Configuration file:</p>
  
  <pre><code>@Configuration
  @EnableWebSocketMessageBroker
  public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
  
      @Override
      public void registerStompEndpoints(StompEndpointRegistry registry) {
          registry.addEndpoint("/charthandler").withSockJS();
      }
  
      @Bean
      public WebSocketHandler chartHandler() {
          return new ChartHandler();
      }
  
      @Override
      public void configureMessageBroker(MessageBrokerRegistry config) {
          config.enableSimpleBroker("/topic");
          config.setApplicationDestinationPrefixes("/app");
      }
  
  }
  </code></pre>
  
  <p>I have the following code in javascript, which creates a STOMP Web Socket Client. It is subscribing to the '/topic/update'</p>
  
  <pre><code>var socket = new SockJS('/reportapplication/charthandler/');
  stompClient = Stomp.over(socket);
  stompClient.connect({}, function(frame) {
    console.log('Connected: ' + frame);
    stompClient.subscribe('/topic/update', function(result) {
      console.log(JSON.parse(result.body).title);
    });
  });
  </code></pre>
  
  <p>Now i am planning to add a listener(java and not in javascript) which would listen to the Rabbit MQ message,  i want to pass the message object to my controller and push all the message to the Web Socket Clients. </p>
  
  <p>I am not sure how to notify all my web-socket clients , when the message is arrived at my MQ listener.
  How will i do that?</p>
  
  <p>Is it a good way to create an instance of report controller and call the pushMessage to notify all my web socket clients.</p>
  
  <pre><code>ReportController controller = new ReportController();
  controller.pushMessage(report);
  </code></pre>
  
  <p>Also i'm not sure, if this works. I will try that. I want to know if there is a better approach.</p>
  
  <p>Is there a better approach or better way of doing this?</p>