users@jms-spec.java.net

[jms-spec users] Confusion about JMSProducer methods and CDI

From: Elias Ross <genman_at_noderunner.net>
Date: Thu, 5 Jun 2014 11:29:27 -0700

I'm really confused by this because this code doesn't do what you might expect:

JMSProducer p = JMSContext.createProducer();
p.setTimeToLive(1000);
p.send(...)
JMSProducer p2 = JMSContext.createProducer();
p2.send(...) // time to live is set to 1000 here!

The settings from JMSProducer p are carried over to p2.

What's the point of having two producers here? The JavaDoc says "new
producer" but in fact the settings are carried over from the old
producer object.

I was using HornetQ, but it looks like the reference implementation
does do the same thing, though, but to me it seems really unintuitive.
The JavaDocs state that JMSContext represents a connection and
session, and JMSContext represents a producer.

The RI has it as:

public class JMSContextImpl implements JMSContext, Traceable {
....
        MessageProducer messageProducer;

The other question I had was the scoping for CDI. For example:

@ApplicationScoped
public class MyClient {
   @Inject JMSContext context;
}

public class MyServlet extends HttpServlet {
   @Inject MyClient client;
}

Then JMSContext ends up being potentially shared between multiple
threads. I would expect the scoping of JMSContext to be request, not
@Dependent here.