<div dir="ltr">Antoine/Nigel/all,<div><br></div><div>Sounds very interesting (especially being in both EGs) </div><div>Although the project situation ended up with a more synchronous requirement, I did something very similar as a prototype relaying an MDB's onMessage() to a CDI event;-)<br><div><div class="gmail_extra"><br></div><div class="gmail_extra">Would be great to get something like that standardized.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div><div class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><p style="margin:0px;font-size:13px;border-collapse:collapse"><span lang="EN-US" style="font-family:Calibri">Werner</span></p><p style="margin:0px;font-size:13px;border-collapse:collapse"><span style="font-size:small"><br></span></p><p style="margin:0px;font-size:13px;border-collapse:collapse"><span style="font-size:small">On Mon, Aug 24, 2015 at 9:48 PM, </span><span dir="ltr" style="font-size:small"><<a href="mailto:cdi-dev-request@lists.jboss.org" target="_blank">cdi-dev-request@lists.jboss.org</a>></span><span style="font-size:small"> wrote:</span></p></div></div></div></div></div></div></div></div></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send cdi-dev mailing list submissions to<br>
<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
or, via email, send a message with subject or body 'help' to<br>
<a href="mailto:cdi-dev-request@lists.jboss.org">cdi-dev-request@lists.jboss.org</a><br>
<br>
You can reach the person managing the list at<br>
<a href="mailto:cdi-dev-owner@lists.jboss.org">cdi-dev-owner@lists.jboss.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of cdi-dev digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
1. Re: JMS 2.1: Proposal to allow any CDI managed bean in a Java<br>
EE application to listen for JMS messages (Antoine Sabot-Durand)<br>
2. Re: JMS 2.1: Proposal to allow any CDI managed bean in a Java<br>
EE application to listen for JMS messages (Antonio Goncalves)<br>
3. Re: JMS 2.1: Proposal to allow any CDI managed bean in a Java<br>
EE application to listen for JMS messages (Nigel Deakin)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Mon, 24 Aug 2015 17:24:27 +0000<br>
From: Antoine Sabot-Durand <<a href="mailto:antoine@sabot-durand.net">antoine@sabot-durand.net</a>><br>
Subject: Re: [cdi-dev] JMS 2.1: Proposal to allow any CDI managed bean<br>
in a Java EE application to listen for JMS messages<br>
To: Nigel Deakin <<a href="mailto:nigel.deakin@oracle.com">nigel.deakin@oracle.com</a>>, <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
Message-ID:<br>
<CABu-YBTqjtdMxbLO=<a href="mailto:TcFikN9XM-zgjfDP8Chhj5bqFSy6ueKOQ@mail.gmail.com">TcFikN9XM-zgjfDP8Chhj5bqFSy6ueKOQ@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Great Nigel,<br>
<br>
I'll have a look and try to give you feedback by the end of the week.<br>
<br>
Antoine<br>
Le lun. 24 ao?t 2015 ? 18:30, Nigel Deakin <<a href="mailto:nigel.deakin@oracle.com">nigel.deakin@oracle.com</a>> a<br>
?crit :<br>
<br>
> Over in the JMS 2.1 expert group I've just published some proposals to<br>
> allow any CDI managed bean in a Java EE<br>
> application to listen for JMS messages. This would be implemented as a<br>
> standard CDI portable extension and would become<br>
> a mandatory part of a full Java EE 8 application server.<br>
><br>
> I would welcome any comments from the CDI spec experts here. If you're<br>
> interested in helping, please take a look at<br>
> <a href="https://java.net/projects/jms-spec/pages/CDIBeansAsJMSListeners" rel="noreferrer" target="_blank">https://java.net/projects/jms-spec/pages/CDIBeansAsJMSListeners</a><br>
> and send comments or questions to me or to the public<br>
> <a href="mailto:users@jms-spec.java.net">users@jms-spec.java.net</a> alias.<br>
><br>
> Thanks,<br>
><br>
> Nigel<br>
> JMS 2.1 specification lead<br>
> _______________________________________________<br>
> cdi-dev mailing list<br>
> <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
><br>
> Note that for all code provided on this list, the provider licenses the<br>
> code under the Apache License, Version 2 (<br>
> <a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas<br>
> provided on this list, the provider waives all patent and other<br>
> intellectual property rights inherent in such information.<br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://lists.jboss.org/pipermail/cdi-dev/attachments/20150824/1da85d2e/attachment-0001.html" rel="noreferrer" target="_blank">http://lists.jboss.org/pipermail/cdi-dev/attachments/20150824/1da85d2e/attachment-0001.html</a><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Mon, 24 Aug 2015 19:42:41 +0200<br>
From: Antonio Goncalves <<a href="mailto:antonio.goncalves@gmail.com">antonio.goncalves@gmail.com</a>><br>
Subject: Re: [cdi-dev] JMS 2.1: Proposal to allow any CDI managed bean<br>
in a Java EE application to listen for JMS messages<br>
To: Nigel Deakin <<a href="mailto:nigel.deakin@oracle.com">nigel.deakin@oracle.com</a>><br>
Cc: cdi-dev <<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a>><br>
Message-ID:<br>
<CA+ZZq9_Brvtks=<a href="mailto:jxQ1TbtXMNm%2Bab3w3GZfG-2sGQYeMK2mu2jA@mail.gmail.com">jxQ1TbtXMNm+ab3w3GZfG-2sGQYeMK2mu2jA@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Nigel, what do you mean by :<br>
<br>
"The application must obtain an instance of the JMS listener bean using<br>
dependency injection"<br>
<br>
In your examples, it looks like a CDI bean cannot start listening if not<br>
injected :<br>
<br>
@WebServlet("/myjmsservlet1")<br>
public class MyJMSServlet1 extends HttpServlet {<br>
<br>
*@Inject MyDepScopeListenerBean* myDepScopeListenerBean;<br>
<br>
public void service(ServletRequest req, ServletResponse res) throws<br>
IOException, ServletException {<br>
...<br>
}<br>
}<br>
<br>
<br>
Did I understand well ? Is this the case ? Just like a MDB, I would like a<br>
CDI bean to start listening to a message without being injected, as soon as<br>
the application starts. Something like :<br>
<br>
*@ApplicationScoped*<br>
public class MyListenerBean{<br>
<br>
<br>
@JMSListener(lookup="java:global/java:global/Trades",type=JMSListener.Type.TOPIC<br>
)<br>
public void deliver(Message message) {<br>
...<br>
}<br>
}<br>
<br>
Or if we manage to get the @Startup annotation to Commons Annotation :<br>
<br>
*@Startup*<br>
public class MyListenerBean{<br>
<br>
<br>
@JMSListener(lookup="java:global/java:global/Trades",type=JMSListener.Type.TOPIC<br>
)<br>
public void deliver(Message message) {<br>
...<br>
}<br>
}<br>
<br>
<br>
Just thinking here<br>
<br>
Antonio<br>
<br>
On Mon, Aug 24, 2015 at 6:30 PM, Nigel Deakin <<a href="mailto:nigel.deakin@oracle.com">nigel.deakin@oracle.com</a>><br>
wrote:<br>
<br>
> Over in the JMS 2.1 expert group I've just published some proposals to<br>
> allow any CDI managed bean in a Java EE<br>
> application to listen for JMS messages. This would be implemented as a<br>
> standard CDI portable extension and would become<br>
> a mandatory part of a full Java EE 8 application server.<br>
><br>
> I would welcome any comments from the CDI spec experts here. If you're<br>
> interested in helping, please take a look at<br>
> <a href="https://java.net/projects/jms-spec/pages/CDIBeansAsJMSListeners" rel="noreferrer" target="_blank">https://java.net/projects/jms-spec/pages/CDIBeansAsJMSListeners</a><br>
> and send comments or questions to me or to the public<br>
> <a href="mailto:users@jms-spec.java.net">users@jms-spec.java.net</a> alias.<br>
><br>
> Thanks,<br>
><br>
> Nigel<br>
> JMS 2.1 specification lead<br>
> _______________________________________________<br>
> cdi-dev mailing list<br>
> <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
><br>
> Note that for all code provided on this list, the provider licenses the<br>
> code under the Apache License, Version 2 (<br>
> <a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas<br>
> provided on this list, the provider waives all patent and other<br>
> intellectual property rights inherent in such information.<br>
><br>
<br>
<br>
<br>
--<br>
Antonio Goncalves<br>
Software architect, Java Champion and Pluralsight author<br>
<br>
Web site <<a href="http://www.antoniogoncalves.org" rel="noreferrer" target="_blank">http://www.antoniogoncalves.org</a>> | Twitter<br>
<<a href="http://twitter.com/agoncal" rel="noreferrer" target="_blank">http://twitter.com/agoncal</a>> | LinkedIn <<a href="http://www.linkedin.com/in/agoncal" rel="noreferrer" target="_blank">http://www.linkedin.com/in/agoncal</a>> |<br>
Pluralsight<br>
<<a href="http://pluralsight.com/training/Authors/Details/antonio-goncalves" rel="noreferrer" target="_blank">http://pluralsight.com/training/Authors/Details/antonio-goncalves</a>> | Paris<br>
JUG <<a href="http://www.parisjug.org" rel="noreferrer" target="_blank">http://www.parisjug.org</a>> | Devoxx France <<a href="http://www.devoxx.fr" rel="noreferrer" target="_blank">http://www.devoxx.fr</a>><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://lists.jboss.org/pipermail/cdi-dev/attachments/20150824/55f410a4/attachment-0001.html" rel="noreferrer" target="_blank">http://lists.jboss.org/pipermail/cdi-dev/attachments/20150824/55f410a4/attachment-0001.html</a><br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Mon, 24 Aug 2015 20:47:51 +0100<br>
From: Nigel Deakin <<a href="mailto:nigel.deakin@oracle.com">nigel.deakin@oracle.com</a>><br>
Subject: Re: [cdi-dev] JMS 2.1: Proposal to allow any CDI managed bean<br>
in a Java EE application to listen for JMS messages<br>
To: Antonio Goncalves <<a href="mailto:antonio.goncalves@gmail.com">antonio.goncalves@gmail.com</a>><br>
Cc: cdi-dev <<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a>><br>
Message-ID: <<a href="mailto:55DB74E7.4080609@oracle.com">55DB74E7.4080609@oracle.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
On 24/08/2015 18:42, Antonio Goncalves wrote:<br>
> Nigel, what do you mean by :<br>
><br>
> "The application must obtain an instance of the JMS listener bean using dependency injection"<br>
><br>
> In your examples, it looks like a CDI bean cannot start listening if not injected :<br>
><br>
> @WebServlet("/myjmsservlet1")<br>
> public class MyJMSServlet1 extends HttpServlet {<br>
> *@Inject MyDepScopeListenerBean* myDepScopeListenerBean;<br>
> public void service(ServletRequest req, ServletResponse res) throws IOException, ServletException {<br>
> ...<br>
> }<br>
> }<br>
><br>
><br>
> Did I understand well ? Is this the case ? Just like a MDB, I would like a CDI bean to start listening to a message<br>
> without being injected, as soon as the application starts.<br>
<br>
My starting point is that these are normal CDI beans which are created just like any other CDI bean. The bean's<br>
postCreate behaviour (inserted by the extension) would connect to the JMS provider and start listening for messages. The<br>
bean's preDestroy behaviour would stop listening for messages and disconnect from the JMS provider.<br>
<br>
As I understand it, if you want to create a CDI managed bean (so that it is managed by CDI) then you have to inject it<br>
into some code somewhere.<br>
<br>
Additionally, if the bean is normal scoped, you have to trigger lazy instantiation by calling a method on the injected<br>
bean proxy (e.g. toString()).<br>
<br>
> Something like :<br>
><br>
> *@ApplicationScoped*<br>
> public class MyListenerBean{<br>
> @JMSListener(lookup="java:global/java:global/Trades",type=JMSListener.Type.TOPIC )<br>
> public void deliver(Message message) {<br>
> ...<br>
> }<br>
> }<br>
><br>
<br>
If I understand things correctly, if this is a normal CDI bean then this alone is not sufficient to cause an instance of<br>
the bean to be created.<br>
<br>
You also need to<br>
(1) inject it into some other bean<br>
(2) create that other bean and<br>
(3) call a method on the MyListenerBean to trigger lazy initialisation.<br>
<br>
I'm trying to avoid getting ahead of myself here. My current proposals simply apply to normal CDI managed beans created<br>
in the normal way (via injection and lazy initialisation). But I could certainly see a benefit in extending this to<br>
allow JMS listener beans to be created in other ways. In particular:<br>
<br>
(a) Creating the bean instance as soon as the bean into which it is injected enters a new scope rather than waiting for<br>
the application to call a method on it (so-called eager initialisation). That sounds relatively straightforward to me;<br>
this could either be a new standard CDI feature available to all normal-scoped beans, or something specific to beans<br>
annotated with @JMSListener.<br>
<br>
(b) Creating the bean instance without the need to inject it anywhere. As you suggest, in the case of ApplicationScoped<br>
beans this would make JMS listener beans more like MDBs. But it might be equally useful to support this for other normal<br>
scopes. For example, could we annotate a @RequestScoped bean so that every time a new request scope started, an instance<br>
of the bean for that scope was automatically created?<br>
<br>
> Or if we manage to get the @Startup annotation to Commons Annotation :<br>
><br>
> *@Startup*<br>
> public class MyListenerBean{<br>
> @JMSListener(lookup="java:global/java:global/Trades",type=JMSListener.Type.TOPIC )<br>
> public void deliver(Message message) {<br>
> ...<br>
> }<br>
> }<br>
><br>
<br>
That looks as if it's tied to ApplicationScoped. I'd rather look for something more general.<br>
<br>
Thanks for your comments so far. You're raising issues I have been thinking about for some time.<br>
<br>
Nigel<br>
<br>
<br>
<br>
><br>
> Just thinking here<br>
><br>
> Antonio<br>
><br>
> On Mon, Aug 24, 2015 at 6:30 PM, Nigel Deakin <<a href="mailto:nigel.deakin@oracle.com">nigel.deakin@oracle.com</a> <mailto:<a href="mailto:nigel.deakin@oracle.com">nigel.deakin@oracle.com</a>>> wrote:<br>
><br>
> Over in the JMS 2.1 expert group I've just published some proposals to allow any CDI managed bean in a Java EE<br>
> application to listen for JMS messages. This would be implemented as a standard CDI portable extension and would<br>
> become<br>
> a mandatory part of a full Java EE 8 application server.<br>
><br>
> I would welcome any comments from the CDI spec experts here. If you're interested in helping, please take a look at<br>
> <a href="https://java.net/projects/jms-spec/pages/CDIBeansAsJMSListeners" rel="noreferrer" target="_blank">https://java.net/projects/jms-spec/pages/CDIBeansAsJMSListeners</a><br>
> and send comments or questions to me or to the public <a href="mailto:users@jms-spec.java.net">users@jms-spec.java.net</a> <mailto:<a href="mailto:users@jms-spec.java.net">users@jms-spec.java.net</a>> alias.<br>
><br>
> Thanks,<br>
><br>
> Nigel<br>
> JMS 2.1 specification lead<br>
> _______________________________________________<br>
> cdi-dev mailing list<br>
> <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a> <mailto:<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a>><br>
> <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
><br>
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2<br>
> (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas provided on this list, the provider waives<br>
> all patent and other intellectual property rights inherent in such information.<br>
><br>
><br>
><br>
><br>
> --<br>
> Antonio Goncalves<br>
> Software architect, Java Champion and Pluralsight author<br>
><br>
> Web site <<a href="http://www.antoniogoncalves.org" rel="noreferrer" target="_blank">http://www.antoniogoncalves.org</a>> | Twitter <<a href="http://twitter.com/agoncal" rel="noreferrer" target="_blank">http://twitter.com/agoncal</a>> | LinkedIn<br>
> <<a href="http://www.linkedin.com/in/agoncal" rel="noreferrer" target="_blank">http://www.linkedin.com/in/agoncal</a>> | Pluralsight<br>
> <<a href="http://pluralsight.com/training/Authors/Details/antonio-goncalves" rel="noreferrer" target="_blank">http://pluralsight.com/training/Authors/Details/antonio-goncalves</a>> | Paris JUG <<a href="http://www.parisjug.org" rel="noreferrer" target="_blank">http://www.parisjug.org</a>> | Devoxx<br>
> France <<a href="http://www.devoxx.fr" rel="noreferrer" target="_blank">http://www.devoxx.fr</a>><br>
<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://lists.jboss.org/pipermail/cdi-dev/attachments/20150824/86151522/attachment.html" rel="noreferrer" target="_blank">http://lists.jboss.org/pipermail/cdi-dev/attachments/20150824/86151522/attachment.html</a><br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.<br>
<br>
End of cdi-dev Digest, Vol 57, Issue 13<br>
***************************************<br>
</blockquote></div><br></div></div></div></div>