1 2 3 Previous Next 36 Replies Latest reply on Feb 15, 2010 12:22 PM by clebert.suconic Go to original post
      • 15. Re: MDB Client for HornetQ Embedded with Core

        I am using the same code to start the HornetQ. I create Queue only at the first run and after that I comment it out.

         

        Code to intialiasize HorrnetQ.

                  Configuration configuration = new ConfigurationImpl();
                  configuration.setPersistenceEnabled(true);
                  configuration.setSecurityEnabled(false);
                  //configuration.set
                  configuration.getAcceptorConfigurations().add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));

         

                  // Step 2. Create and start the server
                  HornetQServer server = HornetQServers.newHornetQServer(configuration);
                  server.start();

        • 16. Re: MDB Client for HornetQ Embedded with Core

          To add on

           

          the Queue is created as a Durable Queue.

           

                    // Step 3. As we are not using a JNDI environment we instantiate the objects directly
                    ClientSessionFactory sf = HornetQClient.createClientSessionFactory(new                                                  TransportConfiguration(InVMConnectorFactory.class.getName()));

                    // Step 4. Create a core queue
                    ClientSession coreSession = sf.createSession(false, false, false);

                    coreSession.createQueue(QUEUE_NAME, QUEUE_NAME, true);
                    coreSession.close();


          As I am testing in a standalone app (with Main method), I have even setup the binding and journal directory.

           

              configuration.setBindingsDirectory("D:/hq/bindings");
              configuration.setJournalDirectory("D:/hq/journal");

           

          I tried viewing the JMX parameters(MessageCount) for the Queue using JConsole.   I have disabled all my receivers. The scenario I am looking out  is

          if I pump some messages (say 100) with my receivers disabled (or no receivers), and crash the server (by doing Ctrl-c) ,  I should be able to see the 100 messages (MessageCount) when I restart the server. This is not happening. Am I missing something ?

          • 17. Re: MDB Client for HornetQ Embedded with Core
            timfox
            You'd need to show us all your code, including the code you use to send messages for us to see what's wrong with it.
            • 18. Re: MDB Client for HornetQ Embedded with Core

              I have the testcase files in Zip along with this message.

               

              The participant classes are

               

              MessageSendAndReceive

               

              The entry class which start the HornetQ emebedded server and starts the message pushing (MessagePusher) or Message receiving (MessageReciver) or do both.

               

              MessagePusher

               

              This class starts a executor framework to send messages parallely.

               

              OrigSender.java implements Runnable

              This does original job of sending the message by creating the producer.

               

               

              MessageReceiver.java

              This classes created multiple consumers and assings and MessageHandler for each and every consumer

               

              MsgHandler implements MessageHandler

              MessageHandler with onMessage method.

               

              Please let me know if you need anything else.

               

              Thanks for all your support

              • 19. Re: MDB Client for HornetQ Embedded with Core
                ataylor

                Your messages aren't durable, in origSender you have 'ClientMessage message = session.createMessage(false);' the false parameter is the durability of th emessage, change this to true.

                 

                One thing i would point out is that you are creating a session for every producer or consumer created. I would change origSender to take a session in its constructor and in MessageReceiver just create the one session.

                • 20. Re: MDB Client for HornetQ Embedded with Core

                  That did the Trick. Thanks !!!!!.  I always assumed durability can be only expressed at the Queue level. I didnt realise this can be expressed at message level also.  I will take care of your adivice on reusing the Session.

                   

                  You guys are reallty cool !!! and supportive.

                   

                  Once again, Thanks a lot for ur Support

                  • 21. Re: MDB Client for HornetQ Embedded with Core

                    Hi Andy,

                     

                    Do we need to call the clientSession.commit() to explicity dequeue or remove the message from the queue? From the same testcase, I am seeing that the queue are only removed only after a commit even though the session is non-transactional session and I am also doing a explicit acknowledge.

                     

                    Also I want to understand what are the best practises I need to follow if I want to reuse a session.

                    • 22. Re: MDB Client for HornetQ Embedded with Core

                      Tim/Andy

                       

                      Any Ideas ?

                      • 23. Re: MDB Client for HornetQ Embedded with Core
                        timfox

                        Messages acks are batched.

                         

                        Have a look in the api docs, ack-batch-size

                        • 24. Re: MDB Client for HornetQ Embedded with Core

                          Thats works. But I need a clarification on the acknowledge. Support for some business conditition I want to retain a message in the queue

                          for ex: if a Message processing leads to a exception I want this message to be retried after some time. I am assuming that if I dont acknowledge a

                          message it will remain in the queue and we can set a retry time so that the message can be retried by any of the available consumer.

                          Is my assumption correct ???

                          I tried implementing this by doing a conditional acknowledge, but the message is dequeued anyway.

                           

                           

                          BTW, I have implemeted a SessionPool (ClientSession) based on apache commons pool. From the documentation I found that it is better to reuse session even though if it is InVM calls, but I didnt find anything like a SessionPool as ActiveMQ provides.

                          • 25. Re: MDB Client for HornetQ Embedded with Core
                            timfox

                            Once a message is acknowledged it is removed from the queue and won't be available for redelivery.

                             

                            If the message has not been acknowledged, then after crash, or close, the message will be available for redelivery.

                             

                            When you call acknowledge from the client side, acks are actually batched, so the acks might not actually be sent to the server until some time later.

                             

                            If you don't want acks batched you can set ack batch size to zero.

                             

                            Regarding pooling - yes always re-use sessions - you don't need pooling to do that. Take a look at the user manual perf tuning chapter.

                             

                            Creating a new session every time you send/receive a message is a horrible anti-pattern

                            • 26. Re: MDB Client for HornetQ Embedded with Core

                              Without Pooling, how we can acheive Session reuse. I have already went through the section 46.6., it talks about the Anti-Patterns, but doesnt talk about how to do Session reuse  for Core API.

                               

                               

                              Another quick questions ? I am currently trying transactional sesstions and for this I am trying to set the Max-Delivery-Attempts and DeadQuery using

                              AddressSettings.

                               

                                          HornetQServer server = HornetQServers.newHornetQServer(configuration);
                                        AddressSettings settings = new AddressSettings();
                                        settings.setDeadLetterAddress(new SimpleString("queue.DLQ"));
                                        //settings.setExpiryAddress(new SimpleString("jms.queue.DLQ"));
                                        //settings.setRedeliveryDelay(5000);
                                        settings.setMaxDeliveryAttempts(3);
                                        server.getAddressSettingsRepository().setDefault(settings);
                                        //server.getAddressSettingsRepository().addMatch("queue.TestQueue11",settings);
                                        server.start();

                               

                              I am explicity rolling back one transaction and I want to check if the message is pusher to DLQ after three attempts. Seems this is not happening.

                               

                              PS: I have explicity created the DLQ using the below code.

                              coreSession.createQueue("queue.DLQ","queue.DLQ",true);

                               

                              Any thoughts on this ?

                              • 27. Re: MDB Client for HornetQ Embedded with Core
                                timfox

                                Session re-use just means don't create a new session for each message sent!

                                 

                                E.g. the following is "re-using" the session:

                                 

                                ClientSession session = sf.createSession(...);

                                 

                                ClientProducer prod = session.createProducer(...);

                                 

                                for (int i = 0; i < 100000; i++)

                                {

                                   prod.send(session.createMessage(false));

                                }

                                 

                                 

                                Whereas the following is *not* re-using the session:

                                 

                                for (int i = 0; i < 100000; i++)

                                {

                                   ClientSession session = sf.createSession(...);

                                 

                                   ClientProducer prod = session.createProducer(...);

                                 

                                   prod.send(session.createMessage(false));

                                }

                                 

                                The second is an anti-pattern and will be *slow*

                                 

                                It's up to you how you maintain your sessions in your application.

                                 

                                Regarding DLQ, take a look a the DLQ examples in the distro.

                                • 28. Re: MDB Client for HornetQ Embedded with Core

                                  I have already peeked the example. My questions was, if I do the AddressSettings through code rather than FileConfiguration will the max retry or DLQ, the functionality is not working as expected. I am seeing the same message with infinite retries. The worst case, no further message is processed as the rollbacked message is in the head of the queue

                                   

                                  Feb 11, 2010 6:09:05 PM org.hornetq.core.logging.impl.JULLogDelegate warn
                                  WARNING: Timed out waiting for handler to complete processing

                                   

                                  Seems it is getting stuck somewhere is ClientConsumerImpl

                                   

                                  Any clues or workarounds ?

                                  • 29. Re: MDB Client for HornetQ Embedded with Core
                                    ataylor
                                    can you write a simple test showing this behaviour