Package org.hornetq.api.core.client

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


         largeMessageCache = File.createTempFile("tmp-large-message-" + largeMessage.getMessageID() + "-",
                                                 ".tmp");
         largeMessageCache.deleteOnExit();
      }

      ClientSessionFactory sf = session.getSessionFactory();
      ServerLocator locator = sf.getServerLocator();
      long callTimeout = locator.getCallTimeout();

      currentLargeMessageController = new LargeMessageControllerImpl(this, largeMessage.getLargeMessageSize(), callTimeout, largeMessageCache);
      currentLargeMessageController.setLocal(true);
View Full Code Here


         largeMessageCache = File.createTempFile("tmp-large-message-" + currentChunkMessage.getMessageID() + "-",
                                                 ".tmp");
         largeMessageCache.deleteOnExit();
      }

      ClientSessionFactory sf = session.getSessionFactory();
      ServerLocator locator = sf.getServerLocator();
      long callTimeout = locator.getCallTimeout();

      currentLargeMessageController = new LargeMessageControllerImpl(this, packet.getLargeMessageSize(), callTimeout, largeMessageCache);

      if (currentChunkMessage.isCompressed())
View Full Code Here

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

         ClientSessionFactory sf = locator.createSessionFactory();

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

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

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

         ClientMessage message = null;

         byte[] body = new byte[messageSize];

         ByteBuffer bb = ByteBuffer.wrap(body);

         for (int j = 1; j <= messageSize; j++)
         {
            bb.put(getSamplebyte(j));
         }

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

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

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

            producer.send(message);
            if (i % 1000 == 0)
            {
               session.commit();
            }
         }
         session.commit();
         session.close();
         session = null;

         sf.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();

         Queue queue = server.locateQueue(ADDRESS);

         assertEquals(numberOfMessages, queue.getMessageCount());

         LinkedList<Xid> xids = new LinkedList<Xid>();

         int msgReceived = 0;
         for (int i = 0; i < numberOfTX; i++)
         {
            ClientSession sessionConsumer = sf.createSession(true, false, false);
            Xid xid = newXID();
            xids.add(xid);
            sessionConsumer.start(xid, XAResource.TMNOFLAGS);
            sessionConsumer.start();
            ClientConsumer consumer = sessionConsumer.createConsumer(PagingTest.ADDRESS);
            for (int msgCount = 0; msgCount < messagesPerTX; msgCount++)
            {
               if (msgReceived == numberOfMessages)
               {
                  break;
               }
               msgReceived++;
               ClientMessage msg = consumer.receive(10000);
               assertNotNull(msg);
               msg.acknowledge();
            }
            sessionConsumer.end(xid, XAResource.TMSUCCESS);
            sessionConsumer.prepare(xid);
            sessionConsumer.close();
         }

         ClientSession sessionCheck = sf.createSession(true, true);

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

         assertNull(consumer.receiveImmediate());

         sessionCheck.close();

         assertEquals(numberOfMessages, queue.getMessageCount());

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

         server.stop();

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

         waitForServer(server);

         queue = server.locateQueue(ADDRESS);

         locator = createInVMNonHALocator();
         sf = locator.createSessionFactory();

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

         consumer = session.createConsumer(PagingTest.ADDRESS);

         session.start();

         assertEquals(numberOfMessages, queue.getMessageCount());

         ClientMessage msg = consumer.receive(5000);
         if (msg != null)
         {
            System.out.println("Msg " + msg.getIntProperty("id"));

            while (true)
            {
               ClientMessage msg2 = consumer.receive(1000);
               if (msg2 == null)
               {
                  break;
               }
               System.out.println("Msg received again : " + msg2.getIntProperty("id"));

            }
         }
         assertNull(msg);

         for (int i = xids.size() - 1; i >= 0; i--)
         {
            Xid xid = xids.get(i);
            session.rollback(xid);
         }
         System.out.println("msgCount = " + queue.getMessageCount());

         xids.clear();

         session.close();

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

         session.start();

         consumer = session.createConsumer(PagingTest.ADDRESS);

         for (int i = 0; i < numberOfMessages; i++)
         {
            msg = consumer.receive(1000);
            assertNotNull(msg);
            msg.acknowledge();

            assertEquals(i, msg.getIntProperty("id").intValue());

            if (i % 500 == 0)
            {
               session.commit();
            }
         }

         session.commit();

         session.close();

         sf.close();

         locator.close();

         assertEquals(0, queue.getMessageCount());
View Full Code Here

         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);
         locator.setProducerWindowSize(-1);
         locator.setMinLargeMessageSize(1024 * 1024);

         ClientSessionFactory sf = locator.createSessionFactory();

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

         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(false, false, false);

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

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

         ClientMessage message = null;

         byte[] body = new byte[messageSize];

         ByteBuffer bb = ByteBuffer.wrap(body);

         for (int j = 1; j <= messageSize; j++)
         {
            bb.put(getSamplebyte(j));
         }

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

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

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

            producer.send(message);
            if (i % 1000 == 0)
            {
               session.commit();
            }
         }
         session.commit();
         session.close();

         session = null;

         sf.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();

         Queue queue = server.locateQueue(ADDRESS);

         assertEquals(numberOfMessages, queue.getMessageCount());

         LinkedList<Xid> xids = new LinkedList<Xid>();

         int msgReceived = 0;
         ClientSession sessionConsumer = sf.createSession(false, false, false);
         sessionConsumer.start();
         ClientConsumer consumer = sessionConsumer.createConsumer(PagingTest.ADDRESS);
         for (int msgCount = 0; msgCount < numberOfMessages; msgCount++)
         {
            log.info("Received " + msgCount);
            msgReceived++;
            ClientMessage msg = consumer.receiveImmediate();
            if (msg == null)
            {
               log.info("It's null. leaving now");
               sessionConsumer.commit();
               fail("Didn't receive a message");
            }
            msg.acknowledge();

            if (msgCount % 5 == 0)
            {
               log.info("commit");
               sessionConsumer.commit();
            }
         }

         sessionConsumer.commit();

         sessionConsumer.close();

         sf.close();

         locator.close();

         assertEquals(0, queue.getMessageCount());
View Full Code Here

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

         ClientSessionFactory sf = locator.createSessionFactory();

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

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

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

         ClientMessage message = null;

         byte[] body = new byte[messageSize];

         ByteBuffer bb = ByteBuffer.wrap(body);

         for (int j = 1; j <= messageSize; j++)
         {
            bb.put(getSamplebyte(j));
         }

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

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

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

            producer.send(message);
            if (i % 1000 == 0)
            {
               session.commit();
            }
         }
         session.commit();
         session.close();

         session = null;

         sf.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();

         Queue queue = server.locateQueue(ADDRESS);

         assertEquals(numberOfMessages, queue.getMessageCount());

         LinkedList<Xid> xids = new LinkedList<Xid>();

         int msgReceived = 0;
         ClientSession sessionConsumer = sf.createSession(false, false, false);
         sessionConsumer.start();
         ClientConsumer consumer = sessionConsumer.createConsumer(PagingTest.ADDRESS);
         for (int msgCount = 0; msgCount < numberOfMessages; msgCount++)
         {
            log.info("Received " + msgCount);
            msgReceived++;
            ClientMessage msg = consumer.receiveImmediate();
            if (msg == null)
            {
               log.info("It's null. leaving now");
               sessionConsumer.commit();
               fail("Didn't receive a message");
            }
            msg.acknowledge();

            if (msgCount % 5 == 0)
            {
               log.info("commit");
               sessionConsumer.commit();
            }
         }

         sessionConsumer.commit();

         sessionConsumer.close();

         sf.close();

         locator.close();

         assertEquals(0, queue.getMessageCount());

         long timeout = System.currentTimeMillis() + 5000;
         while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging())
         {
            Thread.sleep(100);
         }
         assertFalse(queue.getPageSubscription().getPagingStore().isPaging());

         server.stop();

         // Deleting the paging data. Simulating a failure
         // a dumb user, or anything that will remove the data
         deleteDirectory(new File(getPageDir()));

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

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

         sf = locator.createSessionFactory();

         queue = server.locateQueue(ADDRESS);

         sf = locator.createSessionFactory();
         session = sf.createSession(false, false, false);

         producer = session.createProducer(PagingTest.ADDRESS);

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

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

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

            producer.send(message);
            if (i % 1000 == 0)
            {
               session.commit();
            }
         }

         session.commit();

         server.stop();

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

         locator = createInVMNonHALocator();
         sf = locator.createSessionFactory();

         queue = server.locateQueue(ADDRESS);

         // assertEquals(numberOfMessages, queue.getMessageCount());

         xids = new LinkedList<Xid>();

         msgReceived = 0;
         sessionConsumer = sf.createSession(false, false, false);
         sessionConsumer.start();
         consumer = sessionConsumer.createConsumer(PagingTest.ADDRESS);
         for (int msgCount = 0; msgCount < numberOfMessages; msgCount++)
         {
            log.info("Received " + msgCount);
View Full Code Here

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

         ClientSessionFactory sf = locator.createSessionFactory();

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

         session.createQueue(ADDRESS, ADDRESS, true);

         session.createQueue("DLA", "DLA");

         PagingStore pgStoreAddress = server.getPagingManager().getPageStore(ADDRESS);
         pgStoreAddress.startPaging();
         PagingStore pgStoreDLA = server.getPagingManager().getPageStore(new SimpleString("DLA"));

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

         ClientMessage message = null;

         for (int i = 0; i < 500; i++)
         {
            if (i % 100 == 0)
               log.info("send message #" + i);
            message = session.createMessage(true);

            message.putStringProperty("id", "str" + i);

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

            if (i % 2 == 0)
            {
               message.setBodyInputStream(createFakeLargeStream(messageSize));
            }
            else
            {
               byte bytes[] = new byte[messageSize];
               for (int s = 0; s < bytes.length; s++)
               {
                  bytes[s] = getSamplebyte(s);
               }
               message.getBodyBuffer().writeBytes(bytes);
            }

            producer.send(message);

            if ((i + 1) % 2 == 0)
            {
               session.commit();
               if (i < 400)
               {
                  pgStoreAddress.forceAnotherPage();
               }
            }
         }

         session.commit();

         sf.close();

         locator.close();

         server.stop();

         Thread.sleep(3000);

         server.start();

         locator = createInVMNonHALocator();

         sf = locator.createSessionFactory();

         session = sf.createSession(false, false);

         session.start();

         ClientConsumer consAddr = session.createConsumer(ADDRESS);
View Full Code Here

         server.createQueue(MY_QUEUE, MY_QUEUE, null, true, false);

         ServerLocator locator = createInVMNonHALocator();

         ClientSessionFactory sf = locator.createSessionFactory();

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

         byte bufferSample[] = new byte[messageSize];

         for (int i = 0; i < bufferSample.length; i++)
         {
            bufferSample[i] = getSamplebyte(i);
         }

         ClientProducer producer = session.createProducer(MY_QUEUE);

         long timeToExpiry = System.currentTimeMillis() + 1000;
         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage message = session.createMessage(true);

            message.putIntProperty("count", i);

            // Send a few regular messages first, then all is just large messages
            if (i % 2 == 0)
            {
               message.putBooleanProperty("tst-large", false);
               message.getBodyBuffer().writeBytes(bufferSample);
            }
            else
            {
               message.putBooleanProperty("tst-large", true);
               message.setBodyInputStream(createFakeLargeStream(messageSize));
            }

            message.setExpiration(timeToExpiry);

            producer.send(message);
         }

         server.stop();
         server.start();

         sf = locator.createSessionFactory();

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

         Thread.sleep(1500);

         // just to try expiring
         ClientConsumer cons = session.createConsumer(MY_QUEUE);
         assertNull(cons.receive(1000));

         session.close();

         session = sf.createSession(false, false);

         cons = session.createConsumer(EXPIRY);
         session.start();

         // Consume half of the messages to make sure all the messages are paging (on the second try)
         for (int i = 0; i < numberOfMessages / 2; i++)
         {
            ClientMessage msg = cons.receive(5000);
            assertNotNull(msg);
            msg.acknowledge();
         }

         session.commit();

         cons.close();

         for (int rep = 0; rep < 6; rep++)
         {
            cons = session.createConsumer(EXPIRY);
            session.start();

            System.out.println("Trying " + rep);
            for (int i = 0; i < numberOfMessages / 2; i++)
            {
               ClientMessage message = cons.receive(5000);
               assertNotNull(message);

               if (i % 10 == 0)
               {
                  System.out.println("Received " + i);
               }

               for (int location = 0; location < messageSize; location++)
               {
                  assertEquals(getSamplebyte((long)location), message.getBodyBuffer().readByte());
               }
               message.acknowledge();
            }

            session.rollback();

            cons.close();

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

            if (rep == 0)
            {
               // restart the server at the first try
               server.stop();
               server.start();
            }

            sf = locator.createSessionFactory();
            session = sf.createSession(false, false);
            session.start();
         }

         cons = session.createConsumer(EXPIRY);
         session.start();
         assertNull(cons.receiveImmediate());

         cons.close();

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

         for (int rep = 0; rep < 2; rep++)
         {
            sf = locator.createSessionFactory();

            session = sf.createSession(false, false);

            cons = session.createConsumer(DLQ);

            session.start();

            for (int i = 0; i < numberOfMessages / 2; i++)
            {
               ClientMessage message = cons.receive(5000);
               assertNotNull(message);

               if (i % 10 == 0)
               {
                  System.out.println("Received " + i);
               }

               for (int location = 0; location < messageSize; location++)
               {
                  assertEquals(getSamplebyte((long)location), message.getBodyBuffer().readByte());
               }
               message.acknowledge();
            }
            if (rep == 0)
            {
               session.rollback();
               session.close();
               sf.close();
               server.stop();
               server.start();
            }
         }

         session.commit();

         assertNull(cons.receiveImmediate());

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

         validateNoFilesOnLargeDir();
      }
      finally
View Full Code Here

         server.createQueue(MY_QUEUE, MY_QUEUE, null, true, false);

         ServerLocator locator = createInVMNonHALocator();

         ClientSessionFactory sf = locator.createSessionFactory();

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

         byte bufferSample[] = new byte[messageSize];

         for (int i = 0; i < bufferSample.length; i++)
         {
            bufferSample[i] = getSamplebyte(i);
         }

         ClientProducer producer = session.createProducer(MY_QUEUE);

         long timeToExpiry = System.currentTimeMillis() + 1000;
         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage message = session.createMessage(true);

            message.putIntProperty("count", i);

            // Everything is going to be a large message
            message.putBooleanProperty("tst-large", true);
            message.setBodyInputStream(createFakeLargeStream(messageSize));

            message.setExpiration(timeToExpiry);

            producer.send(message);
         }

         server.stop();
         server.start();

         sf = locator.createSessionFactory();

         session = sf.createSession(true, true, 0);
         session.start();

         Thread.sleep(1500);

         ClientConsumer cons = session.createConsumer(MY_QUEUE);
         assertNull(cons.receive(1000));

         session.close();

         session = sf.createSession(false, false);

         cons = session.createConsumer(EXPIRY);
         session.start();

         ClientMessage msg = cons.receive(5000);
         assertNotNull(msg);
         msg.acknowledge();
         session.rollback();

         server.stop();

         // rename the file, simulating old behaviour
         long messageID = msg.getMessageID();
         long oldID = msg.getLongProperty(Message.HDR_ORIG_MESSAGE_ID);

         File largeMessagesFileDir = new File(getLargeMessagesDir());
         File oldFile = new File(largeMessagesFileDir, oldID + ".msg");
         File currentFile = new File(largeMessagesFileDir, messageID + ".msg");
         currentFile.renameTo(oldFile);

         server.start();

         sf = locator.createSessionFactory();

         session = sf.createSession(true, true, 0);
         session.start();

         cons = session.createConsumer(EXPIRY);

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage message = cons.receive(5000);
            assertNotNull(message);

            if (i % 10 == 0)
            {
               System.out.println("Received " + i);
            }

            for (int location = 0; location < messageSize; location++)
            {
               assertEquals(getSamplebyte((long)location), message.getBodyBuffer().readByte());
            }
            message.acknowledge();
         }

         session.commit();

         session.close();
         sf.close();
         locator.close();
      }
      finally
      {
         server.stop();
View Full Code Here

   public void testNonMatchingMessagesFollowedByMatchingMessages() throws Exception
   {
      ServerLocator locator = createInVMNonHALocator();

      ClientSessionFactory sf = locator.createSessionFactory();

      ClientSession session = sf.createSession();

      session.start();

      session.createQueue("foo", "foo");

      ClientProducer producer = session.createProducer("foo");

      ClientConsumer consumer = session.createConsumer("foo", "animal='giraffe'");

      ClientMessage message = session.createMessage(false);

      message.putStringProperty("animal", "hippo");

      producer.send(message);

      assertNull(consumer.receiveImmediate());

      message = session.createMessage(false);

      message.putStringProperty("animal", "giraffe");

      log.info("sending second msg");

      producer.send(message);

      ClientMessage received = consumer.receiveImmediate();

      assertNotNull(received);

      assertEquals("giraffe", received.getStringProperty("animal"));

      assertNull(consumer.receiveImmediate());
     
      session.close();
     
      sf.close();
     
      locator.close();
   }
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.