1 2 Previous Next 15 Replies Latest reply on Jul 5, 2007 6:02 PM by Tim Fox

    Scheduled messages not delayed

    Joel PANSIER Newbie

      Hi,

      I use jboss messaging 1.3.0 integrated in jboss 4.2.0, with clustered queue, and oracle persistent database.
      I follow the automated clustered installation of jboss messaging.

      I want to schedule jms messages. When I send jms message with JMS_JBOSS_SCHEDULED_DELIVERY property,
      messages are consumed as soon as are produced. The SCHED_DELIVERY column value in database seems correct.

      Is there a specific configuration to allow this fonctionnality ?

      Best Regards,

      Joel

        • 1. Re: Scheduled messages not delayed
          Tim Fox Master

          Can you please post your code, or an example that fails?

          In the mean time, please take a look at org.jboss.test.messaging.jms.ScheduledDeliveryTest to see scheduled delivery in action.

          • 2. Re: Scheduled messages not delayed
            Joel PANSIER Newbie

            Indeed, I have look the unit test org.jboss.test.messaging.jms.ScheduledDeliveryTest.

            my code :

            @Stateless
            @Clustered(partition="MyPartition")
            @RemoteBinding(jndiBinding="JMSManagerBean/remote")
            @TransactionManagement(value=TransactionManagementType.BEAN)
            public class JMSManagerBean implements JMSManager {
            
             private static final long serialVersionUID = 1L;
            
             private static Logger log = Logger.getLogger(JMSManagerBean.class);
            
             private QueueConnectionFactory qcf;
             private QueueConnection qc = null;
             private QueueSession session = null;
             private QueueSender qs = null;
             private Queue queue;
            
             private int connect() {
             String nomFileOut = "queue/myQueue";
            
             Hashtable<String, String> properties = new Hashtable<String,String>();
             properties.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
             properties.put(InitialContext.PROVIDER_URL, "localhost:"+HAJNDI_PORT.intValue());
             Context ictx = new InitialContext(properties);
            
             qcf = (QueueConnectionFactory) ictx.lookup("ClusteredConnectionFactory");
             log.debug("Queue Out Name : " + nomFileOut);
            
             queue = (Queue) ictx.lookup(nomFileOut);
            
             qc = qcf.createQueueConnection();
             session = qc.createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
             qs = session.createSender(queue);
            
             return 0;
             }
            
            
             public int sendMessage() {
             try {
             connect();
             TextMessage messageOut;
             messageOut = session.createTextMessage();
            
             messageOut.setText("My message");
             messageOut.setJMSType(String.class.getName());
             try {
             long dateSchedule = current.getDeliveryDate().getTime();
             log.debug("*********** dateSchedule : " + dateSchedule);
             messageOut.setLongProperty(JBossMessage.JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME, dateSchedule);
             } catch (Exception e) {
             log.error("Problem with Schedule Property ",e);
             }
             messageOut.setLongProperty("JMS_JBOSS_REDELIVERY_DELAY", 10000);
             messageOut.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 3);
            
             qs.send(messageOut);
            
             log.debug("SYSTEM.CURRENTTIMEMILLIS : " + System.currentTimeMillis());
             session.commit();
            
             } catch (Exception e) {
             log.error(getClass().getName()+" unable to send message on queue.",e);
             retour = ErrorManager.CAN_NOT_SEND_MT;
             } finally {
             disconnect();
             }
             return 0;
             }
            
            
             private int disconnect() {
             if (qs != null) {
             try {
             qs.close();
             session.close();
             qc.close();
             queue = null;
             qcf = null;
             } catch (Exception e) {
             log.error("",e);
             logNetcool.error("KO");
             }
             }
             return 0;
             }
            }
            
            

            Also, I tried with the AUTO_ACKNOWLEDGE mode, but the result is the same.

            Thanks,
            joel

            • 3. Re: Scheduled messages not delayed
              Tim Fox Master

              Please can you post a full runnable example showing messages being sent and consumed earlier than they should be.

              Something we can copy and paste and run.

              A JUnitTest would be ideal.

              • 4. Re: Scheduled messages not delayed
                Joel PANSIER Newbie

                When I send a jms schedule message (without consumer), it doesn't appear in jboss jmx-console scheduleMessageCount.
                But if I restart jboss server, this message appear correctly in jboss jmx-console scheduleMessageCount and I don't consume this.

                The junit test :

                
                import java.util.Date;
                import java.util.Hashtable;
                
                import javax.jms.Queue;
                import javax.jms.QueueConnection;
                import javax.jms.QueueConnectionFactory;
                import javax.jms.QueueSender;
                import javax.jms.QueueSession;
                import javax.jms.Session;
                import javax.jms.TextMessage;
                import javax.naming.Context;
                import javax.naming.InitialContext;
                
                import junit.framework.TestCase;
                
                public class APITest extends TestCase {
                
                 private QueueConnectionFactory qcf;
                 private QueueConnection qc = null;
                 private QueueSession session = null;
                 private QueueSender qs = null;
                 private Queue queue;
                
                
                 public APITest() {
                 super("APITest");
                 }
                
                
                 protected void setUp() throws Exception {
                 super.setUp();
                 Hashtable<String, String> properties = new Hashtable<String, String>();
                 properties.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                 properties.put(InitialContext.PROVIDER_URL, "localhost:1100");
                 Context jndiContext = new InitialContext(properties);
                 qcf = (QueueConnectionFactory) jndiContext.lookup("ClusteredConnectionFactory");
                
                
                 queue = (Queue) jndiContext.lookup("queue/pcsapiMsgOutDefault");
                
                 qc = qcf.createQueueConnection();
                 session = qc.createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
                 qs = session.createSender(queue);
                
                
                 }
                
                 protected void tearDown() throws Exception {
                
                 super.tearDown();
                 if (qs != null) {
                 try {
                 qs.close();
                 session.close();
                 qc.close();
                 queue = null;
                 qcf = null;
                 } catch (Exception e) {
                 System.err.println(""+e);
                 }
                 }
                
                 }
                
                 public void test() throws Exception
                 {
                 try {
                 TextMessage messageOut;
                 messageOut = session.createTextMessage();
                
                 messageOut.setText("My message");
                 messageOut.setJMSType(String.class.getName());
                 try {
                 long dateSchedule = (new Date()).getTime()+1000*3600*2;
                 messageOut.setLongProperty("JMS_JBOSS_SCHEDULED_DELIVERY", dateSchedule);
                 } catch (Exception e) {
                 System.err.println("Problem with Schedule Property "+e);
                 }
                 messageOut.setLongProperty("JMS_JBOSS_REDELIVERY_DELAY", 10000);
                 messageOut.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 3);
                
                 qs.send(messageOut);
                
                 session.commit();
                
                 } catch (Exception e) {
                 System.err.println(getClass().getName()+" unable to send message on queue."+e);
                 }
                
                 }
                
                }
                
                



                Queue Configuration :

                <mbean code="org.jboss.jms.server.destination.QueueService"
                 name="jboss.messaging.destination:service=Queue,name=pcsapiMsgOutDefault"
                 xmbean-dd="xmdesc/Queue-xmbean.xml">
                 <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
                 <depends>jboss.messaging:service=PostOffice</depends>
                 <attribute name="Clustered">true</attribute>
                 </mbean>
                


                The consumer is a mdb.



                • 5. Re: Scheduled messages not delayed
                  Bastos Fabrice Newbie

                  Hi,
                  I have the same problem, I wonder if it's a bug ?
                  Fab

                  • 6. Re: Scheduled messages not delayed
                    Tim Fox Master

                    Looking at the code I can see an issue.

                    To verify, can you try sending your scheduled message *outside* a transaction.

                    • 8. Re: Scheduled messages not delayed
                      Bastos Fabrice Newbie

                      I try to send a jms message outside transaction, creating a session with transaction attribute = false and acknowlegement mode to AUTO_ACKNOWLEDGE but the result is identic ....
                      Fab

                      • 9. Re: Scheduled messages not delayed
                        Tim Fox Master

                        Are you sure? That is what our tests do.

                        • 10. Re: Scheduled messages not delayed
                          Tim Fox Master

                          In any case, someone will invetsigate this shortly... bogged down on other things right now.

                          • 11. Re: Scheduled messages not delayed
                            Bastos Fabrice Newbie

                            yes,
                            the junit test in post by joel doesn't work with the transaction attribute = false and acknowledgement mode = Session.AUTO_ACKNOWLEDGE
                            Fab

                            • 12. Re: Scheduled messages not delayed
                              Tim Fox Master

                              I have verified with the exact test program posted before applying the fix and I can confirm that scheduled delivery did work as expect if the sending session was non transactional, but did not work if the sending session was transactional.

                              I have applied the fix, and can confirm it now works in both cases. I have also added test suite cases to cover this scenario.

                              Fix will be in the next release, 1.4.0.CR1, due out next week.

                              • 13. Re: Scheduled messages not delayed
                                Joel PANSIER Newbie

                                Thanks a lot Tim.

                                Joel

                                • 14. Re: Scheduled messages not delayed
                                  Jorge Morales Master

                                  Where can I download this release?
                                  We are experiencing similar issues, and want to try the fix.

                                  1 2 Previous Next