1 2 3 Previous Next 36 Replies Latest reply on Feb 15, 2010 12:22 PM by Clebert Suconic

    MDB Client for HornetQ Embedded with Core

    Vijayanandraj Amaladoss Newbie

      Hi,

       

      I am trying to figureout if it is possible to have a MDB to receive message from an Queue established using a HornetQ embedded server using the core API.

       

      I think we can do this for HornetQ embedded server in JMS mode (JNDIServer etc..), but is this possible with Core mode (InVM calls)

       

      Thanks

        • 1. Re: MDB Client for HornetQ Embedded with Core
          Clebert Suconic Master

          Our JMS Layer is just a thin layer in top of our core.

           

          How you connect the Resource adapter to the server depends in how you configure:

           

           

          The example at /examples/javaee/jca-config shows how to configure a series of properties on the resource adapter, including the connection-factory.

           

          More information about configuring the transports can be found at:

           

          http://hornetq.sourceforge.net/docs/hornetq-2.0.0.GA/user-manual/en/html/configuring-transports.html

           

           

           

          I'm assuming you know how to configure / install MDBs at an embedded server (what we don't have any clues, that would be a question to EJB guys) since it will be dependent on TransactionServer.. etc. . Honestly I think you would be fine with jms.MessageListener on an embedded server (or using straight core objects without JMS).

          • 2. Re: MDB Client for HornetQ Embedded with Core
            Vijayanandraj Amaladoss Newbie

            Thanks a lots for those pointers Clebert. I will take a look on those and come back


            • 3. Re: MDB Client for HornetQ Embedded with Core
              Vijayanandraj Amaladoss Newbie
              If I am using Core , is there any possibility of consuming messages parallely ?. Does Core provides anything similar to MDB ?
              • 4. Re: MDB Client for HornetQ Embedded with Core
                Tim Fox Master

                Of course.

                 

                Even with straight JMS (no MDBs) you can consume messages in parallel by creating multiple consumers on the queue from which you wish to consume - you don't need MDBs from that.

                 

                Equally, with core, you can also create as many consumers as you want on a queue.

                 

                I recommend looking at the Sun JMS tutorial to understand these concepts further.

                • 5. Re: MDB Client for HornetQ Embedded with Core
                  Vijayanandraj Amaladoss Newbie

                  Tim, Thanks for your reply. I am looking for a PTP model where I want only one message consumer. I want pool of MDB/Listeners/MessageHandlers to listen on the queue and process message parallely. AFAIK multiple consumers denote a publish-subscribe model which I dont want.

                  My usecase is simple, I want to do some tasks in async way, where the message is produced and consumed in the same vm (Jboss 4.2.3/JDK 6) and I want to leverage Embeded HQ mode with core(InVM) rather than JMS. I am stuck with the parallel processing of message in the queue. AFAIK the EJB container calls the onMessage on reception of message in case of MDB and also provides pooling. I am trying to see if Core has similar option, but going through the API and examples, I am not able to locate anything concrete.

                   

                  Thanks again for your reply and sorry for my ignorance in JMS

                  • 6. Re: MDB Client for HornetQ Embedded with Core
                    Tim Fox Master

                    vijayamaladoss wrote:

                     

                    AFAIK multiple consumers denote a publish-subscribe model which I dont want.

                     

                    That is not correct in the general case.

                     

                    Multiple consumers on a topic, means publish-subscribe.

                     

                    But multiple consumers on a JMS queue *does not* mean pub-sub. Messages will be round robin'd between consumers exactly like a pool of MDBs. This is also supported on core.

                     

                    In fact, MDBs are implemented exactly this way. Each MDB corresponds to a consumer on a queue.

                    • 7. Re: MDB Client for HornetQ Embedded with Core
                      Vijayanandraj Amaladoss Newbie

                      Tim,

                       

                      Do you have any pointers or examples that captures multiple consumers with core. I tried one in a simple standalone application by trying multiple consumers in the loop. Its working as expected. But I am wondering, How do close the session as I want idefinetly wait for the new messages. If I am not closing the session I am getting warning for not closing the session

                       

                          for (int i = 0; i < numConsumers; i++)
                              {
                              ClientSession session = sf.createSession();
                              ClientConsumer messageConsumer = session.createConsumer(queueName);
                              messageConsumer.setMessageHandler(new MsgHandler());
                              session.start();
                              }

                      • 8. Re: MDB Client for HornetQ Embedded with Core
                        Tim Fox Master

                        I don't really understand the question.

                         

                        You close a session by calling session.close()

                        • 9. Re: MDB Client for HornetQ Embedded with Core
                          Vijayanandraj Amaladoss Newbie

                          Closing the session would terminate the session and this means the consumer will not available for sconsuming new messages. What I want to is to intialiase the consumer and wait for the new messages indefinetly.  But when I keep the session open I am getting the warning and that the consumer is garbage collected

                           

                          Below is my code snippet

                           

                                  //Start the receiver. This will intialise 6 consumers with it own message handler.

                                  MessageReceiver receiver = new MessageReceiver();
                                  receiver.receiveMessage();

                           

                                 //Start pushing 130 messages parallely

                                  MessagePusher pusher = new MessagePusher();
                                  pusher.sendMessage(0);

                           

                                  //A time delay

                                  Thread.sleep(1000);

                           

                                 //Pump another 130 messages

                                  pusher.sendMessage(130);

                           

                          what is happenings is all the consumers are garbage collected as the session is closed and garbage collected with the below message.

                           

                          WARNING: I'm closing a core ClientSession you left open. Please make sure you close all ClientSessions explicitly before letting them go out of scope! 2830910
                          Feb 9, 2010 2:05:49 AM org.hornetq.core.logging.impl.JULLogDelegate warn
                          WARNING: The ClientSession you didn't close was created here:
                          java.lang.Exception
                              at org.hornetq.core.client.impl.DelegatingSession.<init>(DelegatingSession.java:92)


                          What I want is to have this consumers available indefinetly for the new messages.

                           

                          Sorry If I am not clear with my question.

                          • 10. Re: MDB Client for HornetQ Embedded with Core
                            Clebert Suconic Master

                            That warning is just saying that all the references to the ClientSession are gone and you left the connection open. But this is ok in your case.

                             

                             

                            You could avoid the warning by adding a reference to the session from your MessageListener.

                            • 11. Re: MDB Client for HornetQ Embedded with Core
                              Vijayanandraj Amaladoss Newbie

                              I am using core's MessageHandler. I am not clear with "adding a reference to the session from your MessageListener".

                              Sorry for my ignorance.

                              • 12. Re: MDB Client for HornetQ Embedded with Core
                                Clebert Suconic Master

                                I actually meant MessageHandler

                                 

                                 

                                You could something like:

                                 

                                 

                                public class MyHandler implements MessageHandler
                                {
                                     // to avoid GC to collect the session
                                     private final ClientSession mySession;
                                
                                
                                    public MyHandler(ClientSession session)
                                    {
                                            this.mySession = session;
                                    }
                                
                                }
                                
                                • 13. Re: MDB Client for HornetQ Embedded with Core
                                  Vijayanandraj Amaladoss Newbie

                                  Thanks !!!. That worked. One final question. Does persistence works out of the box? I am setting the persistence to true


                                           Configuration configuration = new ConfigurationImpl();
                                            configuration.setPersistenceEnabled(true);
                                            configuration.setSecurityEnabled(false);

                                   

                                  I am trying to first push the messages to queues (I have commented the receiver part). After this I terminate my JVM and restart with commenting the message pusher part and enabling the message receiver.  What I am expecting is, all the message that went in the first try should be processed by the receiver. But this is not happening in the currently. Do I need to tweak some configuration ?

                                   

                                  Thanks for all your wonderful support.

                                  • 14. Re: MDB Client for HornetQ Embedded with Core
                                    Clebert Suconic Master

                                    I would need to see how you're starting the server,

                                    how you're creating the queue,


                                    and how you're sending the message

                                     

                                     

                                    Can you post some code?

                                     

                                     

                                    As for starting the server, this should work fine:

                                     

                                             Configuration configuration = new ConfigurationImpl();
                                             configuration.setPersistenceEnabled(true);
                                             configuration.setSecurityEnabled(false);
                                             configuration.getAcceptorConfigurations().add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
                                    
                                             HornetQServer server = HornetQServers.newHornetQServer(configuration);
                                             server.start();
                                    
                                    
                                    1 2 3 Previous Next