使用ActiveMq的Ajax客户端来实现消息通信

最快的开始方式是把Activemq-web-demo部署到自己的容器里,比如Tomcat,再了解于此相关的JavaSript库。

下载Activemq的源文件,进入activemq-web-demo目录,需要Maven来编译,运行mvn install。

将生成的war文件拷贝到tomcat的webapp目录。

这时候,我们还需要修改sevlet和js库的配置来让这个demo运行起来。

sevlet配置
编译web.xml以下内容

    <context-param>
        <param-name>org.apache.activemq.brokerURL</param-name>
        <param-value>tcp://localhost:61616</param-value>
        <description>The URL of the Message Broker to connect to</description>
    </context-param>
将原来单虚拟机方式修改为tcp方式

js库配置
js库文件可以在Activemq Ajax Client下载,包括_amq.js、amq.js、behaviour.js和prototype.js四个文件,在你的activemq-web-demo程序目录下建立一个amqlib目录,把这四个文件拷贝进去。

<script type=”text/javascript” src=”../amqlib/amq.js”></script>
<script type=”text/javascript”>amq.uri=’../amq’;</script>
<script type=”text/javascript” src=”talk.js”></script>
在页面文件里进行以上配置就可以进行通信了,首先导入amq的库文件,再设定servlet地址,最后指定自己的消息处理函数。

当然,不要忘了运行Activemq Broker。

VN:F [1.9.7_1111]
留下你的评价吧
Rating: 5.0/10 (9 votes cast)
使用ActiveMq的Ajax客户端来实现消息通信, 5.0 out of 10 based on 9 ratings

相关文章

Tags: , ,
Subscribe to Comments RSS Feed in this post

3 Responses

  1. 不错。。。。。

    VA:F [1.9.7_1111]
    Rating: 0 (from 0 votes)
  2. ajax客户端也是拉的方式麽?

    VA:F [1.9.7_1111]
    Rating: 0 (from 0 votes)
  3. 是的,如果你看那段javascript代码,就会发现他是间隔向servlet请求来查看消息的,可能实现为推的方式么?@奔跑的西红柿

    VN:F [1.9.7_1111]
    Rating: 0 (from 0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*