users@jms-spec.java.net

[jms-spec users] [jsr343-experts] Re: JMS Support for DI

From: Rüdiger zu Dohna <ruediger.dohna_at_1und1.de>
Date: Thu, 1 Dec 2011 21:57:15 +0100

I think it could go like this:

Java SE clients require a Connection to produce MessagingContexts (formerly known as Sessions). The Connection in turn is produced from a ConnectionFactory that is looked up from JNDI. Or it could be injected with CDI, when the injection point is annotated to provide the name of the factory and the parameters required for creating the connection (user name, etc.).

@Inject
@ConnectionFactory("jms/ConnectionFactory")
@JmsCredentials(userName = "joe", password = "doe")
Connection connection;
...
MessagingContext context = connection.createMessagingContext(MessagingContext.TRANSACTED)


Java EE clients don't need a Connection, so the MessagingContext could be produced from a MessagingContextFactory that is looked up from JNDI, or directly injected with CDI. The EE client would have to provide the same parameters/annotations as the SE client, plus those required for creating the MessagingContext itself.

@Inject
@ConnectionFactory("jms/ConnectionFactory")
@JmsCredentials(userName = "joe", password = "doe")
@AcknowledgeMode(MessagingContext.AUTO_ACKNOWLEDGE)
MessagingContext context;

And best of all: Every annotation could be optional if they have useful defaults.

Does this sound feasible?