Java Code Examples for org.apache.activemq.artemis.api.core.client.ClientMessage#setDurable()

The following examples show how to use org.apache.activemq.artemis.api.core.client.ClientMessage#setDurable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LVQTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveMessageThroughManagement() throws Exception {

   Queue queue = server.locateQueue(qName1);
   ClientProducer producer = clientSession.createProducer(address);
   ClientConsumer consumer = clientSession.createConsumer(qName1);
   SimpleString rh = new SimpleString("SMID1");
   ClientMessage m1 = createTextMessage(clientSession, "m1");
   m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m1.setDurable(true);
   producer.send(m1);

   queue.deleteAllReferences();

   producer.send(m1);

   clientSession.start();
   ClientMessage m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m1");

   assertEquals(0, queue.getDeliveringCount());
}
 
Example 2
Source File: LVQTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleMessagesPersistedCorrectly() throws Exception {
   ClientProducer producer = clientSession.createProducer(address);
   ClientConsumer consumer = clientSession.createConsumer(qName1);
   SimpleString rh = new SimpleString("SMID1");
   ClientMessage m1 = createTextMessage(clientSession, "m1");
   m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m1.setDurable(true);
   ClientMessage m2 = createTextMessage(clientSession, "m2");
   m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m2.setDurable(true);
   ClientMessage m3 = createTextMessage(clientSession, "m3");
   m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m3.setDurable(true);
   ClientMessage m4 = createTextMessage(clientSession, "m4");
   m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m4.setDurable(true);
   ClientMessage m5 = createTextMessage(clientSession, "m5");
   m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m5.setDurable(true);
   ClientMessage m6 = createTextMessage(clientSession, "m6");
   m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m6.setDurable(true);
   producer.send(m1);
   producer.send(m2);
   producer.send(m3);
   producer.send(m4);
   producer.send(m5);
   producer.send(m6);
   clientSession.start();
   ClientMessage m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
   m = consumer.receiveImmediate();
   Assert.assertNull(m);
}
 
Example 3
Source File: LVQTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleMessagesPersistedCorrectlyInTx() throws Exception {
   ClientProducer producer = clientSessionTxSends.createProducer(address);
   ClientConsumer consumer = clientSessionTxSends.createConsumer(qName1);
   SimpleString rh = new SimpleString("SMID1");
   ClientMessage m1 = createTextMessage(clientSession, "m1");
   m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m1.setDurable(true);
   ClientMessage m2 = createTextMessage(clientSession, "m2");
   m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m2.setDurable(true);
   ClientMessage m3 = createTextMessage(clientSession, "m3");
   m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m3.setDurable(true);
   ClientMessage m4 = createTextMessage(clientSession, "m4");
   m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m4.setDurable(true);
   ClientMessage m5 = createTextMessage(clientSession, "m5");
   m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m5.setDurable(true);
   ClientMessage m6 = createTextMessage(clientSession, "m6");
   m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m6.setDurable(true);
   producer.send(m1);
   producer.send(m2);
   producer.send(m3);
   producer.send(m4);
   producer.send(m5);
   producer.send(m6);
   clientSessionTxSends.commit();
   clientSessionTxSends.start();
   ClientMessage m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
   m = consumer.receiveImmediate();
   Assert.assertNull(m);
}
 
Example 4
Source File: LVQTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleAcksPersistedCorrectly2() throws Exception {

   Queue queue = server.locateQueue(qName1);
   ClientProducer producer = clientSession.createProducer(address);
   ClientConsumer consumer = clientSession.createConsumer(qName1);
   SimpleString rh = new SimpleString("SMID1");
   ClientMessage m1 = createTextMessage(clientSession, "m1");
   m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m1.setDurable(true);
   ClientMessage m2 = createTextMessage(clientSession, "m2");
   m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m2.setDurable(true);
   clientSession.start();
   producer.send(m1);
   ClientMessage m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
   producer.send(m2);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m2");

   assertEquals(0, queue.getDeliveringCount());
}
 
Example 5
Source File: ScheduledMessageTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void testMessageDeliveredCorrectly(final boolean recover) throws Exception {

      // then we create a client as normal
      ClientSessionFactory sessionFactory = createSessionFactory(locator);
      ClientSession session = sessionFactory.createSession(false, true, false);
      session.createQueue(new QueueConfiguration(atestq));
      ClientProducer producer = session.createProducer(atestq);
      ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
      message.getBodyBuffer().writeString("testINVMCoreClient");
      message.setDurable(true);
      long time = System.currentTimeMillis();
      time += 10000;
      message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
      producer.send(message);

      if (recover) {
         producer.close();
         session.close();
         server.stop();
         server = null;
         server = createServer(true, configuration);
         server.start();
         sessionFactory = createSessionFactory(locator);
         session = sessionFactory.createSession(false, true, true);
      }
      ClientConsumer consumer = session.createConsumer(atestq);

      session.start();

      ClientMessage message2 = consumer.receive(11000);
      Assert.assertTrue(System.currentTimeMillis() >= time);
      Assert.assertEquals("testINVMCoreClient", message2.getBodyBuffer().readString());

      message2.acknowledge();

      // Make sure no more messages
      consumer.close();
      consumer = session.createConsumer(atestq);
      Assert.assertNull(consumer.receiveImmediate());

      session.close();
   }
 
