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

The following examples show how to use org.apache.activemq.artemis.api.core.client.ClientMessage#putBytesProperty() . 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: RemoteMessageQueue.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@Override
public boolean offer(InternalMessage message) {
    // see if we are recovering first
    if(this.recovering.get()) {
        throw new MessageDeliveryException("MessagingService is recovering",true);
    }

    ClientMessage clientMessage = clientSession.createMessage(message.isDurable());
    clientMessage.getBodyBuffer().writeBytes(message.toByteArray());
    clientMessage.putStringProperty("routingKey", routingKey);
    // duplicate detection
    clientMessage.putBytesProperty(HDR_DUPLICATE_DETECTION_ID, toByteArray(message.getId()));
    // set timeout if needed
    if(message.getTimeout() >= 0) {
        clientMessage.setExpiration(System.currentTimeMillis() + message.getTimeout());
    }
    try {
        producer.send(clientMessage);
        return true;
    } catch (ActiveMQException e) {
        throw new MessageDeliveryException("IOException while publishing message",e,false);
    } /*catch(SomeRecoverableException e) { @todo: figure out which exceptions are recoverable
        this.recovering.set(true);
        throw new MessageDeliveryException("MessagingService is recovering",true);
    } */

}
 
Example 2
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testRollbackThenSend() throws Exception {
   ClientSession session = sf.createSession(false, false, false);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   ClientMessage message = createMessage(session, 0);
   SimpleString dupID1 = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID1.getData());
   message.putStringProperty("key", dupID1.toString());
   producer.send(message);

   session.rollback();

   message = createMessage(session, 0);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID1.getData());
   message.putStringProperty("key", dupID1.toString());
   producer.send(message);

   session.commit();

   message = consumer.receive(5000);
   assertNotNull(message);
   assertTrue(message.getStringProperty("key").equals(dupID1.toString()));
}
 
Example 3
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void testDuplicateIDCacheMemoryRetention(boolean temporary) throws Exception {
   final int TEST_SIZE = 100;

   locator = createInVMNonHALocator().setBlockOnNonDurableSend(true);

   sf = createSessionFactory(locator);

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

   session.start();

   Assert.assertEquals(0, ((PostOfficeImpl) server.getPostOffice()).getDuplicateIDCaches().size());

   final SimpleString addressName = new SimpleString("DuplicateDetectionTestAddress");

   for (int i = 0; i < TEST_SIZE; i++) {
      final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue_" + i);

      session.createQueue(new QueueConfiguration(queueName).setAddress(addressName).setDurable(!temporary).setTemporary(temporary));

      ClientProducer producer = session.createProducer(addressName);

      ClientConsumer consumer = session.createConsumer(queueName);

      ClientMessage message = createMessage(session, 1);
      SimpleString dupID = new SimpleString("abcdefg");
      message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
      producer.send(message);
      ClientMessage message2 = consumer.receive(1000);
      Assert.assertEquals(1, message2.getObjectProperty(propKey));

      message = createMessage(session, 2);
      message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
      producer.send(message);
      message2 = consumer.receiveImmediate();
      Assert.assertNull(message2);

      message = createMessage(session, 3);
      message.putBytesProperty(Message.HDR_BRIDGE_DUPLICATE_ID, dupID.getData());
      producer.send(message);
      message2 = consumer.receive(1000);
      Assert.assertEquals(3, message2.getObjectProperty(propKey));

      message = createMessage(session, 4);
      message.putBytesProperty(Message.HDR_BRIDGE_DUPLICATE_ID, dupID.getData());
      producer.send(message);
      message2 = consumer.receiveImmediate();
      Assert.assertNull(message2);

      producer.close();
      consumer.close();

      // there will be 2 ID caches, one for messages using "_AMQ_DUPL_ID" and one for "_AMQ_BRIDGE_DUP"
      Assert.assertEquals(2, ((PostOfficeImpl) server.getPostOffice()).getDuplicateIDCaches().size());
      session.deleteQueue(queueName);
      Assert.assertEquals(0, ((PostOfficeImpl) server.getPostOffice()).getDuplicateIDCaches().size());
   }

   Assert.assertEquals(0, ((PostOfficeImpl) server.getPostOffice()).getDuplicateIDCaches().size());
}
 
Example 4
Source File: AlmostLargeAsynchronousFailoverTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
protected void addPayload(ClientMessage message) {
   message.putBytesProperty("payload", new byte[20 * 1024]);
}
 
