Package org.hornetq.api.core.client

Examples of org.hornetq.api.core.client.ClientMessage


         session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         ClientMessage message = null;

         byte[] body = new byte[numberOfBytes];

         for (int j = 0; j < numberOfBytes; j++)
         {
            body[j] = UnitTestCase.getSamplebyte(j);
         }

         long scheduledTime = System.currentTimeMillis() + 5000;

         for (int i = 0; i < numberOfMessages; i++)
         {
            message = session.createMessage(true);

            message.getBodyBuffer().writeBytes(body);
            message.putIntProperty(new SimpleString("id"), i);

            TestSupportPageStore store = (TestSupportPageStore)server.getPostOffice()
                                                                     .getPagingManager()
                                                                     .getPageStore(PagingTest.ADDRESS);

            // Worse scenario possible... only schedule what's on pages
            if (store.getCurrentPage() != null)
            {
               message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, scheduledTime);
            }

            producer.send(message);
         }

         if (restart)
         {
            session.close();

            server.stop();

            server = createServer(true,
                                  config,
                                  PagingTest.PAGE_SIZE,
                                  PagingTest.PAGE_MAX,
                                  new HashMap<String, AddressSettings>());
            server.start();

            sf = locator.createSessionFactory();

            session = sf.createSession(null, null, false, true, true, false, 0);
         }

         ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);

         session.start();

         for (int i = 0; i < numberOfMessages; i++)
         {

            ClientMessage message2 = consumer.receive(PagingTest.RECEIVE_TIMEOUT);

            Assert.assertNotNull(message2);

            message2.acknowledge();

            Assert.assertNotNull(message2);

            Long scheduled = (Long)message2.getObjectProperty(Message.HDR_SCHEDULED_DELIVERY_TIME);
            if (scheduled != null)
            {
               Assert.assertTrue("Scheduling didn't work", System.currentTimeMillis() >= scheduledTime);
            }

            try
            {
               assertBodiesEqual(body, message2.getBodyBuffer());
            }
            catch (AssertionFailedError e)
            {
               PagingTest.log.info("Expected buffer:" + UnitTestCase.dumbBytesHex(body, 40));
               PagingTest.log.info("Arriving buffer:" + UnitTestCase.dumbBytesHex(message2.getBodyBuffer()
                                                                                          .toByteBuffer()
                                                                                          .array(), 40));
               throw e;
            }
         }
View Full Code Here


         session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         ClientMessage message = null;

         for (int i = 0; i < numberOfMessages; i++)
         {
            message = session.createMessage(true);

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            for (int j = 1; j <= numberOfIntegers; j++)
            {
               bodyLocal.writeInt(j);
            }

            message.putIntProperty(new SimpleString("id"), i);

            producer.send(message);
         }

         session.rollback();
View Full Code Here

         session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         ClientMessage message = null;

         for (int i = 0; i < numberOfMessages; i++)
         {
            message = session.createMessage(true);

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            for (int j = 1; j <= numberOfIntegers; j++)
            {
               bodyLocal.writeInt(j);
            }

            message.putIntProperty(new SimpleString("id"), i);

            producer.send(message);
         }

         session.commit();

         session.close();

         locator.close();

         locator = createInVMNonHALocator();

         server.stop();

         server = createServer(true,
                               config,
                               PagingTest.PAGE_SIZE,
                               PagingTest.PAGE_MAX,
                               new HashMap<String, AddressSettings>());

         server.start();

         sf = locator.createSessionFactory();

         session = sf.createSession(null, null, false, false, false, false, 0);

         ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);

         session.start();
         for (int i = 0; i < numberOfMessages; i++)
         {
            System.out.println("Received " + i);
            if (i == 55)
            {
               System.out.println("i = 55");
            }
            ClientMessage msg = consumer.receive(5000);
            Assert.assertNotNull(msg);
            msg.acknowledge();
            session.commit();
         }

         session.close();
      }
View Full Code Here

         session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         ClientMessage message = null;

         for (int i = 0; i < numberOfMessages; i++)
         {
            message = session.createMessage(true);

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(new byte[1024]);

            message.putIntProperty(new SimpleString("id"), i);

            producer.send(message);
         }

         session.commit();

         session.close();

         locator.close();

         server.stop();

         server = createServer(true,
                               config,
                               PagingTest.PAGE_SIZE,
                               PagingTest.PAGE_MAX,
                               new HashMap<String, AddressSettings>());

         server.start();

         locator = createInVMNonHALocator();

         sf = locator.createSessionFactory();

         session = sf.createSession(null, null, false, false, false, false, 0);

         ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);

         session.start();
         // 347 = I just picked any odd number, not rounded, to make sure it's not at the beggining of any page
         for (int i = 0; i < 347; i++)
         {
            System.out.println("Received " + i);
            ClientMessage msg = consumer.receive(5000);
            assertEquals(i, msg.getIntProperty("id").intValue());
            Assert.assertNotNull(msg);
            msg.acknowledge();
            session.commit();
         }

         session.close();

         locator.close();

         server.stop();

         server = createServer(true,
                               config,
                               PagingTest.PAGE_SIZE,
                               PagingTest.PAGE_MAX,
                               new HashMap<String, AddressSettings>());

         server.start();

         locator = createInVMNonHALocator();

         sf = locator.createSessionFactory();

         session = sf.createSession(null, null, false, false, false, false, 0);

         consumer = session.createConsumer(PagingTest.ADDRESS);

         session.start();
         for (int i = 347; i < numberOfMessages; i++)
         {
            System.out.println("Received " + i);
            ClientMessage msg = consumer.receive(5000);
            assertEquals(i, msg.getIntProperty("id").intValue());
            Assert.assertNotNull(msg);
            msg.acknowledge();
            session.commit();
         }

         session.close();
      }
