Package javax.jms

Examples of javax.jms.Message


         String prodName = null;
         Integer msgCount = null;
        
         while (count < numMessages)
         {
            Message m = getMessage();
           
            if (m == null)
            {
               log.error("Message is null");
               failed = true;
               processingDone();
               return;
            }
           
            prodName = m.getStringProperty("PROD_NAME");
            msgCount = new Integer(m.getIntProperty("MSG_NUMBER"));
         //   log.info(this + " Got: " + prodName + ":" + msgCount);
                            
            Integer prevCount = (Integer)counts.get(prodName);
            if (prevCount == null)
View Full Code Here


    final int numMessages = 100;
   
    for (int i = 0; i < numMessages; i++)
    {
      Message m = session.createMessage();
      m.setIntProperty("test_counter", i+1);
      producer.send(m);
    }
   
    log.trace("Sent messages");
   
    QueueBrowser browser = session.createBrowser(queue, "test_counter > 30");
   
    Enumeration en = browser.getEnumeration();
    int count = 0;
    while (en.hasMoreElements())
    {
      Message m = (Message)en.nextElement();
      int testCounter = m.getIntProperty("test_counter");
      assertTrue(testCounter > 30);
      count++;
    }
    assertEquals(70, count);
  }
View Full Code Here

   public void testGetEnumeration() throws Exception
   {
      // send a message to the queue

      Message m = session.createTextMessage("A");
      producer.send(m);

      // make sure we can browse it

      QueueBrowser browser = session.createBrowser(queue);
View Full Code Here

               xid = new MessagingXid("bq1".getBytes(), 1, new GUID().toString().getBytes());
               xaResource.start(xid, XAResource.TMNOFLAGS);
            }
            for (int innerCount = 0; innerCount < commitSize; innerCount++)
            {
               Message m = sess.createMessage();
               m.setStringProperty("PROD_NAME", prodName);
               m.setIntProperty("MSG_NUMBER", outerCount * commitSize + innerCount);  
               prod.send(m);
            }
            if (commitSize > 0)
            {
               xaResource.end(xid, XAResource.TMSUCCESS);
               xaResource.prepare(xid);
               xaResource.commit(xid, false);
            }
            if (rollbackSize > 0)
            {
               xid = new MessagingXid("bq1".getBytes(), 1, new GUID().toString().getBytes());
               xaResource.start(xid, XAResource.TMNOFLAGS);
            }
            for (int innerCount = 0; innerCount < rollbackSize; innerCount++)
            {
               Message m = sess.createMessage();
               m.setStringProperty("PROD_NAME", prodName);
               m.setIntProperty("MSG_NUMBER", (outerCount + 1) * commitSize + innerCount);         
               prod.send(m);
            }
            if (rollbackSize > 0)
            {
               xaResource.end(xid, XAResource.TMSUCCESS);
View Full Code Here

         // we add the message to a transaction instead of sending it now. An XA session that has
         // not been enrolled in a global transaction behaves as a non-transacted session.

         ConnectionState connState = (ConnectionState)state.getParent();
         MethodInvocation mi = (MethodInvocation)invocation;
         Message m = (Message)mi.getArguments()[0];

         if (trace) { log.trace("sending message " + m + " transactionally, queueing on resource manager txID=" + txID + " sessionID= " + state.getSessionID()); }

         connState.getResourceManager().addMessage(txID, state.getSessionID(), (JBossMessage)m);
View Full Code Here

               {              
                  // receiveNoWait

                  if (trace) { log.trace(this + " attempting to get message with receiveNoWait"); }
                 
                  Message m = null;
                 
                  try
                  {
                     m = cons.receive(-1);
                  }
                  catch (JMSException e)
                  {
                     //If the consumer is closed, we will get a JMSException so we ignore
                     if (!closed)
                     {
                        throw e;
                     }                       
                  }
              
                  if (m == null)
                  {
                     if (trace) { log.trace("receiveNoWait did not retrieve any message"); }
                     break;
                  }

                  if (trace) { log.trace("receiveNoWait got message " + m + " adding to queue"); }
                  mesList.add(m);
               }

               if (mesList.isEmpty())
               {
                  // We didn't get any messages doing receiveNoWait, so let's wait. This returns if
                  // a message is received or by the consumer closing.

                  if (trace) { log.trace(this + " attempting to get message with blocking receive (no timeout)"); }

                  Message m = null;
                 
                  try
                  {
                     m = cons.receive(0);                 
                  }
View Full Code Here

         for (int outerCount = 0; outerCount < iterations; outerCount++)
         {
                                               
            for (int innerCount = 0; innerCount < commitSize; innerCount++)
            {
               Message m = getMessage();
                       
               if (m == null)
               {
                  log.error("Message is null");
                  failed = true;
                  return;
               }
               String prodName = m.getStringProperty("PROD_NAME");
               Integer msgCount = new Integer(m.getIntProperty("MSG_NUMBER"));
              
        //       log.info("got " + prodName + ":" + msgCount);
                    
               Count count = (Count)counts.get(prodName);
               if (count == null)
               {
                  //First time
                  if (msgCount.intValue() != 0)
                  {
                     log.error("First message from " + prodName + " is not 0, it is " + msgCount);
                     failed = true;
                     return;
                  }
                  else
                  {
                     count = new Count();
                     counts.put(prodName, count);
                  }
               }
               else
               {
                  if (count.lastCommitted != msgCount.intValue() - 1)
                  {
                     log.error("Message out of sequence for " + prodName + ", expected " + (count.lastCommitted + 1) + ", actual " + msgCount);
                     failed = true;
                     return;
                  }
               }
               count.lastCommitted = msgCount.intValue();
              
               count.lastReceived = msgCount.intValue();
              
               if (innerCount == commitSize -1)
               {
                  xaResource.end(xid, XAResource.TMSUCCESS);
                  xaResource.prepare(xid);
                  xaResource.commit(xid, false);
                                   
                  //Starting new tx
                  xid = new MessagingXid("bq1".getBytes(), 1, new GUID().toString().getBytes());
                  xaResource.start(xid, XAResource.TMNOFLAGS);
                
               }
              
               processingDone();           
            }           
                       
            if (outerCount == iterations - 1)
            {
               break;
            }
                                      
            for (int innerCount = 0; innerCount < rollbackSize; innerCount++)
            {
               Message m = getMessage();
              
               if (m == null)
               {
                  log.error("Message is null (rollback)");
                  failed = true;
                  return;
               }
               String prodName = m.getStringProperty("PROD_NAME");              
               Integer msgCount = new Integer(m.getIntProperty("MSG_NUMBER"));
              
         //      log.info("got " + prodName + ":" + msgCount);
              
               Count count = (Count)counts.get(prodName);
               if (count == null)
View Full Code Here

      s.close();

      s = conn.createSession(true, Session.SESSION_TRANSACTED);
      MessageConsumer c = s.createConsumer(queue);
      conn.start();
      Message m = c.receive();

      assertEquals("one", ((TextMessage)m).getText());
      assertFalse(m.getJMSRedelivered());
      assertEquals(1, m.getIntProperty("JMSXDeliveryCount"));

      s.rollback();

      // get the message again
      m = c.receive();
      assertTrue(m.getJMSRedelivered());
      assertEquals(2, m.getIntProperty("JMSXDeliveryCount"));

      conn.close();
     
      //Need to pause a little while - cancelling back to the queue is async
     
View Full Code Here

         Session sessSend = conn.createSession(true, Session.SESSION_TRANSACTED);
         Session sess1 = conn.createSession(true, Session.SESSION_TRANSACTED);        
         MessageConsumer consumer1 = sess1.createConsumer(topic);
        
         MessageProducer producer = sessSend.createProducer(topic);
         Message mSent = sessSend.createTextMessage("igloo");
         producer.send(mSent);     
         sessSend.commit();
              
         conn.start();
             
View Full Code Here

        
         MessageConsumer consumer = sess.createConsumer(topic);
         conn.start();
  
        
         Message mSent = sess.createTextMessage("igloo");
         producer.send(mSent);
        
         sess.commit();
        
         TextMessage mRec = (TextMessage)consumer.receive(2000);
View Full Code Here

TOP

Related Classes of javax.jms.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.