Package org.hornetq.api.core.client

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


      qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
      CountDownLatch latch = new CountDownLatch(1);
      DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
      DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
      qResourceAdapter.endpointActivation(endpointFactory, spec);
      ClientSession session = locator.createSessionFactory().createSession();
      ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
      ClientMessage message = session.createMessage(true);
      message.getBodyBuffer().writeString("1");
      clientProducer.send(message);

      latch.await(5, TimeUnit.SECONDS);

      assertNotNull(endpoint.lastMessage);
      assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");

      qResourceAdapter.endpointDeactivation(endpointFactory, spec);

      message = session.createMessage(true);
      message.getBodyBuffer().writeString("2");
      clientProducer.send(message);

      latch = new CountDownLatch(1);
      endpoint = new DummyMessageEndpoint(latch);
      endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
      qResourceAdapter.endpointActivation(endpointFactory, spec);
      latch.await(5, TimeUnit.SECONDS);

      assertNotNull(endpoint.lastMessage);
      assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "2");
      latch = new CountDownLatch(1);
      endpoint.reset(latch);
      message = session.createMessage(true);
      message.getBodyBuffer().writeString("3");
      clientProducer.send(message);
      latch.await(5, TimeUnit.SECONDS);

      assertNotNull(endpoint.lastMessage);
View Full Code Here


      ServerLocator locator = createInVMNonHALocator();

      ClientSessionFactory sf = locator.createSessionFactory();

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

      ClientProducer prod1 = session.createProducer(queue.getAddress());
      ClientProducer prod2 = session.createProducer(otherQueue.getAddress());

      ClientMessage msg = session.createMessage(true);

      msg.putStringProperty(org.hornetq.api.core.Message.HDR_DUPLICATE_DETECTION_ID, new SimpleString("dupl-1"));

      prod1.send(msg);
      prod2.send(msg);

      JMSQueueControl queueControl = createManagementControl();
      JMSQueueControl otherQueueControl = ManagementControlHelper.createJMSQueueControl((HornetQQueue)otherQueue,
                                                                                        mbeanServer);

      Assert.assertEquals(1, queueControl.getMessageCount());
      Assert.assertEquals(1, otherQueueControl.getMessageCount());

      int moved = queueControl.moveMessages(null, otherQueueName, true);

      assertEquals(1, moved);

      assertEquals(0, queueControl.getDeliveringCount());

      session.start();

      ClientConsumer cons1 = session.createConsumer(queue.getAddress());

      assertNull(cons1.receiveImmediate());

      cons1.close();

      ClientConsumer cons2 = session.createConsumer(otherQueue.getAddress());

      msg = cons2.receive(10000);

      assertNotNull(msg);

      msg.acknowledge();

      cons2.close();

      session.close();

      sf.close();

      locator.close();
View Full Code Here

      qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
      CountDownLatch latch = new CountDownLatch(1);
      DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
      DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
      qResourceAdapter.endpointActivation(endpointFactory, spec);
      ClientSession session = locator.createSessionFactory().createSession();
      ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
      ClientMessage message = session.createMessage(true);
      message.getBodyBuffer().writeString("1");
      clientProducer.send(message);

      latch.await(5, TimeUnit.SECONDS);

      assertNotNull(endpoint.lastMessage);
      assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");

      qResourceAdapter.endpointDeactivation(endpointFactory, spec);

      message = session.createMessage(true);
      message.getBodyBuffer().writeString("2");
      clientProducer.send(message);

      latch = new CountDownLatch(1);
      endpoint = new DummyMessageEndpoint(latch);
      endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
      qResourceAdapter.endpointActivation(endpointFactory, spec);
      message = session.createMessage(true);
      message.getBodyBuffer().writeString("3");
      clientProducer.send(message);
      latch.await(5, TimeUnit.SECONDS);

      assertNotNull(endpoint.lastMessage);
