Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMSBroadcaster JMS Session is null, every time #149

Closed
mattnathan opened this issue Jan 17, 2012 · 10 comments
Closed

JMSBroadcaster JMS Session is null, every time #149

mattnathan opened this issue Jan 17, 2012 · 10 comments

Comments

@mattnathan
Copy link
Contributor

In JMSBroadcaster the outgoingBroadcast method checks to see if the session object has been set. If it is null it throws an exception. Unfortunately this is always the case because as far as I can tell the configure method is never called (the only place the session is set). This causes the following exception to be thrown every time a message is received.

2012-01-17 15:19:09,517 [ActiveMQ Session Task] ERROR org.apache.activemq.ActiveMQMessageConsumer - ID:localhost.localdomain-57073-1326813541941-0:0:1:1 Exception while processing message: java.lang.IllegalStateException: JMS Session is null
java.lang.IllegalStateException: JMS Session is null
    at org.atmosphere.plugin.jms.JMSBroadcaster.outgoingBroadcast(JMSBroadcaster.java:214)
    at org.atmosphere.util.AbstractBroadcasterProxy.broadcast(AbstractBroadcasterProxy.java:145)
    at org.atmosphere.plugin.jms.JMSFilter$1.onMessage(JMSFilter.java:171)
    at org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:1088)
    at org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:127)
    at org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:197)
    at org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:122)
    at org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:43)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

The Class I'm using to test with is:

package test;

import org.atmosphere.annotation.Broadcast;
import org.atmosphere.annotation.Cluster;
import org.atmosphere.annotation.Suspend;
import org.atmosphere.cpr.Broadcaster;
import org.atmosphere.jersey.Broadcastable;
import org.atmosphere.plugin.jms.JMSFilter;

import javax.ws.rs.*;

/**
 * Servlet that will listen for subscription requests and publish any messages that are sent via a JMS queue.
 */
@Path("/{topic}")
public class ServerPushServlet {
  @PathParam("topic")
  private Broadcaster topic;

  @GET
  @Suspend(resumeOnBroadcast = true, outputComments = true)
  public Broadcastable subscribe() {
    return new Broadcastable(topic);
  }

  @POST
  @Broadcast
  @Produces("application/xml;charset=UTF-8")
  @Cluster(name = "chat", value = JMSFilter.class)
  public Broadcastable broadcast(String content) {
    return new Broadcastable(content, "", topic);
  }
}

I'm using atmosphere 0.8.3

@jfarcand
Copy link
Member

Looking...Thanks!

@mattnathan
Copy link
Contributor Author

I should also point out that this issue also causes an infinite loop in the incomingBroadcast method too which also hold a lock on this preventing any other entry into synchronized(this) blocks

@jfarcand
Copy link
Member

OK thanks. That's strange I'm pretty sure a lot of people are using the JMSBroadcaster and I would have expected the regression be catched. Anyway, sorry about that. If you have a fix let me know :-)

@mattnathan
Copy link
Contributor Author

Sorry no idea on a fix. Pretty new to Atmosphere and JMS and wouldn't know which direction would fit the best.

Because of my new-ness (really a word?) it could be a configuration issue on my end, though I'm not sure what I could have done to make that 'session' variable never to be set :/

@mattnathan
Copy link
Contributor Author

After doing some experimentation it seems that if the configure method on JMSBroadcaster is called and the JMSFilter is being used then the JMS message code ends up in an infinate loop and publishes the same message over and over again until the JMS topic server throttles the topic.

I haven't experimented with this yet but I'm starting to think that a workaround could be to implement my own broadcaster that doesn't really do much and let the JMSFilter handle all the heavy lifting

@mattnathan
Copy link
Contributor Author

Found a workaround: Apply this patch to the atmosphere source then remove any use of the @Cluster(JMSFilter.class) from the jersey servlet. Also of note is that the atmosphere.xml file will need to change context-root="/path" to context-root="/path/*" in order for it to work (though this is probably just be a side effect of upgrading to the 0.9-SNAPSHOT release)

Index: extras/jms/src/main/java/org/atmosphere/plugin/jms/JMSBroadcaster.java
===================================================================
--- extras/jms/src/main/java/org/atmosphere/plugin/jms/JMSBroadcaster.java  (revision e68256be3d7c094761d9754db286474eaa09c2f1)
+++ extras/jms/src/main/java/org/atmosphere/plugin/jms/JMSBroadcaster.java  (revision )
@@ -83,9 +83,10 @@

     public JMSBroadcaster(String id, AtmosphereServlet.AtmosphereConfig config) {
         super(id, null, config);
+        configure(config);
     }

-    public synchronized void configure(AtmosphereServlet.AtmosphereConfig config) {
+    private synchronized void configure(AtmosphereServlet.AtmosphereConfig config) {
         try {
             // For backward compatibility.
             if (config.getInitParameter(JMS_TOPIC) != null) {

@jfarcand
Copy link
Member

Ya there are some failure with path mapping in 0.9. I've added your proposal and commited in 0.8.4-SNAPSHOT (will release it soon).Ya don't use the filter, just the broadcaster and it should works. If you have a chance, grab 0.8.4-SNAPSHOT (wait 1 hour as I'm uploading it). Thanks!

@jfarcand
Copy link
Member

Fixed. Please re-open if still broken.

@mattnathan
Copy link
Contributor Author

Thanks, I will note that with the current fix if you happen to use the JMSFilter and the JMSBroadcaster together you will end up sending unlimited messages to the JMS Topic so it might be worth mentioning that somewhere so people don't hit that problem for themselves.

@jfarcand
Copy link
Member

Ya, you need to use one or the other, but not both at the same time..Agree I will add documentation. Thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants