title: Stomp sockjs with Spring 4 WebSocket can't connect to ActiveMQ
body: <p>I cannot manage to code a server that would listen to STOMP messages over WebSocket. </p>
  
  <p>I use sockjs + stomp js + spring 4(.0.5~.1.2~2.2) + activemq 5.13 + jdk 1.7.0_17 + tomcat 7.0.67.</p>
  
  <p>Client throws "Broker not available" error!</p>
  
  <p>client js:</p>
  
  <pre><code>var ws = new SockJS(basePath + "/websocket");
  var client = Stomp.over(ws);
  client.heartbeat.outgoing=10000;
  client.heartbeat.incoming=10000;
  client.connect({},function(frame){
      setConnect(true);
      console.log('connectd:' + frame);
      client.subscribe('/topic/ggg',function(data){
          alert(JSON.parse(data.body).content);
      });
  },function(error){
      console.log('stomp:' + error);
      setTimeout(connect,10000);
      console.log('stomp: Reconnecting in 10 seconds');
  });
  </code></pre>
  
  <p>my pom.xml : spring-*-version(4.2.2) activemq-core-version(5.7.0)</p>
  
  <pre><code>    &lt;!-- JMS begin --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-jms&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.activemq&lt;/groupId&gt;
          &lt;artifactId&gt;activemq-core&lt;/artifactId&gt;
          &lt;version&gt;${activemq.version}&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.apache.activemq.protobuf&lt;/groupId&gt;
                  &lt;artifactId&gt;activemq-protobuf&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.springframework.osgi&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-osgi-core&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.osgi&lt;/groupId&gt;
                  &lt;artifactId&gt;org.osgi.core&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.fusesource.mqtt-client&lt;/groupId&gt;
                  &lt;artifactId&gt;mqtt-client&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;commons-logging&lt;/groupId&gt;
                  &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;!-- JMS end --&gt;
      &lt;!-- websocket --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-websocket&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-messaging&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.projectreactor&lt;/groupId&gt;
          &lt;artifactId&gt;reactor-core&lt;/artifactId&gt;
          &lt;version&gt;2.0.7.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.projectreactor&lt;/groupId&gt;
          &lt;artifactId&gt;reactor-net&lt;/artifactId&gt;
          &lt;version&gt;2.0.7.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.projectreactor.spring&lt;/groupId&gt;
          &lt;artifactId&gt;reactor-spring-context&lt;/artifactId&gt;
          &lt;version&gt;2.0.7.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.netty&lt;/groupId&gt;
          &lt;artifactId&gt;netty-all&lt;/artifactId&gt;
          &lt;version&gt;4.0.33.Final&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>config.java</p>
  
  <pre><code>@Configuration
  @EnableWebSocketMessageBroker 
  @DependsOn({"applicationProperties"})
  public class WebSocketConfig implements WebSocketMessageBrokerConfigurer{
  
  @Override
  public void addArgumentResolvers(List&lt;HandlerMethodArgumentResolver&gt; arg0) {
  
  }
  
  @Override
  public void addReturnValueHandlers(List&lt;HandlerMethodReturnValueHandler&gt;     arg0) {
  
  }
  
  @Override
  public void configureClientInboundChannel(ChannelRegistration registration)  {
       registration.taskExecutor().corePoolSize(4) 
                      .maxPoolSize(8)
                      .keepAliveSeconds(60);
  }
  
  @Override
  public void configureClientOutboundChannel(ChannelRegistration registration) {
       registration.taskExecutor().corePoolSize(4).maxPoolSize(8);
  }
  
  @Override
  public void configureMessageBroker(MessageBrokerRegistry registry) {
       registry.enableStompBrokerRelay("/topic")
  .setRelayHost(ApplicationProperties.getProproperty("jms.websocket.ip"))
  .setRelayPort(Integer.valueOf(ApplicationProperties.getProproperty("jms.websocket.port"))) 
               .setSystemHeartbeatReceiveInterval(2000) 
               .setSystemHeartbeatSendInterval(2000); 
       registry.setApplicationDestinationPrefixes("/ws");
  }
  
  @Override
  public boolean configureMessageConverters(List&lt;MessageConverter&gt; arg0) {
      return true;
  }
  
  @Override
  public void configureWebSocketTransport(WebSocketTransportRegistration   registry) {
      registry.setMessageSizeLimit(8192)
              .setSendBufferSizeLimit(8192)
              .setSendTimeLimit(10000);
  }
  
  @Override
  public void registerStompEndpoints(StompEndpointRegistry registry) {
       registry.addEndpoint("/websocket")
              .withSockJS();
  }
  }
  </code></pre>
  
  <p>application.properties</p>
  
  <pre><code>jms.broker_url=tcp://127.0.0.1:61616
  jms.websocket.ip=stomp://127.0.0.1
  jms.websocket.port=61613
  </code></pre>
  
  <p>configed this code,then I  run activemq ,run tomcat,open chrome for url</p>
  
  <p>console log:</p>
  
  <pre><code>Opening web socket...
  web socket opened...
  &gt;&gt;&gt;CONNECT
  accept-version:1.1,1.0
  heart-beat:10000,10000
  
  &lt;&lt;&lt;ERROR
  message:Broker not avalibale.
  content-length:0
  
  stomp:ERROR
  content-length:0
  message:Broker not available.
  
  stomp:Reconnecting in 10 seconds
  Whoops! lost connection to http://localhost:8080/example/websocket
  </code></pre>
  
  <p>activemq conf:</p>
  
  <pre><code>&lt;transportConnectors&gt;
          &lt;!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB --&gt;
          &lt;transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;amp;wireFormat.maxFrameSize=104857600"/&gt;
          &lt;transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;amp;wireFormat.maxFrameSize=104857600"/&gt;
          &lt;transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;amp;wireFormat.maxFrameSize=104857600"/&gt;
          &lt;transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;amp;wireFormat.maxFrameSize=104857600"/&gt;
          &lt;transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;amp;wireFormat.maxFrameSize=104857600"/&gt;
      &lt;/transportConnectors&gt;
  </code></pre>
  
  <p>when I use spring JmsTemplate sendTopic() is ok,MQ is received!</p>
  
  <p>I traced code StompBrokerRelayMessageHandler &amp; AbstractBrokerMessageHandler find that isBrokerAvailable() method return false! But mq is running!</p>
  
  <p>How can i set brokerAvailable is true?</p>
  
  <p>Reactor2TcpClient is not support ActiveMQ? Why i must be set transport protocol  stomp:// if not throws error....</p>
  
  <p>Can you please point out the issue with this code? How to configure programmatically to a topic over WebSocket/Stomp with AMQ?</p>
  
  <p>ths!</p>