View Full Code Here

      qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
      CountDownLatch latch = new CountDownLatch(1);
      DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
      DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
      qResourceAdapter.endpointActivation(endpointFactory, spec);
      ClientSession session = locator.createSessionFactory().createSession();
      ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
      ClientMessage message = session.createMessage(true);
      message.getBodyBuffer().writeString("1");
      message.putStringProperty("foo", "bar");
      clientProducer.send(message);

      latch.await(5, TimeUnit.SECONDS);

      assertNotNull(endpoint.lastMessage);
      assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");

      qResourceAdapter.endpointDeactivation(endpointFactory, spec);

      message = session.createMessage(true);
      message.getBodyBuffer().writeString("2");
      message.putStringProperty("foo", "bar");
      clientProducer.send(message);

      latch = new CountDownLatch(1);
      endpoint = new DummyMessageEndpoint(latch);
      //change the selector forcing the queue to be recreated
      spec.setMessageSelector("foo='abar'");
      endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
      qResourceAdapter.endpointActivation(endpointFactory, spec);
      message = session.createMessage(true);
      message.getBodyBuffer().writeString("3");
      message.putStringProperty("foo", "abar");
      clientProducer.send(message);
      latch.await(5, TimeUnit.SECONDS);
View Full Code Here

      ServerLocator locator = createInVMNonHALocator();

      ClientSessionFactory sf = locator.createSessionFactory();

      ClientSession session = sf.createSession(true, true);
     
      ClientProducer prod = session.createProducer(pagedQueue.getAddress());
     
      ClientMessage msg = session.createMessage(true);
     
      msg.getBodyBuffer().writeBytes(new byte[90 * 1024]);
      for (int i = 0 ; i < 100; i++)
      {
         prod.send(msg);
      }
     
      JMSQueueControl control = createManagementControl(pagedQueue);
     
      assertEquals(100, control.removeMessages("     "));
     
     
     
      session.start();
     
      ClientConsumer consumer = session.createConsumer(pagedQueue.getAddress());
     
      assertNull(consumer.receive(300));

     
      session.close();

      sf.close();
      locator.close();
   }
View Full Code Here

      qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
      CountDownLatch latch = new CountDownLatch(1);
      DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
      DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
      qResourceAdapter.endpointActivation(endpointFactory, spec);
      ClientSession session = locator.createSessionFactory().createSession();
      ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
      ClientMessage message = session.createMessage(true);
      message.getBodyBuffer().writeString("1");
      message.putStringProperty("foo", "bar");
      clientProducer.send(message);

      latch.await(5, TimeUnit.SECONDS);

      assertNotNull(endpoint.lastMessage);
      assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");

      qResourceAdapter.endpointDeactivation(endpointFactory, spec);

      message = session.createMessage(true);
      message.getBodyBuffer().writeString("2");
      message.putStringProperty("foo", "bar");
      clientProducer.send(message);

      latch = new CountDownLatch(1);
View Full Code Here

         locator = HornetQClient.createServerLocatorWithoutHA(server0tc, server1tc);
         ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);

         ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);

         ClientSession session0 = sf0.createSession(false, true, true);

         ClientSession session1 = sf1.createSession(false, true, true);

         ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));

         ClientConsumer consumer1 = session1.createConsumer(queueName1);

         session1.start();

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

         final SimpleString propKey = new SimpleString("testkey");

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage message = session0.createMessage(false);

            if (largeMessage)
            {
               message.setBodyInputStream(UnitTestCase.createFakeLargeStream(1024 * 1024));
            }

            message.putIntProperty(propKey, i);

            message.getBodyBuffer().writeBytes(bytes);

            producer0.send(message);
         }

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage message = consumer1.receive(200);

            Assert.assertNotNull(message);

            Assert.assertEquals(i, message.getObjectProperty(propKey));

            if (largeMessage)
            {
               readMessages(message);
            }

            message.acknowledge();
         }

         Assert.assertNull(consumer1.receiveImmediate());

         session0.close();

         session1.close();

         sf0.close();

         sf1.close();

View Full Code Here

         locator = HornetQClient.createServerLocatorWithoutHA(server0tc, server1tc);
         ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);

         ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);

         ClientSession session0 = sf0.createSession(false, true, true);

         ClientSession session1 = sf1.createSession(false, true, true);

         ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));

         ClientConsumer consumer1 = session1.createConsumer(queueName1);

         session1.start();

         final int numMessages = 10;

         final SimpleString propKey = new SimpleString("testkey");

         final SimpleString selectorKey = new SimpleString("animal");

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage message = session0.createMessage(false);

            message.putIntProperty(propKey, i);

            message.putStringProperty(selectorKey, new SimpleString("monkey"));

            if (largeMessage)
            {
               message.setBodyInputStream(UnitTestCase.createFakeLargeStream(1024 * 1024));
            }

            producer0.send(message);
         }

         Assert.assertNull(consumer1.receiveImmediate());

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage message = session0.createMessage(false);

            message.putIntProperty(propKey, i);

            message.putStringProperty(selectorKey, new SimpleString("goat"));

            if (largeMessage)
            {
               message.setBodyInputStream(UnitTestCase.createFakeLargeStream(1024 * 1024));
            }

            producer0.send(message);
         }

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage message = consumer1.receive(200);

            Assert.assertNotNull(message);

            Assert.assertEquals(i, message.getObjectProperty(propKey));

            message.acknowledge();

            if (largeMessage)
            {
               readMessages(message);
            }
         }

         Assert.assertNull(consumer1.receiveImmediate());

         session0.close();

         session1.close();

         sf0.close();

         sf1.close();
      }