Example 6
Source File: LVQRecoveryTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testManyMessagesReceivedWithRollback() throws Exception {
   Xid xid = new XidImpl("bq1".getBytes(), 4, "gtid1".getBytes());
   ClientProducer producer = clientSession.createProducer(address);
   ClientConsumer consumer = clientSessionXa.createConsumer(qName1);

   SimpleString rh = new SimpleString("SMID1");
   ClientMessage m1 = createTextMessage(clientSession, "m1");
   m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m1.setDurable(true);
   ClientMessage m2 = createTextMessage(clientSession, "m2");
   m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m2.setDurable(true);
   ClientMessage m3 = createTextMessage(clientSession, "m3");
   m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m3.setDurable(true);
   ClientMessage m4 = createTextMessage(clientSession, "m4");
   m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m4.setDurable(true);
   ClientMessage m5 = createTextMessage(clientSession, "m5");
   m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m5.setDurable(true);
   ClientMessage m6 = createTextMessage(clientSession, "m6");
   m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m6.setDurable(true);
   clientSessionXa.start(xid, XAResource.TMNOFLAGS);
   clientSessionXa.start();
   producer.send(m1);
   ClientMessage m = consumer.receive(1000);
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
   producer.send(m2);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
   producer.send(m3);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
   producer.send(m4);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
   producer.send(m5);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
   producer.send(m6);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
   clientSessionXa.end(xid, XAResource.TMSUCCESS);
   clientSessionXa.prepare(xid);

   clientSession.close();
   clientSessionXa.close();
   restartServer();

   clientSessionXa.rollback(xid);
   consumer = clientSession.createConsumer(qName1);
   clientSession.start();
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
   m = consumer.receiveImmediate();
   Assert.assertNull(m);
}
 
Example 7
Source File: LVQTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultipleAcksPersistedCorrectly() throws Exception {

   Queue queue = server.locateQueue(qName1);
   ClientProducer producer = clientSession.createProducer(address);
   ClientConsumer consumer = clientSession.createConsumer(qName1);
   SimpleString rh = new SimpleString("SMID1");
   ClientMessage m1 = createTextMessage(clientSession, "m1");
   m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m1.setDurable(true);
   ClientMessage m2 = createTextMessage(clientSession, "m2");
   m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m2.setDurable(true);
   ClientMessage m3 = createTextMessage(clientSession, "m3");
   m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m3.setDurable(true);
   ClientMessage m4 = createTextMessage(clientSession, "m4");
   m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m4.setDurable(true);
   ClientMessage m5 = createTextMessage(clientSession, "m5");
   m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m5.setDurable(true);
   ClientMessage m6 = createTextMessage(clientSession, "m6");
   m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m6.setDurable(true);
   clientSession.start();
   producer.send(m1);
   ClientMessage m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
   producer.send(m2);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
   producer.send(m3);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
   producer.send(m4);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
   producer.send(m5);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
   producer.send(m6);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m6");

   assertEquals(0, queue.getDeliveringCount());
}
 
Example 8
Source File: LVQTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultipleAcksPersistedCorrectlyInTx() throws Exception {
   ClientProducer producer = clientSessionTxReceives.createProducer(address);
   ClientConsumer consumer = clientSessionTxReceives.createConsumer(qName1);
   SimpleString rh = new SimpleString("SMID1");
   ClientMessage m1 = createTextMessage(clientSession, "m1");
   m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m1.setDurable(true);
   ClientMessage m2 = createTextMessage(clientSession, "m2");
   m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m2.setDurable(true);
   ClientMessage m3 = createTextMessage(clientSession, "m3");
   m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m3.setDurable(true);
   ClientMessage m4 = createTextMessage(clientSession, "m4");
   m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m4.setDurable(true);
   ClientMessage m5 = createTextMessage(clientSession, "m5");
   m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m5.setDurable(true);
   ClientMessage m6 = createTextMessage(clientSession, "m6");
   m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
   m6.setDurable(true);
   clientSessionTxReceives.start();
   producer.send(m1);
   ClientMessage m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
   producer.send(m2);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
   producer.send(m3);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
   producer.send(m4);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
   producer.send(m5);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
   producer.send(m6);
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
   clientSessionTxReceives.commit();
}