下面的测试客户端代码(使用https://github.com/jmesnil/stomp-websocket)在JBoss 7.0.1中产生一个异常:
var client = Stomp.client("ws://192.168.0.4:61614/stomp");
client.connect("guest", "guest", function() {
client.send("/queue/test", {priority: 9}, "Hello world!");
});
client.subscribe("/queue/test", function(message) {
alert(message.body);
});
它也发生在下面的单行:
new WebSocket("ws://192.168.0.4:61614/stomp");
为什么JBoss HornetQ报告以下异常?
08:56:55,732 ERROR [org.hornetq.core.protocol.stomp.StompProtocolManager] (Old I/O server worker (parentId: 17267825, [id: 0x01077c71, france/192.168.0.4:61614])) Failed to decode: org.hornetq.core.protocol.stomp.StompException: Invalid STOMP frame: G,E,T,32,/,s,t,o,m,p,32,H,T,T,P,/,1,.,1,13,10,U,p,g,r,a,d,e,:,32,w,e,b,s,o,c,k,e,t,13,10,C,o,n,n,e,c,t,i,o,n,:,32,U,p,g,r,a,d,e,13,10,H,o,s,t,:,32,1,9,2,.,1,6,8,.,0,.,4,:,6,1,6,1,4,13,10,S,e,c,-,W,e,b,S,o,c,k,e,t,-,O,r,i,g,i,n,:,32,n,u,l,l,13,10,S,e,c,-,W,e,b,S,o,c,k,e,t,-,K,e,y,:,32,J,9,d,h,k,4,a,w,c,Z,l,y,d,p,0,k,b,X,P,u,s,Q,=,=,13,10,S,e,c,-,W,e,b,S,o,c,k,e,t,-,V,e,r,s,i,o,n,:,32,8,13,10,13,10,
at org.hornetq.core.protocol.stomp.StompDecoder.throwInvalid(StompDecoder.java:566) [hornetq-core-2.2.7.Final.jar:]
at org.hornetq.core.protocol.stomp.StompDecoder.decode(StompDecoder.java:367) [hornetq-core-2.2.7.Final.jar:]
at org.hornetq.core.protocol.stomp.StompProtocolManager.handleBuffer(StompProtocolManager.java:161) [hornetq-core-2.2.7.Final.jar:]
at org.hornetq.core.protocol.stomp.StompConnection.bufferReceived(StompConnection.java:269) [hornetq-core-2.2.7.Final.jar:]
at org.hornetq.core.remoting.server.impl.RemotingServiceImpl$DelegatingBufferHandler.bufferReceived(RemotingServiceImpl.java:458) [hornetq-core-2.2.7.Final.jar:]
at org.hornetq.core.remoting.impl.netty.HornetQChannelHandler.messageReceived(HornetQChannelHandler.java:73) [hornetq-core-2.2.7.Final.jar:]
at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:100) [netty-3.2.3.Final.jar:]
at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:362) [netty-3.2.3.Final.jar:]
at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:357) [netty-3.2.3.Final.jar:]
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274) [netty-3.2.3.Final.jar:]
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261) [netty-3.2.3.Final.jar:]
at org.jboss.netty.channel.socket.oio.OioWorker.run(OioWorker.java:90) [netty-3.2.3.Final.jar:]
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) [netty-3.2.3.Final.jar:]
at org.jboss.netty.util.internal.IoWorkerRunnable.run(IoWorkerRunnable.java:46) [netty-3.2.3.Final.jar:]
at org.jboss.netty.util.VirtualExecutorService$ChildExecutorRunnable.run(VirtualExecutorService.java:181) [netty-3.2.3.Final.jar:]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [:1.7.0]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [:1.7.0]
at java.lang.Thread.run(Thread.java:722) [:1.7.0]
查看standalone.xml (JBoss的主配置文件)
旧的hornetq-configuration.xml在消息子系统下。你所要做的就是在acceptors下面声明stomp websocket:
<acceptors>
.....
<acceptor name="stomp-websocket">
<factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
<param key="protocol" value="stomp_ws" />
<param key="port" value="61614" />
</acceptor>
</acceptors>