Rudiger,
So I think here is one of the issues that Pete Muir raised to us, that
didn't end up on the whole EG. This mostly stems from an issue I had that
I was using incorrectly. Basically, CDI doesn't handle the "configuration"
elements that DI can provide, only the injection part. This would be
represented in things like Spring where you can read files from the file
system as your context, which may differ between environments.
Configuration in this case could be done in the external files and loaded
into the application context. CDI provides no mechanism for this, though
it seems like you can do this using qualifiers. The problem is that you
need to reinject on each injection point. So the injected object must be
dependent scoped, rather than bound to other contexts. This is the main
issue I see with trying to inject against a connection factory.
Nigel,
As far as an example goes, yes that is what I was thinking.
I really don't have an example with shared transaction. I would imagine
though just a receive method that returns a message.
John
On Thu, Dec 1, 2011 at 3:57 PM, Rüdiger zu Dohna <ruediger.dohna_at_1und1.de>wrote:
> 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?
>
>