日期:2014-05-16  浏览次数:20774 次

用ajax发送jms消息监听指定队列并从中取出消息的小例子
1.下载 apache-activemq-5.3.0-bin.zip

2.下载例子 jsmqtest.rar

3.用eclipse 打开   jsmqtest 工程,并把 D:\apache-activemq-5.3.0\lib中的jar导入

4.启动 D:\apache-activemq-5.3.0\bin\activemq.bat

5.打开 http://127.0.0.1/jsmqtest/index.htm页面

6.开始测试吧





说明:

1.引入activemq-web-5.3.0.jar 包,里面有封装好的AjaxServlet ; _amq.js; amq.js;behaviour.js

2. 配置 D:\jetty-6.1.7-atf\webapps\jsmqtest\WEB-INF\web.xml

    添加

   <context-param>
      <param-name>org.apache.activemq.brokerURL</param-name>
      <param-value>tcp://localhost:61616</param-value>
   </context-param>


   <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>
3.在html页面增加监听方法,用于监听jms中间件消息,jms队列可以是  topic 也可以是queue;

4.启动web服务器和jms服务器

5.打开 http://127.0.0.1/jsmqtest/index.htm页面 只要jms“queue://mqtes”队列中有消息,html页面就会自动显示出来。



6.开始测试吧
1 楼 goumin1818 2012-06-08  
可以用了,发送一条消息后,得刷新页面!后天还报错




严重: Servlet.service() for servlet AjaxServlet threw exception
java.lang.NoClassDefFoundError: org/eclipse/jetty/continuation/ContinuationSupport
at org.apache.activemq.web.MessageListenerServlet.doMessages(MessageListenerServlet.java:309)
at org.apache.activemq.web.MessageListenerServlet.doGet(MessageListenerServlet.java:246)
at org.apache.activemq.web.AjaxServlet.doGet(AjaxServlet.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
2 楼 goumin1818 2012-06-08  
您还熟悉ActiveMQ吗? 能给一些指导吗?QQ:237567685