1 2 3 4 Previous Next 48 Replies Latest reply on Apr 10, 2011 1:28 PM by blabno Go to original post
      • 30. Re: JMS MessageListener in a web application
        nbhatia.bhatian.comcast.net

        Thanks Leo. I have already cast my vote for this issue :-). If this is important to others as well, please vote for getting it fixed.


        Thanks.


        Naresh

        • 31. Re: JMS MessageListener in a web application
          lvdberg

          Naresh,


          We have more customers, lets see how to focus this to one single request.


          http://www.seamframework.org/Community/SeamSupportFormMessagedrivenPOJOs


          Leo

          • 32. Re: JMS MessageListener in a web application
            dan.j.allen

            You are experiencing this issue likely because your datasource is not setup to support XA. When you use transaction operations in an MDB (such as JPA) you must have an XA datasource since the message deliver is one transaction resource and the database is a second.


            Here's the example of a XA MySQL datasource configuration for JBoss AS:


               <xa-datasource>
                  <jndi-name>mydbDatasource</jndi-name>
                  <use-java-context>false</use-java-context>
                  <track-connection-by-tx>true</track-connection-by-tx>
                  <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                  <xa-datasource-property name="URL">jdbc:mysql://localhost/mydb</xa-datasource-property>
                  <user-name>user</user-name>
                  <password>pass</password>
               </xa-datasource>



            If you set this up, you will likely run into a bug in MySQL when the connection is being closed. http://bugs.mysql.com/bug.php?id=37645 You need to use a nightly of MySQL to work around it.


            Even then, you still may run into EJBTHREE-898. It seems that JBoss EJB 3 is very difficult to make happy when it comes to two-phase commit transactions. The database is being written as far as I can tell, so I suppose either rollback will break or the warning is simply erroneous.

            • 33. Re: JMS MessageListener in a web application
              dan.j.allen

              Please try out my solution and tell me if you like it. If there is some way you can think to make the code prettier or easier to read, feel free to provide a patch. I am not completely happy with how exceptions are dealt with, but it certainly gets the job done for now.

              • 34. Re: JMS MessageListener in a web application
                lvdberg

                Dan,


                Im am using your example as a basis for the JMS part of our application. I will give some background information why JMS is so important for this application.


                We work for the Ducth Ministry of Transport and we are collecting Traffic incident data from all available sources, police, firemen, ambulance, towers and so on. What we do is to create a common operationl picture, filtering out all differnces and giving advice of how to handle. We've done numerous prototypes (I even did a presentation of our approach in JBOSS world Berlin)  Because of the high number of involved organisations and locations we needed to shift from the basically Spring/Swing approach to soemthing far more mainatinable end extensible. We've started using Seam last year end we can now say its finally up and running. JMS is an important pillar for dataeexchange together with Rest-services. We basicaaly use JMS to notify events (changes in incident location, type or size) from one system to the other and inside the system as a scopeless mechanisme to communicate between differnt sessions (which is quite difficult with the standard Events).


                I am 110% happy with Seam as it works now, but it could have some additional goodies to make it 120% (another one is nice integration with reporting such as JasperReport).


                In the next few months we will migrate the existing Drools moules from Java client to Seam and we will start using JBPM for the workflow of the application. All together it also has become a nice Seam demo.


                Once again thanks for you help and Naresh for raising the matter.



                Leo

                • 35. Re: JMS MessageListener in a web application
                  pgmjsd

                  Dan,


                  I made a similar solution a while back, although in the end I put the messages in a non-Seam POJO where the Seam component could pick them up later, driven by browser polling.  That avoided the Lifecycle calls.


                  • 36. Re: JMS MessageListener in a web application
                    nbhatia.bhatian.comcast.net

                    Cool application Leo!

                    • 37. Re: JMS MessageListener in a web application
                      nbhatia.bhatian.comcast.net

                      Dan, following up on your suggestion to install an XA datasource:


                      1) I thought that Seam was setting up the JMS connection to be non-transactional (with auto acknowledge). In that case an XA datasource should not be needed - correct?


                      2) In any case, I tried out an XA data source as you suggested and the JTA warning went away. I am not getting the MySQL exception that you mention. Propably my driver (version 5.1.7) has incorporated the fix? However I am seeing a new warning EJBTHREE-1246: Do not use InterceptorsFactory with a ManagedObjectAdvisor, InterceptorRegistry should be used via the bean container. This was supposed to be resolved in AS 5.0.0.CR1, anyway I am ignoring this for right now.


                      Again, thanks for all your help.


                      Naresh

                      • 38. Re: JMS MessageListener in a web application
                        dan.j.allen

                        I realized that I was working off the false assumption that Seam is not intercepting the MDB. In fact, Seam does intercept the MDB and injection into an MDB does work:


                        @MessageDriven(activationConfig = {
                                @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
                                @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue")
                        })
                        @Name("messageReceiver")
                        public class MessageReceiver implements MessageListener {
                        
                                @In(create = true) MessageProcessor messageProcessor;
                                
                                @Override
                                public void onMessage(Message message) {
                                    messageProcessor.process(((TextMessage) message).getText());
                                }
                        
                        }



                        Note that if injection is failing, likely it is because your @In annotation does not specify create=true when injecting a component that does not have @Autocreate.

                        • 39. Re: JMS MessageListener in a web application
                          pgmjsd

                          Aha!  That's even better.   I think I'm going to have to refactor everything now, darnit!

                          • 40. Re: JMS MessageListener in a web application
                            nbhatia.bhatian.comcast.net

                            Dan, I tried @AutoCreate on my MessageProcessor as well as @In(create = true) in my MessageReceiver - I am still getting a NPE!

                            • 41. Re: JMS MessageListener in a web application
                              dan.j.allen

                              From your very first message I see you are packaging as an WAR, not an EAR. How exactly are you registering this listener? It appears that it is being handled differently, which is the root of your problem.

                              • 42. Re: JMS MessageListener in a web application
                                nbhatia.bhatian.comcast.net

                                That was ages ago :-). I have switched to an EAR since then. Here's my latest code (with changes you suggested):


                                @MessageDriven(activationConfig={
                                        @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
                                        @ActivationConfigProperty(propertyName="destination", propertyValue="queue/myqueue")
                                     })
                                @Name("myListener")
                                public class MyListener implements MessageListener {
                                
                                    @In(create=true) MessageProcessor messageProcessor;
                                
                                    @Override
                                    public void onMessage(Message message) {
                                        messageProcessor.process(((TextMessage)message).getText());
                                    }
                                }
                                
                                @Name("messageProcessor")
                                @AutoCreate
                                public class MessageProcessor {
                                
                                    public void process(TextMessage msg) {
                                    }
                                }
                                

                                • 43. Re: JMS MessageListener in a web application
                                  dan.j.allen

                                  Are you sure you have the Seam interceptor configured in the META-INF/ejb-jar.xml file in your EJB-JAR?


                                  <?xml version="1.0" encoding="UTF-8"?>
                                  <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" 
                                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                                           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
                                           version="3.0">
                                  
                                     <interceptors>
                                        <interceptor>
                                           <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
                                        </interceptor>
                                     </interceptors>
                                  
                                     <assembly-descriptor>
                                        <interceptor-binding>
                                           <ejb-name>*</ejb-name>
                                           <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
                                        </interceptor-binding>
                                     </assembly-descriptor>
                                  
                                  </ejb-jar>

                                  • 44. Re: JMS MessageListener in a web application
                                    nbhatia.bhatian.comcast.net

                                    That's what I had forgotten! It's working beautifully now. I am a happy camper!


                                    Thanks so much for all your help Dan.


                                    Naresh