Example 5
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testTransactedDuplicateDetection3() throws Exception {
   ClientSession session = sf.createSession(false, false, false);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   ClientMessage message = createMessage(session, 0);
   SimpleString dupID1 = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID1.getData());
   producer.send(message);

   message = createMessage(session, 1);
   SimpleString dupID2 = new SimpleString("hijklmno");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);

   session.commit();

   // These next two should get rejected

   message = createMessage(session, 2);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID1.getData());
   producer.send(message);

   message = createMessage(session, 3);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);

   try {
      session.commit();
   } catch (Exception e) {
      session.rollback();
   }

   message = consumer.receive(250);
   Assert.assertEquals(0, message.getObjectProperty(propKey));

   message = consumer.receive(250);
   Assert.assertEquals(1, message.getObjectProperty(propKey));

   message = consumer.receiveImmediate();
   Assert.assertNull(message);
}
 
Example 6
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSimpleDuplicateDetecion() throws Exception {
   ClientSession session = sf.createSession(false, true, true);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   ClientMessage message = createMessage(session, 0);
   producer.send(message);
   ClientMessage message2 = consumer.receive(1000);
   Assert.assertEquals(0, message2.getObjectProperty(propKey));

   message = createMessage(session, 1);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);
   message2 = consumer.receive(1000);
   Assert.assertEquals(1, message2.getObjectProperty(propKey));

   message = createMessage(session, 2);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);
   message2 = consumer.receiveImmediate();
   Assert.assertNull(message2);

   message = createMessage(session, 3);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);
   message2 = consumer.receiveImmediate();
   Assert.assertNull(message2);

   // Now try with a different id

   message = createMessage(session, 4);
   SimpleString dupID2 = new SimpleString("hijklmnop");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);
   message2 = consumer.receive(1000);
   Assert.assertEquals(4, message2.getObjectProperty(propKey));

   message = createMessage(session, 5);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);
   message2 = consumer.receiveImmediate();
   Assert.assertNull(message2);

   message = createMessage(session, 6);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);
   message2 = consumer.receiveImmediate();
   Assert.assertNull(message2);
}
 
Example 7
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@Test
public void testTransactedDuplicateDetection2() throws Exception {
   ClientSession session = sf.createSession(false, false, false);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   ClientMessage message = createMessage(session, 0);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.rollback();

   // Should be able to resend it and not get rejected since transaction didn't commit

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.commit();

   message = consumer.receive(250);
   Assert.assertEquals(1, message.getObjectProperty(propKey));

   message = consumer.receiveImmediate();
   Assert.assertNull(message);
}
 
Example 8
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testEntireTransactionRejected() throws Exception {
   ClientSession session = sf.createSession(false, false, false);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   final SimpleString queue2 = new SimpleString("queue2");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   session.createQueue(new QueueConfiguration(queue2).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientMessage message = createMessage(session, 0);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   ClientMessage message2 = createMessage(session, 0);
   ClientProducer producer2 = session.createProducer(queue2);
   producer2.send(message2);

   session.commit();

   session.close();

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

   session.start();

   ClientConsumer consumer2 = session.createConsumer(queue2);

   producer = session.createProducer(queueName);

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   message = createMessage(session, 2);
   producer.send(message);

   message = createMessage(session, 3);
   producer.send(message);

   message = createMessage(session, 4);
   producer.send(message);

   message = consumer2.receive(5000);
   assertNotNull(message);
   message.acknowledge();

   try {
      session.commit();
   } catch (ActiveMQDuplicateIdException die) {
      session.rollback();
   } catch (ActiveMQException e) {
      fail("Invalid Exception type:" + e.getType());
   }

   ClientConsumer consumer = session.createConsumer(queueName);

   message = consumer.receive(250);
   Assert.assertEquals(0, message.getObjectProperty(propKey));

   message = consumer.receiveImmediate();
   Assert.assertNull(message);

   message = consumer2.receive(5000);
   assertNotNull(message);

   message.acknowledge();

   session.commit();
}
 
Example 9
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testXADuplicateDetection1() throws Exception {
   ClientSession session = sf.createSession(true, false, false);

   Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid, XAResource.TMNOFLAGS);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientMessage message = createMessage(session, 0);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.end(xid, XAResource.TMSUCCESS);

   session.close();

   Xid xid2 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

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

   session.start(xid2, XAResource.TMNOFLAGS);

   session.start();

   producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   // Should be able to resend it and not get rejected since transaction didn't commit

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.end(xid2, XAResource.TMSUCCESS);

   session.prepare(xid2);

   session.commit(xid2, false);

   Xid xid3 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid3, XAResource.TMNOFLAGS);

   message = consumer.receive(250);
   Assert.assertEquals(1, message.getObjectProperty(propKey));

   message = consumer.receiveImmediate();
   Assert.assertNull(message);

   log.debug("ending session");
   session.end(xid3, XAResource.TMSUCCESS);

   log.debug("preparing session");
   session.prepare(xid3);

   log.debug("committing session");
   session.commit(xid3, false);
}
 
