TOMCAT+ACTIVEMQ+AJAX
当activemq-web-console-5.5.0可以运行后,就开始试着添加自己的ajax的activemq的文件到客户端了。
首先是添加activemqdemo中的js文件夹的所有文件到activemq-web-console-5.5.0中的js文件夹中,然后将最简单的一个ajax的客户端文件添加到activemq-web-console-5.5.0的主页。再然后是编辑WEB-INF中的web.xml注册Ajax的servlet,最后是修改tomcat的conf中的context.xml文件注册connectionfactory,queue和topic。
web.xml添加或者修改的是
<servlet> <servlet-name>AjaxServlet</servlet-name> <servlet-class>org.apache.activemq.web.AjaxServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AjaxServlet</servlet-name> <url-pattern>/amq/*</url-pattern> </servlet-mapping>
context.xml添加的是
<Resource name="jms/ConnectionFactory" auth="Container" type="org.apache.activemq.ActiveMQConnectionFactory" description="JMS Connection Factory" factory="org.apache.activemq.jndi.JNDIReferenceFactory" brokerURL="vm://localhost" brokerName="LocalActiveMQBroker"/> <Resource name="jms/myTopic" auth="Container" type="org.apache.activemq.command.ActiveMQTopic" description="my Topic" factory="org.apache.activemq.jndi.JNDIReferenceFactory" physicalName="MY.NAME"/> <Resource name="jms/myQueue" auth="Container" type="org.apache.activemq.command.ActiveMQQueue" description="my Queue" factory="org.apache.activemq.jndi.JNDIReferenceFactory" physicalName="MY.NAME"/>
最简单的AJax使用方法是index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Ajax Test</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="js/amq_jquery_adapter.js"></script> <script type="text/javascript" src="js/amq.js"></script> <script type="text/javascript"> var amq = org.activemq.Amq; amq.init({ uri:'amq', logging: true,timeout: 20}); var des = "queue://MY.NAME"; var myHandler = { rcvMessage: function(message) { alert("received from handler "+message.data); } }; amq.addListener('list',des,myHandler.rcvMessage); function getRecords() { var myMessage = document.getElementById("num").value; amq.sendMessage(des, myMessage); alert("received "+myMessage); } </script> </head> <body> title<br> <input type="TEXT" id="num" /> <br> <br> <br> <input type="button" value="submit" onclick="getRecords()" /> <br> <div id="recordlist" > </div> </body> </html>
这时候打开http://localhost:8080/activemq-web-console-5.5.0/[your_client_file].html便可用Ajax向JMS收发消息了。
相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
时光如瑾雨微凉 2020-07-19
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05