View Full Code Here

         server0.start();

         locator = HornetQClient.createServerLocatorWithoutHA(server0tc, server1tc);
         ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);

         ClientSession session0 = sf0.createSession(false, true, true);

         ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));

         final int numMessages = 100;

         final SimpleString propKey = new SimpleString("testkey");

         final SimpleString selectorKey = new SimpleString("animal");

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage message = session0.createMessage(false);

            message.getBodyBuffer().writeBytes(new byte[1024]);

            message.putIntProperty(propKey, i);

            message.putStringProperty(selectorKey, new SimpleString("monkey" + i));

            producer0.send(message);
         }

         server1.start();

         Thread.sleep(1000);

         ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);

         ClientSession session1 = sf1.createSession(false, true, true);

         try
         {
            session1.createQueue(forwardAddress, queueName1);
         }
         catch (Throwable ignored)
         {
            ignored.printStackTrace();
         }

         ClientConsumer consumer1 = session1.createConsumer(queueName1);

         session1.start();

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage message = consumer1.receive(5000);
            assertNotNull(message);
            message.acknowledge();
         }

         session1.commit();

         Assert.assertNull(consumer1.receiveImmediate());

         consumer1.close();

         session1.deleteQueue(queueName1);

         session1.close();

         sf1.close();

         server1.stop();
View Full Code Here

         server0.start();

         locator = HornetQClient.createServerLocatorWithoutHA(server0tc, server1tc);
         ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);

         ClientSession session0 = sf0.createSession(false, true, true);

         ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));

         final int numMessages = 1000;

         final SimpleString propKey = new SimpleString("testkey");

         final SimpleString selectorKey = new SimpleString("animal");

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage message = session0.createMessage(false);

            message.getBodyBuffer().writeBytes(new byte[1024]);

            message.putIntProperty(propKey, i);

            message.putStringProperty(selectorKey, new SimpleString("monkey" + i));

            producer0.send(message);
         }

         server1.start();

         // Inserting the duplicateIDs so the bridge will fail in a few
         {
            long ids[] = new long[100];

            Queue queue = server0.locateQueue(new SimpleString(queueName0));
            LinkedListIterator<MessageReference> iterator = queue.iterator();

            for (int i = 0; i < 100; i++)
            {
               iterator.hasNext();
               ids[i] = iterator.next().getMessage().getMessageID();
            }

            iterator.close();

            DuplicateIDCache duplicateTargetCache = server1.getPostOffice()
                                                           .getDuplicateIDCache(PostOfficeImpl.BRIDGE_CACHE_STR.concat(forwardAddress));

            TransactionImpl tx = new TransactionImpl(server1.getStorageManager());
            for (long id : ids)
            {
               byte[] duplicateArray = BridgeImpl.getDuplicateBytes(server0.getNodeManager().getUUID(), id);
               duplicateTargetCache.addToCache(duplicateArray, tx);
            }
            tx.commit();
         }

         Thread.sleep(1000);

         ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);

         ClientSession session1 = sf1.createSession(false, true, true);

         try
         {
            session1.createQueue(forwardAddress, queueName1);
         }
         catch (Throwable ignored)
         {
            ignored.printStackTrace();
         }

         ClientConsumer consumer1 = session1.createConsumer(queueName1);

         session1.start();

         for (int i = 100; i < numMessages; i++)
         {
            ClientMessage message = consumer1.receive(5000);
            assertNotNull(message);
            assertEquals(i, message.getIntProperty(propKey).intValue());
            message.acknowledge();
         }

         session1.commit();

         Assert.assertNull(consumer1.receiveImmediate());

         consumer1.close();

         session1.deleteQueue(queueName1);

         session1.close();

         sf1.close();

         server1.stop();
View Full Code Here

TOP

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

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.