Package org.hornetq.api.core.client

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


            locator.setBlockOnNonDurableSend(true);
            locator.setBlockOnDurableSend(true);
            locator.setBlockOnAcknowledge(true);

            ClientSessionFactory sf = locator.createSessionFactory();

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

            session.createQueue(PagingTest.ADDRESS.toString(), PagingTest.ADDRESS + "-1", null, true);

            session.createQueue(PagingTest.ADDRESS.toString(), PagingTest.ADDRESS + "-2", null, false);

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

            ClientMessage message = null;

            for (int i = 0; i < numberOfMessages; i++)
            {
               if (i % 500 == 0)
               {
                  session.commit();
               }
               message = session.createMessage(true);

               HornetQBuffer bodyLocal = message.getBodyBuffer();

               bodyLocal.writeBytes(body);

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

               producer.send(message);
            }

            session.commit();

            session.close();

            server.stop();

            sf.close();
            locator.close();
         }

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

         ServerLocator locator = createInVMNonHALocator();
         final ClientSessionFactory sf2 = locator.createSessionFactory();

         final AtomicInteger errors = new AtomicInteger(0);

         Thread t = new Thread()
         {
            public void run()
            {
               try
               {
                  ClientSession session = sf2.createSession(null, null, false, true, true, false, 0);

                  ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS + "-1");

                  session.start();
View Full Code Here


         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);

         ClientSessionFactory sf = locator.createSessionFactory();

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

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

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

         ClientMessage message = null;

         byte[] body = new byte[numberOfIntegers * 4];

         ByteBuffer bb = ByteBuffer.wrap(body);

         for (int j = 1; j <= numberOfIntegers; j++)
         {
            bb.putInt(j);
         }

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

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

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

            producer.send(message);
         }

         session.close();
         sf.close();
         locator.close();

         if (persistentMessages)
         {
            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, 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);

            Assert.assertEquals(i, message2.getIntProperty("id").intValue());

            message2.acknowledge();

            Assert.assertNotNull(message2);

            if (i % 1000 == 0)
               session.commit();

            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;
            }
         }

         consumer.close();

         session.close();

         sf.close();

         locator.close();
      }
      finally
      {
View Full Code Here

         ServerLocator locator = createInVMNonHALocator();
         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);

         ClientSessionFactory sf = locator.createSessionFactory();

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

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

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

         byte[] body = new byte[messageSize];
         // HornetQBuffer bodyLocal = HornetQChannelBuffers.buffer(DataConstants.SIZE_INT * numberOfIntegers);

         ClientMessage message = null;

         int numberOfMessages = 0;
         while (true)
         {
            message = session.createMessage(true);
            message.getBodyBuffer().writeBytes(body);

            // Stop sending message as soon as we start paging
            if (server.getPostOffice().getPagingManager().getPageStore(PagingTest.ADDRESS).isPaging())
            {
               break;
            }
            numberOfMessages++;

            producer.send(message);
         }

         Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PagingTest.ADDRESS).isPaging());

         session.start();

         ClientSession sessionTransacted = sf.createSession(null, null, false, false, false, false, 0);

         ClientProducer producerTransacted = sessionTransacted.createProducer(PagingTest.ADDRESS);

         for (int i = 0; i < 10; i++)
         {
            message = session.createMessage(true);
            message.getBodyBuffer().writeBytes(body);
            message.putIntProperty(new SimpleString("id"), i);

            // Consume messages to force an eventual out of order delivery
            if (i == 5)
            {
               ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);
               for (int j = 0; j < numberOfMessages; j++)
               {
                  ClientMessage msg = consumer.receive(PagingTest.RECEIVE_TIMEOUT);
                  msg.acknowledge();
                  Assert.assertNotNull(msg);
               }

               Assert.assertNull(consumer.receiveImmediate());
               consumer.close();
            }

            Integer messageID = (Integer)message.getObjectProperty(new SimpleString("id"));
            Assert.assertNotNull(messageID);
            Assert.assertEquals(messageID.intValue(), i);

            producerTransacted.send(message);
         }

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

         Assert.assertNull(consumer.receiveImmediate());

         sessionTransacted.commit();

         sessionTransacted.close();

         for (int i = 0; i < 10; i++)
         {
            message = consumer.receive(PagingTest.RECEIVE_TIMEOUT);

            Assert.assertNotNull(message);

            Integer messageID = (Integer)message.getObjectProperty(new SimpleString("id"));

            Assert.assertNotNull(messageID);
            Assert.assertEquals("message received out of order", messageID.intValue(), i);

            message.acknowledge();
         }

         Assert.assertNull(consumer.receiveImmediate());

         consumer.close();

         session.close();

         sf.close();

         locator.close();
      }
      finally
      {
View Full Code Here

         ServerLocator locator = createInVMNonHALocator();
         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);

         ClientSessionFactory sf = locator.createSessionFactory();

         byte[] body = new byte[messageSize];

         ClientSession sessionTransacted = sf.createSession(null, null, false, false, false, false, 0);
         ClientProducer producerTransacted = sessionTransacted.createProducer(PagingTest.ADDRESS);

         ClientSession session = sf.createSession(null, null, false, true, true, false, 0);
         session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);

         ClientMessage firstMessage = sessionTransacted.createMessage(IS_DURABLE_MESSAGE);
         firstMessage.getBodyBuffer().writeBytes(body);
         firstMessage.putIntProperty(new SimpleString("id"), 0);

         producerTransacted.send(firstMessage);

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

         ClientMessage message = null;

         int numberOfMessages = 0;
         while (true)
         {
            message = session.createMessage(IS_DURABLE_MESSAGE);
            message.getBodyBuffer().writeBytes(body);
            message.putIntProperty("id", numberOfMessages);
            message.putBooleanProperty("new", false);

            // Stop sending message as soon as we start paging
            if (server.getPostOffice().getPagingManager().getPageStore(PagingTest.ADDRESS).isPaging())
            {
               break;
            }
            numberOfMessages++;

            producer.send(message);
         }

         Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PagingTest.ADDRESS).isPaging());

         session.start();

         for (int i = 1; i < 10; i++)
         {
            message = session.createMessage(true);
            message.getBodyBuffer().writeBytes(body);
            message.putIntProperty(new SimpleString("id"), i);

            // Consume messages to force an eventual out of order delivery
            if (i == 5)
            {
               ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);
               for (int j = 0; j < numberOfMessages; j++)
               {
                  ClientMessage msg = consumer.receive(PagingTest.RECEIVE_TIMEOUT);
                  msg.acknowledge();
                  assertEquals(j, msg.getIntProperty("id").intValue());
                  assertFalse(msg.getBooleanProperty("new"));
                  Assert.assertNotNull(msg);
               }

               ClientMessage msgReceived = consumer.receiveImmediate();

               if (msgReceived != null)
               {
                  System.out.println("new = " + msgReceived.getBooleanProperty("new") +
                                     " id = " +
                                     msgReceived.getIntProperty("id"));
               }

               Assert.assertNull(msgReceived);
               consumer.close();
            }

            Integer messageID = (Integer)message.getObjectProperty(new SimpleString("id"));
            Assert.assertNotNull(messageID);
            Assert.assertEquals(messageID.intValue(), i);

            producerTransacted.send(message);
         }

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

         Assert.assertNull(consumer.receiveImmediate());

         sessionTransacted.commit();

         sessionTransacted.close();

         for (int i = 0; i < 10; i++)
         {
            message = consumer.receive(PagingTest.RECEIVE_TIMEOUT);

            Assert.assertNotNull(message);

            Integer messageID = (Integer)message.getObjectProperty(new SimpleString("id"));

            // System.out.println(messageID);
            Assert.assertNotNull(messageID);
            Assert.assertEquals("message received out of order", i, messageID.intValue());

            message.acknowledge();
         }

         Assert.assertNull(consumer.receiveImmediate());

         consumer.close();

         session.close();

         sf.close();

         locator.close();
      }
      finally
      {
View Full Code Here

         ServerLocator locator = createInVMNonHALocator();
         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);

         ClientSessionFactory sf = locator.createSessionFactory();

         byte[] body = new byte[messageSize];

         ClientSession sessionTransacted = sf.createSession(null, null, false, false, false, false, 0);
         ClientProducer producerTransacted = sessionTransacted.createProducer(PagingTest.ADDRESS);

         ClientSession sessionNonTX = sf.createSession(true, true, 0);
         sessionNonTX.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);

         ClientProducer producerNonTransacted = sessionNonTX.createProducer(PagingTest.ADDRESS);

         sessionNonTX.start();

         for (int i = 0; i < 50; i++)
         {
            System.out.println("Sending " + i);
            ClientMessage message = sessionNonTX.createMessage(true);
            message.getBodyBuffer().writeBytes(body);
            message.putIntProperty(new SimpleString("id"), i);
            message.putStringProperty(new SimpleString("tst"), new SimpleString("i=" + i));

            producerTransacted.send(message);

            if (i % 2 == 0)
            {
               System.out.println("Sending 20 msgs to make it page");
               for (int j = 0; j < 20; j++)
               {
                  ClientMessage msgSend = sessionNonTX.createMessage(true);
                  msgSend.putStringProperty(new SimpleString("tst"), new SimpleString("i=" + i + ", j=" + j));
                  msgSend.getBodyBuffer().writeBytes(new byte[10 * 1024]);
                  producerNonTransacted.send(msgSend);
               }
               assertTrue(server.getPostOffice().getPagingManager().getPageStore(PagingTest.ADDRESS).isPaging());
            }
            else
            {
               System.out.println("Consuming 20 msgs to make it page");
               ClientConsumer consumer = sessionNonTX.createConsumer(PagingTest.ADDRESS);
               for (int j = 0; j < 20; j++)
               {
                  ClientMessage msgReceived = consumer.receive(10000);
                  assertNotNull(msgReceived);
                  msgReceived.acknowledge();
               }
               consumer.close();
            }
         }

         ClientConsumer consumerNonTX = sessionNonTX.createConsumer(PagingTest.ADDRESS);
         while (true)
         {
            ClientMessage msgReceived = consumerNonTX.receive(1000);
            if (msgReceived == null)
            {
               break;
            }
            msgReceived.acknowledge();
         }
         consumerNonTX.close();

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

         Assert.assertNull(consumer.receiveImmediate());

         sessionTransacted.commit();

         sessionTransacted.close();

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

            Assert.assertNotNull(message);

            Integer messageID = (Integer)message.getObjectProperty(new SimpleString("id"));

            // System.out.println(messageID);
            Assert.assertNotNull(messageID);
            Assert.assertEquals("message received out of order", i, messageID.intValue());

            System.out.println("MessageID = " + messageID);

            message.acknowledge();
         }

         Assert.assertNull(consumer.receiveImmediate());

         consumer.close();

         sessionNonTX.close();

         sf.close();

         locator.close();
      }
      finally
      {
View Full Code Here

      locator.setBlockOnAcknowledge(false);

      try
      {

         final ClientSessionFactory sf = locator.createSessionFactory();

         final byte[] body = new byte[messageSize];

         Thread producerThread = new Thread()
         {
            public void run()
            {
               ClientSession sessionProducer = null;
               try
               {
                  sessionProducer = sf.createSession(false, false);
                  ClientProducer producer = sessionProducer.createProducer(ADDRESS);

                  for (int i = 0; i < numberOfMessages; i++)
                  {
                     ClientMessage msg = sessionProducer.createMessage(true);
                     msg.getBodyBuffer().writeBytes(body);
                     msg.putIntProperty("count", i);
                     producer.send(msg);

                     if (i % 100 == 0 && i != 0)
                     {
                        sessionProducer.commit();
                        // Thread.sleep(500);
                     }
                  }

                  sessionProducer.commit();

                  System.out.println("Producer gone");

               }
               catch (Throwable e)
               {
                  e.printStackTrace(); // >> junit report
                  errors.incrementAndGet();
               }
               finally
               {
                  try
                  {
                     if (sessionProducer != null)
                     {
                        sessionProducer.close();
                     }
                  }
                  catch (Throwable e)
                  {
                     e.printStackTrace();
                     errors.incrementAndGet();
                  }
               }
            }
         };

         ClientSession session = sf.createSession(true, true, 0);
         session.start();
         session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);

         producerThread.start();

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

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage msg = consumer.receive(5000);
            assertNotNull(msg);
            assertEquals(i, msg.getIntProperty("count").intValue());
            msg.acknowledge();
            if (i > 0 && i % 10 == 0)
            {
               session.commit();
            }
         }
         session.commit();

         session.close();

         producerThread.join();

         locator.close();

         sf.close();

         assertEquals(0, errors.get());
      }
      finally
      {
View Full Code Here

      try
      {
         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);
         final ClientSessionFactory sf = locator.createSessionFactory();

         final CountDownLatch ready = new CountDownLatch(1);

         final byte[] body = new byte[messageSize];

         Thread producerThread = new Thread()
         {
            public void run()
            {
               ClientSession sessionProducer = null;
               try
               {
                  sessionProducer = sf.createSession(true, true);
                  ClientProducer producer = sessionProducer.createProducer(ADDRESS);

                  for (int i = 0; i < numberOfMessages; i++)
                  {
                     ClientMessage msg = sessionProducer.createMessage(true);
                     msg.getBodyBuffer().writeBytes(body);
                     msg.putIntProperty("count", i);
                     producer.send(msg);

                     if (i == 1000)
                     {
                        // The session is not TX, but we do this just to perform a round trip to the server
                        // and make sure there are no pending messages
                        sessionProducer.commit();

                        assertTrue(server.getPagingManager().getPageStore(ADDRESS).isPaging());
                        ready.countDown();
                     }
                  }

                  sessionProducer.commit();

                  log.info("Producer gone");

               }
               catch (Throwable e)
               {
                  e.printStackTrace(); // >> junit report
                  errors.incrementAndGet();
               }
               finally
               {
                  try
                  {
                     if (sessionProducer != null)
                     {
                        sessionProducer.close();
                     }
                  }
                  catch (Throwable e)
                  {
                     e.printStackTrace();
                     errors.incrementAndGet();
                  }
               }
            }
         };

         ClientSession session = sf.createSession(true, true, 0);
         session.start();
         session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);

         producerThread.start();
View Full Code Here

         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);

         ClientSessionFactory sf = locator.createSessionFactory();
         ClientSession session = sf.createSession(null, null, false, true, true, false, 0);

         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();
View Full Code Here

         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);

         ClientSessionFactory sf = locator.createSessionFactory();
         ClientSession session = sf.createSession(null, null, false, false, true, false, 0);

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

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
View Full Code Here

         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);

         ClientSessionFactory sf = locator.createSessionFactory();
         ClientSession session = sf.createSession(null, null, false, false, false, false, 0);

         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++)
View Full Code Here

TOP

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

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.