Java Code Examples for org.apache.activemq.artemis.api.core.client.ClientMessage#acknowledge()
The following examples show how to use
org.apache.activemq.artemis.api.core.client.ClientMessage#acknowledge() .
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: NIOvsOIOTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void onMessage(ClientMessage msg) { try { msg.acknowledge(); } catch (Exception e) { log.error("Caught exception", e); } count++; if (count == numMessages) { latch.countDown(); } //log.debug(id + " got msg " + count); }
Example 2
Source File: QueueConsumer.java From activemq-artemis with Apache License 2.0 | 6 votes |
protected Response pollWithIndex(long wait, UriInfo info, String basePath, long index) { try { ClientMessage message = receive(wait); if (message == null) { Response.ResponseBuilder builder = Response.status(503).entity("Timed out waiting for message receive.").type("text/plain"); setPollTimeoutLinks(info, basePath, builder, Long.toString(index)); return builder.build(); } previousIndex = index; lastConsumed = ConsumedMessage.createConsumedMessage(message, this.getJmsOptions()); String token = Long.toString(lastConsumed.getMessageID()); Response response = getMessageResponse(lastConsumed, info, basePath, token).build(); if (autoAck) message.acknowledge(); return response; } catch (Exception e) { Response errorResponse = Response.serverError().entity(e.getMessage()).status(Response.Status.INTERNAL_SERVER_ERROR).build(); return errorResponse; } }
Example 3
Source File: WildCardRoutingTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testWildcardRoutingStarInMiddle() throws Exception { SimpleString addressAB = new SimpleString("a.b.c"); SimpleString addressAC = new SimpleString("a.c"); SimpleString address = new SimpleString("*.b.*"); SimpleString queueName1 = new SimpleString("Q1"); SimpleString queueName2 = new SimpleString("Q2"); SimpleString queueName = new SimpleString("Q"); clientSession.createQueue(new QueueConfiguration(queueName1).setAddress(addressAB).setDurable(false)); clientSession.createQueue(new QueueConfiguration(queueName2).setAddress(addressAC).setDurable(false)); clientSession.createQueue(new QueueConfiguration(queueName).setAddress(address).setDurable(false)); ClientProducer producer = clientSession.createProducer(addressAB); ClientProducer producer2 = clientSession.createProducer(addressAC); ClientConsumer clientConsumer = clientSession.createConsumer(queueName); clientSession.start(); producer.send(createTextMessage(clientSession, "m1")); producer2.send(createTextMessage(clientSession, "m2")); ClientMessage m = clientConsumer.receive(500); Assert.assertNotNull(m); Assert.assertEquals("m1", m.getBodyBuffer().readString()); m.acknowledge(); m = clientConsumer.receiveImmediate(); Assert.assertNull(m); }
Example 4
Source File: AutoCreateDeadLetterResourcesTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void triggerDlaDelivery() throws Exception { try { server.createQueue(new QueueConfiguration(queueA).setAddress(addressA).setRoutingType(RoutingType.ANYCAST)); } catch (Exception e) { // ignore } ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory sessionFactory = createSessionFactory(locator); ClientSession session = addClientSession(sessionFactory.createSession(true, false)); ClientProducer producer = addClientProducer(session.createProducer(addressA)); producer.send(session.createMessage(true)); producer.close(); ClientConsumer consumer = addClientConsumer(session.createConsumer(queueA)); session.start(); ClientMessage message = consumer.receive(); assertNotNull(message); message.acknowledge(); session.rollback(); session.close(); sessionFactory.close(); locator.close(); }
Example 5
Source File: RoutingTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testRouteToSingleDurableQueue() throws Exception { ClientSession sendSession = cf.createSession(false, true, true); sendSession.createQueue(new QueueConfiguration(queueA).setAddress(addressA)); int numMessages = 300; ClientProducer p = sendSession.createProducer(addressA); for (int i = 0; i < numMessages; i++) { p.send(sendSession.createMessage(false)); } ClientSession session = cf.createSession(false, true, true); ClientConsumer c1 = session.createConsumer(queueA); session.start(); for (int i = 0; i < numMessages; i++) { ClientMessage m = c1.receive(5000); Assert.assertNotNull(m); m.acknowledge(); } Assert.assertNull(c1.receiveImmediate()); sendSession.close(); session.close(); }
Example 6
Source File: WildCardRoutingTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testLargeWildcardRouting() throws Exception { SimpleString addressAB = new SimpleString("a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z"); SimpleString addressAC = new SimpleString("a.c"); SimpleString address = new SimpleString("a.#"); SimpleString queueName1 = new SimpleString("Q1"); SimpleString queueName2 = new SimpleString("Q2"); SimpleString queueName = new SimpleString("Q"); clientSession.createQueue(new QueueConfiguration(queueName1).setAddress(addressAB).setDurable(false)); clientSession.createQueue(new QueueConfiguration(queueName2).setAddress(addressAC).setDurable(false)); clientSession.createQueue(new QueueConfiguration(queueName).setAddress(address).setDurable(false)); Assert.assertEquals(2, server.getPostOffice().getBindingsForAddress(addressAB).getBindings().size()); Assert.assertEquals(2, server.getPostOffice().getBindingsForAddress(addressAC).getBindings().size()); Assert.assertEquals(1, server.getPostOffice().getBindingsForAddress(address).getBindings().size()); ClientProducer producer = clientSession.createProducer(addressAB); ClientProducer producer2 = clientSession.createProducer(addressAC); ClientConsumer clientConsumer = clientSession.createConsumer(queueName); clientSession.start(); producer.send(createTextMessage(clientSession, "m1")); producer2.send(createTextMessage(clientSession, "m2")); ClientMessage m = clientConsumer.receive(500); Assert.assertNotNull(m); Assert.assertEquals("m1", m.getBodyBuffer().readString()); m.acknowledge(); m = clientConsumer.receive(500); Assert.assertNotNull(m); Assert.assertEquals("m2", m.getBodyBuffer().readString()); m.acknowledge(); m = clientConsumer.receiveImmediate(); Assert.assertNull(m); clientConsumer.close(); clientSession.deleteQueue(queueName); Assert.assertEquals(1, server.getPostOffice().getBindingsForAddress(addressAB).getBindings().size()); Assert.assertEquals(1, server.getPostOffice().getBindingsForAddress(addressAC).getBindings().size()); Assert.assertEquals(0, server.getPostOffice().getBindingsForAddress(address).getBindings().size()); }
Example 7
Source File: BMFailoverTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test @BMRules( rules = {@BMRule( name = "trace clientsessionimpl commit", targetClass = "org.apache.activemq.artemis.core.client.impl.ClientSessionImpl", targetMethod = "commit", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.BMFailoverTest.serverToStop.getServer().stop(true)")}) public void testFailoverOnReceiveCommit() throws Exception { serverToStop = liveServer; locator = getServerLocator(); createSessionFactory(); ClientSession session = createSessionAndQueue(); ClientSession sendSession = createSession(sf, true, true); ClientProducer producer = addClientProducer(sendSession.createProducer(FailoverTestBase.ADDRESS)); sendMessages(sendSession, producer, 10); ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS); session.start(); for (int i = 0; i < 10; i++) { ClientMessage m = consumer.receive(500); assertNotNull(m); m.acknowledge(); } try { session.commit(); fail("should have thrown an exception"); } catch (ActiveMQTransactionOutcomeUnknownException e) { //pass } catch (ActiveMQTransactionRolledBackException e1) { //pass } Queue bindable = (Queue) backupServer.getServer().getPostOffice().getBinding(FailoverTestBase.ADDRESS).getBindable(); assertEquals(10, getMessageCount(bindable)); }
Example 8
Source File: BasicXaTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testRestartWithTXPrepareDeletedQueue() throws Exception { ClientSession clientSession2 = sessionFactory.createSession(false, true, true); ClientProducer clientProducer = clientSession2.createProducer(atestq); ClientMessage m1 = createTextMessage(clientSession2, "m1"); clientProducer.send(m1); Xid xid = newXID(); clientSession.start(xid, XAResource.TMNOFLAGS); clientSession.start(); ClientConsumer clientConsumer = clientSession.createConsumer(atestq); ClientMessage message = clientConsumer.receive(5000); message.acknowledge(); clientSession.end(xid, XAResource.TMSUCCESS); clientSession.prepare(xid); Queue queueAtestQ = messagingService.locateQueue(atestq); Assert.assertNotNull(queueAtestQ); clientSession.getSessionFactory().getConnection().destroy(); Wait.assertEquals(0, queueAtestQ::getConsumerCount); messagingService.destroyQueue(atestq); messagingService.stop(); messagingService.start(); messagingService.waitForActivation(10, TimeUnit.SECONDS); assertTrue(messagingService.isStarted()); }
Example 9
Source File: LVQTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@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 10
Source File: ReceiveImmediateTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private void doConsumerReceiveImmediate(final boolean browser) throws Exception { locator.setBlockOnNonDurableSend(true).setBlockOnAcknowledge(true).setAckBatchSize(0); sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, true, true); session.createQueue(new QueueConfiguration(QUEUE).setAddress(ADDRESS).setDurable(false)); ClientProducer producer = session.createProducer(ADDRESS); final int numMessages = 100; for (int i = 0; i < numMessages; i++) { ClientMessage message = createTextMessage(session, "m" + i); producer.send(message); } ClientConsumer consumer = session.createConsumer(QUEUE, null, browser); session.start(); for (int i = 0; i < numMessages; i++) { ClientMessage message2 = consumer.receiveImmediate(); Assert.assertNotNull("did not receive message " + i, message2); Assert.assertEquals("m" + i, message2.getBodyBuffer().readString()); if (!browser) { message2.acknowledge(); } } Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(QUEUE).getBindable()).getDeliveringCount()); Assert.assertNull(consumer.receiveImmediate()); Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(QUEUE).getBindable()).getDeliveringCount()); int messagesOnServer = browser ? numMessages : 0; Assert.assertEquals(messagesOnServer, getMessageCount(((Queue) server.getPostOffice().getBinding(QUEUE).getBindable()))); consumer.close(); session.close(); }
Example 11
Source File: XaTimeoutTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testPreparedTransactionNotTimedOut() throws Exception { Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes()); ClientMessage m1 = createTextMessage(clientSession, "m1"); ClientMessage m2 = createTextMessage(clientSession, "m2"); ClientMessage m3 = createTextMessage(clientSession, "m3"); ClientMessage m4 = createTextMessage(clientSession, "m4"); ClientMessage m5 = createTextMessage(clientSession, "m5"); ClientMessage m6 = createTextMessage(clientSession, "m6"); ClientMessage m7 = createTextMessage(clientSession, "m7"); ClientMessage m8 = createTextMessage(clientSession, "m8"); ClientSession clientSession2 = sessionFactory.createSession(false, true, true); ClientProducer clientProducer2 = clientSession2.createProducer(atestq); clientProducer2.send(m1); clientProducer2.send(m2); clientProducer2.send(m3); clientProducer2.send(m4); clientSession2.close(); clientSession.setTransactionTimeout(2); clientSession.start(xid, XAResource.TMNOFLAGS); clientSession.start(); clientProducer.send(m5); clientProducer.send(m6); clientProducer.send(m7); clientProducer.send(m8); ClientMessage m = clientConsumer.receive(500); m.acknowledge(); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m1"); m = clientConsumer.receive(500); Assert.assertNotNull(m); m.acknowledge(); Assert.assertEquals(m.getBodyBuffer().readString(), "m2"); m = clientConsumer.receive(500); m.acknowledge(); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m3"); m = clientConsumer.receive(500); m.acknowledge(); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m4"); clientSession.end(xid, XAResource.TMSUCCESS); clientSession.prepare(xid); CountDownLatch latch = new CountDownLatch(1); server.getResourceManager().getTransaction(xid).addOperation(new RollbackCompleteOperation(latch)); Assert.assertFalse(latch.await(2600, TimeUnit.MILLISECONDS)); clientSession.commit(xid, false); clientSession.setTransactionTimeout(0); clientConsumer.close(); clientSession2 = sessionFactory.createSession(false, true, true); ClientConsumer consumer = clientSession2.createConsumer(atestq); clientSession2.start(); m = consumer.receive(500); m.acknowledge(); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m5"); m = consumer.receive(500); Assert.assertNotNull(m); m.acknowledge(); Assert.assertEquals(m.getBodyBuffer().readString(), "m6"); m = consumer.receive(500); m.acknowledge(); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m7"); m = consumer.receive(500); m.acknowledge(); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m8"); m = consumer.receiveImmediate(); Assert.assertNull(m); clientSession2.close(); }
Example 12
Source File: LVQTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testManyMessagesReceivedAndCancelled() 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); ClientMessage m2 = createTextMessage(clientSession, "m2"); m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); ClientMessage m3 = createTextMessage(clientSession, "m3"); m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); ClientMessage m4 = createTextMessage(clientSession, "m4"); m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); ClientMessage m5 = createTextMessage(clientSession, "m5"); m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); ClientMessage m6 = createTextMessage(clientSession, "m6"); m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); clientSession.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"); consumer.close(); consumer = clientSession.createConsumer(qName1); m = consumer.receive(1000); Assert.assertNotNull(m); m.acknowledge(); Assert.assertEquals(m.getBodyBuffer().readString(), "m6"); m = consumer.receiveImmediate(); Assert.assertNull(m); }
Example 13
Source File: LVQTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@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(); }
Example 14
Source File: QueueControlTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
/** * <ol> * <li>send a message to queue</li> * <li>move all messages from queue to otherQueue using management method</li> * <li>check there is no message to consume from queue</li> * <li>consume the message from otherQueue</li> * </ol> */ @Test public void testMoveMessages() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); SimpleString queue = RandomUtil.randomSimpleString(); SimpleString otherAddress = RandomUtil.randomSimpleString(); SimpleString otherQueue = RandomUtil.randomSimpleString(); session.createQueue(new QueueConfiguration(queue).setAddress(address).setDurable(durable)); session.createQueue(new QueueConfiguration(otherQueue).setAddress(otherAddress).setDurable(durable)); ClientProducer producer = session.createProducer(address); // send on queue ClientMessage message = session.createMessage(durable); SimpleString key = RandomUtil.randomSimpleString(); long value = RandomUtil.randomLong(); message.putLongProperty(key, value); producer.send(message); final LocalQueueBinding binding = (LocalQueueBinding) server.getPostOffice().getBinding(queue); Queue q = binding.getQueue(); Field queueMemorySizeField = QueueImpl.class.getDeclaredField("queueMemorySize"); queueMemorySizeField.setAccessible(true); //Get memory size counters to verify AtomicInteger queueMemorySize = (AtomicInteger) queueMemorySizeField.get(q); QueueControl queueControl = createManagementControl(address, queue); assertMessageMetrics(queueControl, 1, durable); //verify memory usage is greater than 0 Assert.assertTrue(queueMemorySize.get() > 0); // moved all messages to otherQueue int movedMessagesCount = queueControl.moveMessages(null, otherQueue.toString()); Assert.assertEquals(1, movedMessagesCount); assertMessageMetrics(queueControl, 0, durable); //verify memory usage is 0 after move Assert.assertEquals(0, queueMemorySize.get()); // check there is no message to consume from queue consumeMessages(0, session, queue); // consume the message from otherQueue ClientConsumer otherConsumer = session.createConsumer(otherQueue); ClientMessage m = otherConsumer.receive(500); Assert.assertEquals(value, m.getObjectProperty(key)); m.acknowledge(); session.deleteQueue(queue); otherConsumer.close(); session.deleteQueue(otherQueue); }
Example 15
Source File: BasicXaTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testSimpleJoin() throws Exception { SimpleString ADDRESS1 = new SimpleString("Address-1"); SimpleString ADDRESS2 = new SimpleString("Address-2"); clientSession.createQueue(new QueueConfiguration(ADDRESS1)); clientSession.createQueue(new QueueConfiguration(ADDRESS2)); Xid xid = newXID(); ClientSession sessionA = sessionFactory.createSession(true, false, false); sessionA.start(xid, XAResource.TMNOFLAGS); ClientSession sessionB = sessionFactory.createSession(true, false, false); sessionB.start(xid, XAResource.TMJOIN); ClientProducer prodA = sessionA.createProducer(ADDRESS1); ClientProducer prodB = sessionB.createProducer(ADDRESS2); for (int i = 0; i < 100; i++) { prodA.send(createTextMessage(sessionA, "A" + i)); prodB.send(createTextMessage(sessionB, "B" + i)); } sessionA.end(xid, XAResource.TMSUCCESS); sessionB.end(xid, XAResource.TMSUCCESS); sessionB.close(); sessionA.commit(xid, true); sessionA.close(); xid = newXID(); clientSession.start(xid, XAResource.TMNOFLAGS); ClientConsumer cons1 = clientSession.createConsumer(ADDRESS1); ClientConsumer cons2 = clientSession.createConsumer(ADDRESS2); clientSession.start(); for (int i = 0; i < 100; i++) { ClientMessage msg = cons1.receive(1000); Assert.assertNotNull(msg); Assert.assertEquals("A" + i, getTextMessage(msg)); msg.acknowledge(); msg = cons2.receive(1000); Assert.assertNotNull(msg); Assert.assertEquals("B" + i, getTextMessage(msg)); msg.acknowledge(); } Assert.assertNull(cons1.receiveImmediate()); Assert.assertNull(cons2.receiveImmediate()); clientSession.end(xid, XAResource.TMSUCCESS); clientSession.commit(xid, true); clientSession.close(); }
Example 16
Source File: BatchDelayTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testSendReceiveOne() throws Exception { ClientSessionFactory sf = createSessionFactory(); ClientSession session = sf.createSession(); final String foo = "foo"; session.createQueue(new QueueConfiguration(foo).setRoutingType(RoutingType.ANYCAST)); ClientProducer prod = session.createProducer(foo); ClientConsumer cons = session.createConsumer(foo); session.start(); ClientMessage msg = session.createMessage(false); prod.send(msg); msg = cons.receive(10000); Assert.assertNotNull(msg); msg.acknowledge(); }
Example 17
Source File: QueueControlTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
/** * Test retry - get a diverted message from DLQ and put on original queue. */ @Test public void testRetryDivertedMessage() throws Exception { final SimpleString dla = new SimpleString("DLA"); final SimpleString dlq = new SimpleString("DLQ"); final SimpleString forwardingQueue = new SimpleString("forwardingQueue"); final SimpleString forwardingAddress = new SimpleString("forwardingAddress"); final SimpleString myTopic = new SimpleString("myTopic"); final String sampleText = "Put me on DLQ"; AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla); server.getAddressSettingsRepository().addMatch(forwardingAddress.toString(), addressSettings); // create target queue, DLQ and source topic session.createQueue(new QueueConfiguration(dlq).setAddress(dla).setDurable(durable)); session.createQueue(new QueueConfiguration(forwardingQueue).setAddress(forwardingAddress).setDurable(durable)); session.createAddress(myTopic, RoutingType.MULTICAST, false); DivertConfiguration divert = new DivertConfiguration().setName("local-divert") .setRoutingName("some-name").setAddress(myTopic.toString()) .setForwardingAddress(forwardingAddress.toString()).setExclusive(false); server.deployDivert(divert); // Send message to topic. ClientProducer producer = session.createProducer(myTopic); producer.send(createTextMessage(session, sampleText)); session.start(); ClientConsumer clientConsumer = session.createConsumer(forwardingQueue); ClientMessage clientMessage = clientConsumer.receive(500); clientMessage.acknowledge(); Assert.assertNotNull(clientMessage); Assert.assertEquals(clientMessage.getBodyBuffer().readString(), sampleText); // force a rollback to DLQ session.rollback(); clientMessage = clientConsumer.receiveImmediate(); Assert.assertNull(clientMessage); QueueControl queueControl = createManagementControl(dla, dlq, RoutingType.MULTICAST); assertMessageMetrics(queueControl, 1, durable); final long messageID = getFirstMessageId(queueControl); // Retry the message - i.e. it should go from DLQ to original Queue. Assert.assertTrue(queueControl.retryMessage(messageID)); // Assert DLQ is empty... assertMessageMetrics(queueControl, 0, durable); // .. and that the message is now on the original queue once more. clientMessage = clientConsumer.receive(500); Assert.assertNotNull(clientMessage); // fails because of AMQ222196 !!! clientMessage.acknowledge(); Assert.assertEquals(sampleText, clientMessage.getBodyBuffer().readString()); clientConsumer.close(); }
Example 18
Source File: ClusterTestBase.java From activemq-artemis with Apache License 2.0 | 4 votes |
protected void verifyReceiveAllWithGroupIDRoundRobin(final boolean ack, final long firstReceiveTime, final int msgStart, final int msgEnd, final int... consumerIDs) throws Exception { HashMap<SimpleString, Integer> groupIdsReceived = new HashMap<>(); for (int i = 0; i < consumerIDs.length; i++) { ConsumerHolder holder = consumers[consumerIDs[i]]; if (holder == null) { throw new IllegalArgumentException("No consumer at " + consumerIDs[i]); } for (int j = msgStart; j < msgEnd; j++) { ClientMessage message = holder.consumer.receive(2000); if (message == null) { log.debug("*** dumping consumers:"); dumpConsumers(); Assert.assertNotNull("consumer " + consumerIDs[i] + " did not receive message " + j, message); } if (ack) { message.acknowledge(); } if (firstReceiveTime != -1) { Assert.assertTrue("Message received too soon", System.currentTimeMillis() >= firstReceiveTime); } SimpleString id = (SimpleString) message.getObjectProperty(Message.HDR_GROUP_ID); if (groupIdsReceived.get(id) == null) { groupIdsReceived.put(id, i); } else if (groupIdsReceived.get(id) != i) { Assert.fail("consumer " + groupIdsReceived.get(id) + " already bound to groupid " + id + " received on consumer " + i); } } } }
Example 19
Source File: ExpiryAddressTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testBasicSendWithRetroActiveAddressSettings() throws Exception { // apply "original" address settings SimpleString expiryAddress1 = new SimpleString("expiryAddress1"); SimpleString qName = new SimpleString("q1"); SimpleString expiryQueue1 = new SimpleString("expiryQueue1"); AddressSettings addressSettings = new AddressSettings().setExpiryAddress(expiryAddress1); server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings); clientSession.createQueue(new QueueConfiguration(expiryQueue1).setAddress(expiryAddress1).setDurable(false)); clientSession.createQueue(new QueueConfiguration(qName).setDurable(false)); // override "original" address settings SimpleString expiryAddress2 = new SimpleString("expiryAddress2"); SimpleString expiryQueue2 = new SimpleString("expiryQueue2"); addressSettings = new AddressSettings().setExpiryAddress(expiryAddress2); server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings); clientSession.createQueue(new QueueConfiguration(expiryQueue2).setAddress(expiryAddress2).setDurable(false)); // send message that will expire ASAP ClientProducer producer = clientSession.createProducer(qName); ClientMessage clientMessage = createTextMessage(clientSession, "heyho!"); clientMessage.setExpiration(System.currentTimeMillis()); producer.send(clientMessage); clientSession.start(); // make sure the message has expired from the original queue ClientConsumer clientConsumer = clientSession.createConsumer(qName); ClientMessage m = clientConsumer.receiveImmediate(); Assert.assertNull(m); m = clientConsumer.receiveImmediate(); Assert.assertNull(m); clientConsumer.close(); // make sure the message wasn't sent to the original expiry address clientConsumer = clientSession.createConsumer(expiryQueue1); m = clientConsumer.receiveImmediate(); Assert.assertNull(m); m = clientConsumer.receiveImmediate(); Assert.assertNull(m); clientConsumer.close(); // make sure the message was sent to the expected expected expiry address clientConsumer = clientSession.createConsumer(expiryQueue2); m = clientConsumer.receive(500); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!"); m.acknowledge(); }
Example 20
Source File: LargeMessageTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
public void testGlobalSizeBytesAndAddressSize(boolean isPage) throws Exception { ActiveMQServer server = createServer(true, isNetty(), storeType); server.start(); ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator)); ClientSession session = sf.createSession(false, false); LargeServerMessageImpl fileMessage = new LargeServerMessageImpl((JournalStorageManager) server.getStorageManager()); fileMessage.setMessageID(1005); for (int i = 0; i < largeMessageSize; i++) { fileMessage.addBytes(new byte[]{ActiveMQTestBase.getSamplebyte(i)}); } fileMessage.releaseResources(false); session.createQueue(new QueueConfiguration(ADDRESS)); PagingStore store = server.getPagingManager().getPageStore(ADDRESS); if (isPage) { store.startPaging(); } ClientProducer prod = session.createProducer(ADDRESS); prod.send(fileMessage); fileMessage.deleteFile(); session.commit(); if (isPage) { server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().clearCache(); } if (isPage) { Assert.assertEquals(0, server.getPagingManager().getPageStore(ADDRESS).getAddressSize()); Assert.assertEquals(0, server.getPagingManager().getGlobalSize()); } else { Assert.assertNotEquals(0, server.getPagingManager().getPageStore(ADDRESS).getAddressSize()); Assert.assertNotEquals(0, server.getPagingManager().getGlobalSize()); } session.start(); ClientConsumer cons = session.createConsumer(ADDRESS); ClientMessage msg = cons.receive(5000); Assert.assertNotNull(msg); msg.acknowledge(); session.commit(); Wait.assertEquals(0, server.getPagingManager().getPageStore(ADDRESS)::getAddressSize); Wait.assertEquals(0, server.getPagingManager()::getGlobalSize); session.close(); cons.close(); }