Package org.hornetq.api.core.client

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


            bb.put(getSamplebyte(j));
         }

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

            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 = sf.createSession(true, true, 0);

         session.start();

         ClientConsumer consumer = session.createConsumer(ADDRESS);

         for (int i = 0; i < numberOfMessages / 2; i++)
         {
            ClientMessage message = consumer.receive(5000);
            assertNotNull(message);
            assertEquals(i, message.getIntProperty("id").intValue());

            if (i < 100)
            {
               // Do not consume the last one so we could restart
               message.acknowledge();
            }
         }

         session.close();
        
         session = null;

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

         locator = createInVMNonHALocator();

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

         session.start();

         consumer = session.createConsumer(ADDRESS);

         for (int i = 100; i < numberOfMessages; i++)
         {
            ClientMessage message = consumer.receive(5000);
            assertNotNull(message);
            assertEquals(i, message.getIntProperty("id").intValue());
            message.acknowledge();
         }
        
         session.close();
        
         sf.close();
View Full Code Here


                  ClientSession sess = sf.createSession(true, true, 0);
                  sess.start();
                  ClientConsumer cons = sess.createConsumer(ADDRESS);
                  for (int i = 0; i < numberOfMessages; i++)
                  {
                     ClientMessage msg = cons.receive(5000);
                     assertNotNull(msg);
                     assertEquals(i, msg.getIntProperty("id").intValue());
                     msg.acknowledge();
                  }

                  assertNull(cons.receiveImmediate());
                  sess.close();
                  sl.close();
               }
               catch (Throwable e)
               {
                  e.printStackTrace();
                  errors.incrementAndGet();
               }

            }
         };

         t1.start();

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

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

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

            producer.send(message);
            if (i % 20 == 0)
            {
               session.commit();
View Full Code Here

                  ClientSession sess = sf.createSession(true, true, 0);
                  sess.start();
                  ClientConsumer cons = sess.createConsumer(ADDRESS);
                  for (int i = 0; i < 100; i++)
                  {
                     ClientMessage msg = cons.receive(5000);
                     assertNotNull(msg);
                     assertEquals(i, msg.getIntProperty("id").intValue());
                     msg.acknowledge();
                  }
                  sess.close();
                  sl.close();
               }
               catch (Throwable e)
               {
                  e.printStackTrace();
                  errors.incrementAndGet();
               }

            }
         };

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

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

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

            producer.send(message);
            if (i % 20 == 0)
            {
               session.commit();
View Full Code Here

            bb.put(getSamplebyte(j));
         }

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

            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 = sf.createSession(false, false, 0);

         session.start();

         ClientConsumer consumer = session.createConsumer(ADDRESS);

         for (int i = 0; i < numberOfMessages / 2; i++)
         {
            ClientMessage message = consumer.receive(5000);
            assertNotNull(message);
            assertEquals(i, message.getIntProperty("id").intValue());
            message.acknowledge();
         }

         session.rollback();

         session.close();

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

         session.start();

         consumer = session.createConsumer(ADDRESS);

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage message = consumer.receive(5000);
            assertNotNull(message);
            assertEquals(i, message.getIntProperty("id").intValue());
            message.acknowledge();
         }

         session.commit();

      }
View Full Code Here

            bb.put(getSamplebyte(j));
         }

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

            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 = sf.createSession(false, false, 0);

         session.start();

         ClientConsumer consumer = session.createConsumer(ADDRESS);

         // number of references without paging
         int numberOfRefs = queue.getNumberOfReferences();

         // consume all non-paged references
         for (int ref = 0; ref < numberOfRefs; ref++)
         {
            ClientMessage msg = consumer.receive(5000);
            assertNotNull(msg);
            msg.acknowledge();
         }

         session.commit();

         session.close();

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

         session.start();

         consumer = session.createConsumer(ADDRESS);

         ClientMessage msg = consumer.receive(5000);
         assertNotNull(msg);
         int msgIDRolledBack = msg.getIntProperty("id").intValue();
         msg.acknowledge();

         session.rollback();

         msg = consumer.receive(5000);

         assertNotNull(msg);

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

         session.rollback();

         session.close();

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

         server.stop();

         server.start();

         locator = createInVMNonHALocator();

         locator.setClientFailureCheckPeriod(1000);
         locator.setConnectionTTL(2000);
         locator.setReconnectAttempts(0);

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

         sf = locator.createSessionFactory();

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

         session.start();

         consumer = session.createConsumer(ADDRESS);

         for (int i = msgIDRolledBack; i < numberOfMessages; i++)
         {
            ClientMessage message = consumer.receive(5000);
            assertNotNull(message);
            assertEquals(i, message.getIntProperty("id").intValue());
            message.acknowledge();
         }

         session.commit();

         session.close();
View Full Code Here

      XADummyEndpoint endpoint = new XADummyEndpoint(latch);
      DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
      qResourceAdapter.endpointActivation(endpointFactory, spec);
      ClientSession session = locator.createSessionFactory().createSession();
      ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
      ClientMessage message = session.createMessage(true);
      message.getBodyBuffer().writeString("teststring");
      clientProducer.send(message);
      session.close();
      latch.await(5, TimeUnit.SECONDS);

      assertNotNull(endpoint.lastMessage);
View Full Code Here

      XADummyEndpoint endpoint = new XADummyEndpoint(latch);
      DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
      qResourceAdapter.endpointActivation(endpointFactory, spec);
      ClientSession session = locator.createSessionFactory().createSession();
      ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
      ClientMessage message = session.createMessage(true);
      message.getBodyBuffer().writeString("teststring");
      clientProducer.send(message);
      session.close();
      latch.await(5, TimeUnit.SECONDS);

      assertNotNull(endpoint.lastMessage);
View Full Code Here

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

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

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

         assertTrue(ready.await(10, TimeUnit.SECONDS));

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

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage msg = consumer.receive(5000);
            assertNotNull(msg);
            log.info("Received " + i + " with property = " + msg.getIntProperty("count"));
            if (i != msg.getIntProperty("count").intValue())
            {
               log.info("###### different");
            }
            // assertEquals(i, msg.getIntProperty("count").intValue());
            msg.acknowledge();
         }

         session.close();

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