View Full Code Here

         session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         ClientMessage message = null;

         for (int i = 0; i < numberOfMessages; i++)
         {
            byte[] body = new byte[1024];

            message = session.createMessage(true);
            message.getBodyBuffer().writeBytes(body);

            producer.send(message);
         }

         ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);

         session.start();

         for (int i = 0; i < 6; i++)
         {
            ClientMessage message2 = consumer.receive(PagingTest.RECEIVE_TIMEOUT);

            Assert.assertNotNull(message2);

            message2.acknowledge();
         }

         Assert.assertNull(consumer.receiveImmediate());

         Assert.assertEquals(0, server.getPostOffice()
                                      .getPagingManager()
                                      .getPageStore(PagingTest.ADDRESS)
                                      .getAddressSize());

         for (int i = 0; i < numberOfMessages; i++)
         {
            byte[] body = new byte[1024];

            message = session.createMessage(true);
            message.getBodyBuffer().writeBytes(body);

            producer.send(message);
         }

         for (int i = 0; i < 6; i++)
         {
            ClientMessage message2 = consumer.receive(PagingTest.RECEIVE_TIMEOUT);

            Assert.assertNotNull(message2);

            message2.acknowledge();
         }

         Assert.assertNull(consumer.receiveImmediate());

         session.close();

         session = sf.createSession(false, true, true);

         producer = session.createProducer(PagingTest.ADDRESS);

         for (int i = 0; i < numberOfMessages; i++)
         {
            byte[] body = new byte[1024];

            message = session.createMessage(true);
            message.getBodyBuffer().writeBytes(body);

            producer.send(message);
         }

         session.commit();

         consumer = session.createConsumer(PagingTest.ADDRESS);

         session.start();

         for (int i = 0; i < 6; i++)
         {
            ClientMessage message2 = consumer.receive(PagingTest.RECEIVE_TIMEOUT);

            Assert.assertNotNull(message2);

            message2.acknowledge();
         }

         session.commit();

         Assert.assertNull(consumer.receiveImmediate());
View Full Code Here

         session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         ClientMessage message = null;

         class MyHandler implements MessageHandler
         {
            int count;

            public void onMessage(ClientMessage message)
            {
               try
               {
                  Thread.sleep(1);
               }
               catch (Exception e)
               {

               }

               count++;

               if (count % 1000 == 0)
               {
                  log.info("received " + count);
               }

               try
               {
                  message.acknowledge();
               }
               catch (Exception e)
               {
                  e.printStackTrace();
               }
            }
         }

         ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);

         session.start();

         consumer.setMessageHandler(new MyHandler());

         for (int i = 0; i < numberOfMessages; i++)
         {
            byte[] body = new byte[1024];

            message = session.createMessage(false);
            message.getBodyBuffer().writeBytes(body);

            message.setExpiration(System.currentTimeMillis() + 100);

            producer.send(message);
         }

         session.close();
