问题描述:

Is there some activemq javascript library that allows you to send messages to an activemq server without the html page being a JSP, running in a war, and could just be running on a regular Apache 2.2? If so, are there examples of this?

I looked at this page:

http://activemq.apache.org/ajax.html

But it seems that it requires Tomcat and jsp. It would be nice if there was a url I could specify for activemq without having to configure

 <servlet>

<servlet-name>AjaxServlet</servlet-name>

<servlet-class>org.apache.activemq.web.AjaxServlet</servlet-class>

</servlet>

...

<servlet-mapping>

<servlet-name>AjaxServlet</servlet-name>

<url-pattern>/amq/*</url-pattern>

</servlet-mapping>

网友答案:

there are javascript implementations of stomp for node.js that work well with activemq

http://just-another.net/stomp-js-a-nodejs-stomp-client

and there is a working example of javascript and amqp (but i'm not sure if amqp is supported by activemq, the activemq page is not clear on that)

http://www.matt-knight.co.uk/2011/message-queues-in-node-js/

网友答案:

Now We can use Stomp over websocket or MQTT over Websocket with javascript connected directly to an Apache ActiveMQ server.Be sure that your browser support websocket protocol.Download ActiveMQ5.9.0 if you want to use MQTT Over Websocket.The example is bellow.

<script src="javascript/stomp.js"></script>
<script type="text/javascript">
    var client = Stomp.client("ws://localhost:61614/stomp", "v11.stomp");
    var headers = { id:'JUST.FCX', ack: 'client'};
    client.connect("admin", "admin", function () {
        client.subscribe("test",
             function (message) {
                 alert(message);
                 message.ack();
             }, headers);
        //client.send("/topic/JUST.CN", {}, "Hello World~~");
        client.send("test", { priority: 9, persistent: true}, "Hello World~~");
    });
</script>

The great starting point is STOMP Over WebSocket article which introduces the stomp.js module. DD

相关阅读:
Top