Example 10
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testXADuplicateDetection2() throws Exception {
   ClientSession session = sf.createSession(true, false, false);

   Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid, XAResource.TMNOFLAGS);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientMessage message = createMessage(session, 0);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.end(xid, XAResource.TMSUCCESS);

   session.rollback(xid);

   session.close();

   Xid xid2 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

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

   session.start(xid2, XAResource.TMNOFLAGS);

   session.start();

   producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   // Should be able to resend it and not get rejected since transaction didn't commit

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.end(xid2, XAResource.TMSUCCESS);

   session.prepare(xid2);

   session.commit(xid2, false);

   Xid xid3 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid3, XAResource.TMNOFLAGS);

   message = consumer.receive(250);
   Assert.assertEquals(1, message.getObjectProperty(propKey));

   message = consumer.receiveImmediate();
   Assert.assertNull(message);

   log.debug("ending session");
   session.end(xid3, XAResource.TMSUCCESS);

   log.debug("preparing session");
   session.prepare(xid3);

   log.debug("committing session");
   session.commit(xid3, false);
}
 
Example 11
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testXADuplicateDetection3() throws Exception {
   ClientSession session = sf.createSession(true, false, false);

   Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid, XAResource.TMNOFLAGS);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientMessage message = createMessage(session, 0);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.end(xid, XAResource.TMSUCCESS);

   session.prepare(xid);

   session.close();

   Xid xid2 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

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

   session.start(xid2, XAResource.TMNOFLAGS);

   session.start();

   producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   // Should NOT be able to resend it

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.end(xid2, XAResource.TMSUCCESS);

   session.prepare(xid2);

   session.commit(xid2, false);

   Xid xid3 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid3, XAResource.TMNOFLAGS);

   consumer.receive(250);

   message = consumer.receiveImmediate();
   Assert.assertNull(message);

   log.debug("ending session");
   session.end(xid3, XAResource.TMSUCCESS);

   log.debug("preparing session");
   session.prepare(xid3);

   log.debug("committing session");
   session.commit(xid3, false);
}
 
Example 12
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testXADuplicateDetectionPrepareAndRollback() throws Exception {
   ClientSession session = sf.createSession(true, false, false);

   Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid, XAResource.TMNOFLAGS);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientMessage message = createMessage(session, 0);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.end(xid, XAResource.TMSUCCESS);

   session.prepare(xid);

   session.rollback(xid);

   session.close();

   Xid xid2 = new XidImpl("xa2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

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

   session.start(xid2, XAResource.TMNOFLAGS);

   session.start();

   producer = session.createProducer(queueName);

   producer.send(message);

   session.end(xid2, XAResource.TMSUCCESS);

   session.prepare(xid2);

   session.commit(xid2, false);

   session.close();

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

   session.start();

   ClientConsumer consumer = session.createConsumer(queueName);

   ClientMessage msgRec = consumer.receive(5000);
   assertNotNull(msgRec);
   msgRec.acknowledge();

   session.commit();
}
 
Example 13
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testXADuplicateDetectionPrepareAndRollbackStopServer() throws Exception {
   ClientSession session = sf.createSession(true, false, false);

   Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid, XAResource.TMNOFLAGS);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName));

   ClientProducer producer = session.createProducer(queueName);

   ClientMessage message = createMessage(session, 0);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.end(xid, XAResource.TMSUCCESS);

   session.prepare(xid);

   session.close();

   server.stop();

   waitForServerToStop(server);

   server.start();

   sf = createSessionFactory(locator);

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

   session.start(xid, XAResource.TMJOIN);

   session.end(xid, XAResource.TMSUCCESS);

   session.rollback(xid);

   session.close();

   Xid xid2 = new XidImpl("xa2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

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

   session.start(xid2, XAResource.TMNOFLAGS);

   session.start();

   producer = session.createProducer(queueName);

   producer.send(message);

   session.end(xid2, XAResource.TMSUCCESS);

   session.prepare(xid2);

   session.commit(xid2, false);

   session.close();

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

   session.start();

   ClientConsumer consumer = session.createConsumer(queueName);

   ClientMessage msgRec = consumer.receive(5000);
   assertNotNull(msgRec);
   msgRec.acknowledge();

   session.commit();
}
 
