我正在使用Stomp和ActiveMQ来监听来自局域网的消息并将其发布到某些应用程序。
为了进行测试,我实现了使用TCP协议连接,但我需要使用WebSocket协议。
我的activeMQ已经配置为使用WebSocket,请参见下面的代码:
<!--
The transport connectors expose ActiveMQ over a given protocol to
clients and other brokers. For more information, see:
http://activemq.apache.org/configuring-transports.html
-->
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61623?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
但是如果我使用ws连接,对我来说就不起作用:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH:mm:ss.SSS");
String user = env("ACTIVEMQ_USER", "admin");
String password = env("ACTIVEMQ_PASSWORD", "password");
String host = env("ACTIVEMQ_HOST", "localhost");
int port = Integer.parseInt(env("ACTIVEMQ_PORT", "61623"));
String destination = arg(args, 0, "/topic/event");
String protocol = "ws://";
StompJmsConnectionFactory factory = new StompJmsConnectionFactory();
factory.setBrokerURI(protocol + host + ":" + port);
Connection connection = factory.createConnection(user, password);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination dest = new StompJmsDestination(destination);
MessageConsumer consumer = session.createConsumer(dest);
我正在寻找使用StompJmsConnectionFactory
类进行WS连接的示例,但只有使用tcp连接的示例。
是否已经有人实现了类似于这样的东西?
谢谢