[cdi-dev] JMS 2.1: Proposal to allow any CDI managed bean in a Java EE application to listen for JMS messages

Romain Manni-Bucau rmannibucau at gmail.com
Wed Aug 26 05:16:04 EDT 2015


2015-08-26 11:07 GMT+02:00 Nigel Deakin <nigel.deakin at oracle.com>:

> (Tidying up the top-posting...)
>
> Romain Manni-Bucau:
> > ...I see it really nice to not rely only on annotation - and aligned with
> > most specs - since sometimes you just want to either be able to rely on a
> > loop or a custom config to register your listeners. Annotations are too
> > rigid for such cases.
>
> Nigel:
> > Obviously, if users don't want to use CDI (or MDBs, which are also
> > declarative), then they would use the  normal JMS API. The existing
> > API to register an async message listener isn't good enough,
> > and we may improve it in JMS 2.1, but that's not something that
> > I'd want to bother the people on cdi-dev with.
>
> Romain Manni-Bucau:
> > Integrating it in CDI lifecycle through an event allow CDI users to still
> > use it in the right phase of the container boot so it is still important
> > IMO and avoid all users to have their own custom listener for it -
> > @Initialized(AppScoped.class). Also allow to enrich the API through the
> event
> > itself making things smoother IMO.
>
> Nigel:
> > I'm sorry I don't understand you.
> > I thought you were asking about an API which does not use annotation.
>
> Romain Manni-Bucau:
> > Both are needed (like websocket spec). Annotation one is nice for fully
> business
> > code and/or simple libs but relying on CDI allows to simplify the wiring
> since you
> > can reuse CDI beans under the hood ie have an implicit connection
> factory if
> > there is a single one etc which is not possible in fully SE context.
>
> Can you explain the distinction you're making here? You seem to be
> suggesting two alternatives, using "annotation" and "relying on CDI". What
> would an application which uses CDI but which doesn't use annotation look
> like?
>
>
The sample I gave before with the JmsStart event basically:


public class JmsRegistrar {
    @Inject
    @JmsConnectionFactory(...)
    private ConnectionFactory factory;

    @Inject
    @JmsQueue(...)
    private Queue queue;

    public void startJms(@Observes JmsStart start) {
        start.withFactory(factory) // withFactory should be optional if
only 1 bean matches it
               .register(MyCdiTypedListener.class) // with defaults for all
potential config
                   .listenOn(queue)
               .register(MyCdiTypedListener2.class, new MyLiteral())
                    .withMaxSessions(10)
                    .listenOn(Queue.class, new QueueLiteral(...))
                    ......;
    }
}


The power of it appears when you have a config injection in JmsRegistrar
you can iterate over to get the list of listener for instance.

Also JMS resources can be decorated and referenced from qualifiers instead
of instances thanks to CDI.

It doesnt prevent the app to use @JmxListener somewhere else if the
listener doesnt need any input/config to be registered.


> Nigel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20150826/cb5c6600/attachment-0001.html 


More information about the cdi-dev mailing list