Example 14
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testXADuplicateDetection4() throws Exception {
   ClientSession session = sf.createSession(true, false, false);

   Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid, XAResource.TMNOFLAGS);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientMessage message = createMessage(session, 0);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.end(xid, XAResource.TMSUCCESS);

   session.prepare(xid);

   session.commit(xid, false);

   session.close();

   Xid xid2 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

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

   session.start(xid2, XAResource.TMNOFLAGS);

   session.start();

   producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   // Should NOT be able to resend it

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.end(xid2, XAResource.TMSUCCESS);

   try {
      session.prepare(xid2);
      fail("Should throw an exception here!");
   } catch (XAException expected) {
      assertTrue(expected.getCause().toString().contains("DUPLICATE_ID_REJECTED"));
   }

   session.rollback(xid2);

   Xid xid3 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid3, XAResource.TMNOFLAGS);

   consumer.receive(250);

   message = consumer.receiveImmediate();
   Assert.assertNull(message);

   log.debug("ending session");
   session.end(xid3, XAResource.TMSUCCESS);

   log.debug("preparing session");
   session.prepare(xid3);

   log.debug("committing session");
   session.commit(xid3, false);
}
 
Example 15
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testDuplicateCachePersisted() throws Exception {
   server.stop();

   config = createDefaultInVMConfig().setIDCacheSize(cacheSize);

   server = createServer(config);

   server.start();

   sf = createSessionFactory(locator);

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

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   ClientMessage message = createMessage(session, 1);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);
   ClientMessage message2 = consumer.receive(1000);
   Assert.assertEquals(1, message2.getObjectProperty(propKey));

   message = createMessage(session, 2);
   SimpleString dupID2 = new SimpleString("hijklmnopqr");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);
   message2 = consumer.receive(1000);
   Assert.assertEquals(2, message2.getObjectProperty(propKey));

   session.close();

   sf.close();

   server.stop();

   waitForServerToStop(server);

   server.start();

   sf = createSessionFactory(locator);

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

   session.start();

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   producer = session.createProducer(queueName);

   consumer = session.createConsumer(queueName);

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);
   message2 = consumer.receiveImmediate();
   Assert.assertNull(message2);

   message = createMessage(session, 2);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);
   message2 = consumer.receiveImmediate();
   Assert.assertNull(message2);
}
 
Example 16
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testNoPersist() throws Exception {
   server.stop();

   config = createDefaultInVMConfig().setIDCacheSize(cacheSize).setPersistIDCache(false);

   server = createServer(config);

   server.start();

   sf = createSessionFactory(locator);

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

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   ClientMessage message = createMessage(session, 1);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);
   ClientMessage message2 = consumer.receive(1000);
   Assert.assertEquals(1, message2.getObjectProperty(propKey));

   message = createMessage(session, 2);
   SimpleString dupID2 = new SimpleString("hijklmnopqr");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);
   message2 = consumer.receive(1000);
   Assert.assertEquals(2, message2.getObjectProperty(propKey));

   session.close();

   sf.close();

   server.stop();

   waitForServerToStop(server);

   server.start();

   sf = createSessionFactory(locator);

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

   session.start();

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   producer = session.createProducer(queueName);

   consumer = session.createConsumer(queueName);

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);
   message2 = consumer.receive(200);
   Assert.assertEquals(1, message2.getObjectProperty(propKey));

   message = createMessage(session, 2);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);
   message2 = consumer.receive(200);
   Assert.assertEquals(2, message2.getObjectProperty(propKey));
}
 
