-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all,
i'm trying to get access from a web app to an activeMQ messaging server with their AJAX api. Does anyone have successfull run a polling from out a zul-file?
I cannot find out what is the problem:
thanks Stephan
pieces of zul:
<script type="text/javascript" src="js/amq/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/amq/amq_jquery_adapter.js"></script>
<script type="text/javascript" src="js/amq/amq.js"></script>
<script type="text/javascript">amq.uri='/amq';</script>
<script type="text/javascript">
var amq = org.activemq.Amq;
amq.init({
uri: 'amq',
logging: true,
timeout: 45
});
</script>
<script type="text/javascript">
amq.sendMessage("topic://myDetector", "message");
var myHandler = { rcvMessage: function(message) { alert("received " +message); lbl_test.setValue(message); } };
function myPoll(first) { if (first) { amq.addListener('myDetector', 'topic://myDetector', myHandler.rcvMessage);
} }
amq.addPollHandler(myPoll);
</script>
<script type="text/javascript">function sendMessage(){ amq.sendMessage("topic://myDetector", "message"); }</script>
<script type="text/javascript">function sayHello(){alert("Hello");}</script>
<button label="sendMessage" onClick='Clients.evalJavaScript("sendMessage()")' />
<button label="alert" onClick='Clients.evalJavaScript("sayHello()")' />
pieces of web.xml
<!-- activeMQ -->
<context-param>
<param-name>org.apache.activemq.brokerURL</param-name>
<param-value>tcp://localhost</param-value>
</context-param>
<!-- ActiveMQ AjaxServlet -->
<!-- The servlet both serves the required js files and handles the JMS requests and responses -->
<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>
<servlet>
<servlet-name>MessageServlet</servlet-name>
<servlet-class>org.apache.activemq.web.MessageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MessageServlet</servlet-name>
<url-pattern>/message/*</url-pattern>
</servlet-mapping>
Hi Stephan,
I got the polling working from my zul page. I don't know what issues you encountered, but I initially encountered issues, like some camel classes not found, continuations not supported, and illegal state. Finally I found the following link. The second last post helped me get the polling to work. http://activemq.2283324.n4.nabble.com/AjaxServlet-on-Tomcat-td3601798.html
Here are my additional libraries for your reference.
I'm running apache-tomcat-7.0.32. I must have "MessageServlet" registered in web.xml, as suggested by the post. Also, my client page must first make the call, amq.sendMessage(destination, message), before the polling starts to work from there on. I was able to use JConsole to send some testing message to a topic, and saw my client page polled and displayed it on the screen.
Lastly, I didn't try your code. I followed the pattern in the smalltalk to integrate activemq js.
I hope this information help.
Thanks windeyu, i have get it to run in the meantime. For asynchronous working the activeMQ listeners need an entry in the web.xml.
<async-supported>true</async-supported>
(listeners and filters in web.xml) I realize that this can only be run in a servlet-api 3.0 specification. Tomcat 6.x does not support this out of the box. Now it runs in Glassfish and Tomcat 7.0.35
Thanks Stephan
Asked: 2013-02-05 13:18:30 +0800
Seen: 54 times
Last updated: Feb 25 '13