View Full Code Here

            session.createQueue(PagingTest.ADDRESS, new SimpleString("someQueue" + i), null, true);
         }

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         ClientMessage message = null;

         byte[] body = new byte[1024];

         message = session.createMessage(true);
         message.getBodyBuffer().writeBytes(body);

         for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
         {
            producer.send(message);

            if (transacted)
            {
               session.commit();
            }
         }

         session.close();

         server.stop();

         server = createServer(true,
                               config,
                               PagingTest.PAGE_SIZE,
                               PagingTest.PAGE_MAX,
                               new HashMap<String, AddressSettings>());
         server.start();

         sf = locator.createSessionFactory();

         session = sf.createSession(null, null, false, true, true, false, 0);

         session.start();

         for (int msg = 0; msg < NUMBER_OF_MESSAGES; msg++)
         {

            for (int i = 0; i < NUMBER_OF_BINDINGS; i++)
            {
               ClientConsumer consumer = session.createConsumer(new SimpleString("someQueue" + i));

               ClientMessage message2 = consumer.receive(PagingTest.RECEIVE_TIMEOUT);

               Assert.assertNotNull(message2);

               message2.acknowledge();

               Assert.assertNotNull(message2);

               consumer.close();
View Full Code Here

         int NUMBER_OF_MESSAGES = 100;

         for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
         {
            ClientMessage msg = session.createMessage(true);
            msg.getBodyBuffer().writeBytes(new byte[512]);

            producerPaged.send(msg);
            producerNonPaged.send(msg);
         }

         session.close();

         Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS).isPaging());
         Assert.assertFalse(server.getPostOffice().getPagingManager().getPageStore(NON_PAGED_ADDRESS).isPaging());

         session = sf.createSession(false, true, false);

         session.start();

         ClientConsumer consumerNonPaged = session.createConsumer(NON_PAGED_ADDRESS);
         ClientConsumer consumerPaged = session.createConsumer(PAGED_ADDRESS);

         ClientMessage ackList[] = new ClientMessage[NUMBER_OF_MESSAGES];

         for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
         {
            ClientMessage msg = consumerNonPaged.receive(5000);
            Assert.assertNotNull(msg);
            ackList[i] = msg;
         }

         Assert.assertNull(consumerNonPaged.receiveImmediate());

         for (ClientMessage ack : ackList)
         {
            ack.acknowledge();
         }

         consumerNonPaged.close();

         session.commit();

         ackList = null;

         for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
         {
            ClientMessage msg = consumerPaged.receive(5000);
            Assert.assertNotNull(msg);
            msg.acknowledge();
            session.commit();
         }

         Assert.assertNull(consumerPaged.receiveImmediate());
View Full Code Here

         int NUMBER_OF_MESSAGES = 100;

         for (int i = 0; i < NUMBER_MESSAGES_BEFORE_PAGING; i++)
         {
            ClientMessage msg = session.createMessage(true);
            msg.getBodyBuffer().writeBytes(new byte[512]);

            producerA.send(msg);
            producerB.send(msg);
         }

         session.commit(); // commit was called to clean the buffer only (making sure everything is on the server side)

         Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_A).isPaging());
         Assert.assertFalse(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_B).isPaging());

         for (int i = 0; i < NUMBER_MESSAGES_BEFORE_PAGING; i++)
         {
            ClientMessage msg = session.createMessage(true);
            msg.getBodyBuffer().writeBytes(new byte[512]);

            producerA.send(msg);
            producerB.send(msg);
         }

         session.commit(); // commit was called to clean the buffer only (making sure everything is on the server side)

         Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_A).isPaging());
         Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_B).isPaging());

         for (int i = NUMBER_MESSAGES_BEFORE_PAGING * 2; i < NUMBER_OF_MESSAGES; i++)
         {
            ClientMessage msg = session.createMessage(true);
            msg.getBodyBuffer().writeBytes(new byte[512]);

            producerA.send(msg);
            producerB.send(msg);
         }

         session.close();

         Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_A).isPaging());
         Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_B).isPaging());

         session = sf.createSession(null, null, false, true, true, false, 0);

         session.start();

         ClientConsumer consumerA = session.createConsumer(PAGED_ADDRESS_A);

         ClientConsumer consumerB = session.createConsumer(PAGED_ADDRESS_B);

         for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
         {
            ClientMessage msg = consumerA.receive(5000);
            Assert.assertNotNull("Couldn't receive a message on consumerA, iteration = " + i, msg);
            msg.acknowledge();
         }

         Assert.assertNull(consumerA.receiveImmediate());

         consumerA.close();

         Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_B).isPaging());

         for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
         {
            ClientMessage msg = consumerB.receive(5000);
            Assert.assertNotNull(msg);
            msg.acknowledge();
            session.commit();
         }

         Assert.assertNull(consumerB.receiveImmediate());

View Full Code Here

                  ClientConsumer cons = sessionConsumer.createConsumer(ADDRESS);

                  for (int i = 0; i < numberOfMessages; i++)
                  {
                     ClientMessage msg = cons.receive(PagingTest.RECEIVE_TIMEOUT);
                     System.out.println("Message " + i + " consumed");
                     assertNotNull(msg);
                     msg.acknowledge();

                     if (i % 20 == 0)
                     {
                        System.out.println("Commit consumer");
                        sessionConsumer.commit();
                     }
                  }
                  sessionConsumer.commit();
               }
               catch (Throwable e)
               {
                  e.printStackTrace();
                  errors.incrementAndGet();
               }
               finally
               {
                  try
                  {
                     sessionConsumer.close();
                  }
                  catch (HornetQException e)
                  {
                     e.printStackTrace();
                     errors.incrementAndGet();
                  }
               }

            }
         };

         consumeThread.start();

         ClientMessage message = null;

         byte[] body = new byte[messageSize];

         for (int i = 0; i < numberOfMessages; i++)
         {
            message = session.createMessage(persistentMessages);

            System.out.println("Message " + i + " sent");

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

            message.putIntProperty(new SimpleString("id"), i);

            producer.send(message);

            Thread.sleep(50);
         }
View Full Code Here

TOP

Related Classes of org.hornetq.api.core.client.ClientMessage

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.