Example 17
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testNoPersistTransactional() throws Exception {
   server.stop();

   config = createDefaultInVMConfig().setIDCacheSize(cacheSize).setPersistIDCache(false);

   server = createServer(config);

   server.start();

   sf = createSessionFactory(locator);

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

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   ClientMessage message = createMessage(session, 1);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);
   session.commit();
   ClientMessage message2 = consumer.receive(1000);
   Assert.assertEquals(1, message2.getObjectProperty(propKey));

   message = createMessage(session, 2);
   SimpleString dupID2 = new SimpleString("hijklmnopqr");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);
   session.commit();
   message2 = consumer.receive(1000);
   Assert.assertEquals(2, message2.getObjectProperty(propKey));

   session.close();

   sf.close();

   server.stop();

   waitForServerToStop(server);

   server.start();

   sf = createSessionFactory(locator);

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

   session.start();

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   producer = session.createProducer(queueName);

   consumer = session.createConsumer(queueName);

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);
   session.commit();
   message2 = consumer.receive(200);
   Assert.assertEquals(1, message2.getObjectProperty(propKey));

   message = createMessage(session, 2);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);
   session.commit();
   message2 = consumer.receive(200);
   Assert.assertEquals(2, message2.getObjectProperty(propKey));
}
 
Example 18
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testNoPersistXA1() throws Exception {
   server.stop();

   config = createDefaultInVMConfig().setIDCacheSize(cacheSize).setPersistIDCache(false);

   server = createServer(config);

   server.start();

   sf = createSessionFactory(locator);

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

   Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid, XAResource.TMNOFLAGS);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   ClientMessage message = createMessage(session, 1);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   message = createMessage(session, 2);
   SimpleString dupID2 = new SimpleString("hijklmnopqr");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);

   session.end(xid, XAResource.TMSUCCESS);
   session.prepare(xid);
   session.commit(xid, false);

   session.close();

   sf.close();

   server.stop();

   waitForServerToStop(server);

   server.start();

   sf = createSessionFactory(locator);

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

   Xid xid2 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid2, XAResource.TMNOFLAGS);

   session.start();

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   producer = session.createProducer(queueName);

   consumer = session.createConsumer(queueName);

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   message = createMessage(session, 2);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);

   session.end(xid2, XAResource.TMSUCCESS);
   session.prepare(xid2);
   session.commit(xid2, false);

   Xid xid3 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid3, XAResource.TMNOFLAGS);

   ClientMessage message2 = consumer.receive(200);
   Assert.assertEquals(1, message2.getObjectProperty(propKey));

   message2 = consumer.receive(200);
   Assert.assertEquals(2, message2.getObjectProperty(propKey));
}
 
Example 19
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testTransactedDuplicateDetection1() throws Exception {
   ClientSession session = sf.createSession(false, false, false);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientMessage message = createMessage(session, 0);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.close();

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

   session.start();

   producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   // Should be able to resend it and not get rejected since transaction didn't commit

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   session.commit();

   message = consumer.receive(250);
   Assert.assertEquals(1, message.getObjectProperty(propKey));

   message = consumer.receiveImmediate();
   Assert.assertNull(message);
}
 
Example 20
Source File: DuplicateDetectionTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testPersistXA1() throws Exception {
   ClientSession session = addClientSession(sf.createSession(true, false, false));

   Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid, XAResource.TMNOFLAGS);

   session.start();

   final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   ClientProducer producer = session.createProducer(queueName);

   ClientConsumer consumer = session.createConsumer(queueName);

   ClientMessage message = createMessage(session, 1);
   SimpleString dupID = new SimpleString("abcdefg");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   message = createMessage(session, 2);
   SimpleString dupID2 = new SimpleString("hijklmnopqr");
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);

   session.end(xid, XAResource.TMSUCCESS);
   session.prepare(xid);
   session.commit(xid, false);

   session.close();

   sf.close();

   server.stop();

   waitForServerToStop(server);

   server.start();

   sf = createSessionFactory(locator);

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

   Xid xid2 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid2, XAResource.TMNOFLAGS);

   session.start();

   session.createQueue(new QueueConfiguration(queueName).setDurable(false));

   producer = session.createProducer(queueName);

   consumer = session.createConsumer(queueName);

   message = createMessage(session, 1);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
   producer.send(message);

   message = createMessage(session, 2);
   message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
   producer.send(message);

   session.end(xid2, XAResource.TMSUCCESS);
   try {
      session.prepare(xid2);
      fail("Should throw an exception here!");
   } catch (XAException expected) {
   }

   session.rollback(xid2);

   Xid xid3 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   session.start(xid3, XAResource.TMNOFLAGS);

   ClientMessage message2 = consumer.receiveImmediate();
   Assert.assertNull(message2);

   message2 = consumer.receiveImmediate();
   Assert.assertNull(message2);
}