Java Code Examples for org.apache.activemq.artemis.api.core.client.ClientMessage#putStringProperty()
The following examples show how to use
org.apache.activemq.artemis.api.core.client.ClientMessage#putStringProperty() .
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 |
@Test public void testFirstMessageReceivedButAckedAfter() throws Exception { ClientProducer producer = clientSession.createProducer(address); ClientConsumer consumer = clientSession.createConsumer(qName1); ClientMessage m1 = createTextMessage(clientSession, "m1"); SimpleString rh = new SimpleString("SMID1"); m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); ClientMessage m2 = createTextMessage(clientSession, "m2"); m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); producer.send(m1); clientSession.start(); ClientMessage m = consumer.receive(1000); Assert.assertNotNull(m); producer.send(m2); m.acknowledge(); Assert.assertEquals(m.getBodyBuffer().readString(), "m1"); m = consumer.receive(1000); Assert.assertNotNull(m); m.acknowledge(); Assert.assertEquals(m.getBodyBuffer().readString(), "m2"); }
Example 2
Source File: LocalMessageQueue.java From elasticactors with Apache License 2.0 | 6 votes |
@Override public void run() { ClientMessage clientMessage = clientSession.createMessage(message.isDurable()); clientMessage.getBodyBuffer().writeBytes(message.toByteArray()); clientMessage.putStringProperty("routingKey", routingKey); // use the duplicate detection from ActiveMQ 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); } 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 3
Source File: LVQTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSimple() throws Exception { ClientProducer producer = clientSession.createProducer(address); ClientConsumer consumer = clientSession.createConsumer(qName1); ClientMessage m1 = createTextMessage(clientSession, "m1"); SimpleString rh = new SimpleString("SMID1"); m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); ClientMessage m2 = createTextMessage(clientSession, "m2"); m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); producer.send(m1); producer.send(m2); clientSession.start(); ClientMessage m = consumer.receive(1000); Assert.assertNotNull(m); m.acknowledge(); Assert.assertEquals(m.getBodyBuffer().readString(), "m2"); }
Example 4
Source File: LVQTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@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: RemoteMessageQueue.java From elasticactors with Apache License 2.0 | 5 votes |
@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 6
Source File: MultipleConsumersPageStressTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void run() { try { if (shareConnectionFactory) { session = sharedSf.createSession(false, false); } else { locator = createInVMNonHALocator(); sf = createSessionFactory(locator); session = sf.createSession(false, false); } ClientProducer prod = session.createProducer(MultipleConsumersPageStressTest.ADDRESS); int count = 0; while (enabled()) { int numberOfMessages = getNumberOfMessages(); for (int i = 0; i < numberOfMessages; i++) { ClientMessage msg = session.createMessage(true); msg.putStringProperty("Test", "This is a simple test"); msg.putIntProperty("count", count++); prod.send(msg); } messagesAvailable.addAndGet(numberOfMessages); session.commit(); } } catch (Throwable e) { exceptionHappened(e); } }
Example 7
Source File: ConsumerFilterTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * @param session * @param producer * @throws Exception */ private void sendMessage(ClientSession session, ClientProducer producer, String color, String msg) throws Exception { ClientMessage anyMessage = session.createMessage(true); anyMessage.putStringProperty("color", color); anyMessage.putStringProperty("value", msg); producer.send(anyMessage); session.commit(); }
Example 8
Source File: InterceptorTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException { if (packet.getType() == PacketImpl.SESS_RECEIVE_MSG) { SessionReceiveMessage p = (SessionReceiveMessage) packet; ClientMessage cm = (ClientMessage) p.getMessage(); cm.putStringProperty(InterceptorTest.key, "orange"); } return true; }
Example 9
Source File: DuplicateDetectionTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@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 10
Source File: MessageGroupingTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testMultipleGroupingConsumeHalf() throws Exception { ClientProducer clientProducer = clientSession.createProducer(qName); ClientConsumer consumer = clientSession.createConsumer(qName); ClientConsumer consumer2 = clientSession.createConsumer(qName); clientSession.start(); //need to wait a bit or consumers might be busy Thread.sleep(200); SimpleString groupId = new SimpleString("grp1"); SimpleString groupId2 = new SimpleString("grp2"); int numMessages = 100; for (int i = 0; i < numMessages; i++) { ClientMessage message = createTextMessage(clientSession, "m" + i); if (i % 2 == 0 || i == 0) { message.putStringProperty(Message.HDR_GROUP_ID, groupId); } else { message.putStringProperty(Message.HDR_GROUP_ID, groupId2); } clientProducer.send(message); } for (int i = 0; i < numMessages / 2; i++) { ClientMessage cm = consumer.receive(500); Assert.assertNotNull(cm); Assert.assertEquals(cm.getBodyBuffer().readString(), "m" + i); i++; cm = consumer2.receive(500); Assert.assertNotNull(cm); Assert.assertEquals(cm.getBodyBuffer().readString(), "m" + i); } log.debug("closing consumer2"); consumer2.close(); consumer.close(); }
Example 11
Source File: ActiveMQMessageHandlerTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testSelectorNotChangedWithTopic() throws Exception { ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Topic"); spec.setDestination("mdbTopic"); spec.setSubscriptionDurability("Durable"); spec.setSubscriptionName("durable-mdb"); spec.setClientID("id-1"); spec.setMessageSelector("foo='bar'"); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); CountDownLatch latch = new CountDownLatch(1); DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch); DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false); qResourceAdapter.endpointActivation(endpointFactory, spec); ClientSession session = locator.createSessionFactory().createSession(); ClientProducer clientProducer = session.createProducer("mdbTopic"); ClientMessage message = session.createMessage(true); message.getBodyBuffer().writeString("1"); message.putStringProperty("foo", "bar"); clientProducer.send(message); latch.await(5, TimeUnit.SECONDS); assertNotNull(endpoint.lastMessage); assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1"); qResourceAdapter.endpointDeactivation(endpointFactory, spec); message = session.createMessage(true); message.getBodyBuffer().writeString("2"); message.putStringProperty("foo", "bar"); clientProducer.send(message); latch = new CountDownLatch(1); endpoint = new DummyMessageEndpoint(latch); endpointFactory = new DummyMessageEndpointFactory(endpoint, false); qResourceAdapter.endpointActivation(endpointFactory, spec); latch.await(5, TimeUnit.SECONDS); assertNotNull(endpoint.lastMessage); assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "2"); qResourceAdapter.endpointDeactivation(endpointFactory, spec); qResourceAdapter.stop(); }
Example 12
Source File: ActiveMQMessageHandlerTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testSelectorChangedWithTopic() throws Exception { ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Topic"); spec.setDestination("mdbTopic"); spec.setSubscriptionDurability("Durable"); spec.setSubscriptionName("durable-mdb"); spec.setClientID("id-1"); spec.setMessageSelector("foo='bar'"); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); CountDownLatch latch = new CountDownLatch(1); DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch); DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false); qResourceAdapter.endpointActivation(endpointFactory, spec); ClientSession session = locator.createSessionFactory().createSession(); ClientProducer clientProducer = session.createProducer("mdbTopic"); ClientMessage message = session.createMessage(true); message.getBodyBuffer().writeString("1"); message.putStringProperty("foo", "bar"); clientProducer.send(message); latch.await(5, TimeUnit.SECONDS); assertNotNull(endpoint.lastMessage); assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1"); qResourceAdapter.endpointDeactivation(endpointFactory, spec); message = session.createMessage(true); message.getBodyBuffer().writeString("2"); message.putStringProperty("foo", "bar"); clientProducer.send(message); latch = new CountDownLatch(1); endpoint = new DummyMessageEndpoint(latch); //change the selector forcing the queue to be recreated spec.setMessageSelector("foo='abar'"); endpointFactory = new DummyMessageEndpointFactory(endpoint, false); qResourceAdapter.endpointActivation(endpointFactory, spec); message = session.createMessage(true); message.getBodyBuffer().writeString("3"); message.putStringProperty("foo", "abar"); clientProducer.send(message); latch.await(5, TimeUnit.SECONDS); assertNotNull(endpoint.lastMessage); assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "3"); qResourceAdapter.endpointDeactivation(endpointFactory, spec); qResourceAdapter.stop(); }
Example 13
Source File: GlobalPagingTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testManagementMessageRequestCannotFailAfterFailedDirectDeliver() throws Exception { clearDataRecreateServerDirs(); Configuration config = createDefaultNettyConfig().setJournalSyncNonTransactional(false); final ActiveMQServer server = createServer(true, config, PagingTest.PAGE_SIZE, -1); try { final SimpleString managementAddress = server.getConfiguration().getManagementAddress(); server.start(); //need to use Netty in order to have direct delivery available final ServerLocator locator = createNettyNonHALocator() .setBlockOnNonDurableSend(true) .setBlockOnDurableSend(true) .setBlockOnAcknowledge(true); try (ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, true, true)) { session.start(); if (server.locateQueue(managementAddress) == null) { session.createQueue(new QueueConfiguration(managementAddress)); } final SimpleString address = SimpleString.toSimpleString("queue"); if (server.locateQueue(address) == null) { session.createQueue(new QueueConfiguration(address)); } try (ClientProducer requestProducer = session.createProducer(managementAddress)) { final SimpleString replyQueue = new SimpleString(managementAddress + "." + UUID.randomUUID().toString()); session.createQueue(new QueueConfiguration(replyQueue).setRoutingType(ActiveMQDefaultConfiguration.getDefaultRoutingType()).setDurable(false).setTemporary(true)); int id = 1000; try (ClientConsumer consumer = session.createConsumer(replyQueue)) { final Queue queue = server.locateQueue(replyQueue); final MessageReference reference = MessageReference.Factory.createReference(session.createMessage(false), queue); reference.getMessage().setMessageID(id++); //it will cause QueueImpl::directDeliver -> false queue.addHead(reference, false); Wait.assertFalse(queue::isDirectDeliver); queue.removeReferenceWithID(reference.getMessageID()); ClientMessage message = session.createMessage(false); message.putStringProperty(ClientMessageImpl.REPLYTO_HEADER_NAME, replyQueue); ManagementHelper.putAttribute(message, "queue." + address.toString(), "messageCount"); requestProducer.send(message); Assert.assertNotNull(consumer.receive()); } } } } finally { server.stop(true); } }
Example 14
Source File: RoutingTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testRouteToMultipleQueueWithFilters() throws Exception { ClientSession sendSession = cf.createSession(false, true, true); sendSession.createQueue(new QueueConfiguration(queueA).setAddress(addressA).setFilterString(new SimpleString("foo = 'bar'")).setDurable(false)); sendSession.createQueue(new QueueConfiguration(queueB).setAddress(addressA).setFilterString(new SimpleString("x = 1")).setDurable(false)); sendSession.createQueue(new QueueConfiguration(queueC).setAddress(addressA).setFilterString(new SimpleString("b = false")).setDurable(false)); int numMessages = 300; ClientProducer p = sendSession.createProducer(addressA); for (int i = 0; i < numMessages; i++) { ClientMessage clientMessage = sendSession.createMessage(false); if (i % 3 == 0) { clientMessage.putStringProperty(new SimpleString("foo"), new SimpleString("bar")); } else if (i % 3 == 1) { clientMessage.putIntProperty(new SimpleString("x"), 1); } else { clientMessage.putBooleanProperty(new SimpleString("b"), false); } p.send(clientMessage); } ClientSession session = cf.createSession(false, true, true); ClientConsumer c1 = session.createConsumer(queueA); ClientConsumer c2 = session.createConsumer(queueB); ClientConsumer c3 = session.createConsumer(queueC); session.start(); for (int i = 0; i < numMessages / 3; i++) { ClientMessage m = c1.receive(5000); Assert.assertNotNull(m); m.acknowledge(); m = c2.receive(5000); Assert.assertNotNull(m); m.acknowledge(); m = c3.receive(5000); Assert.assertNotNull(m); m.acknowledge(); } Assert.assertNull(c1.receiveImmediate()); Assert.assertNull(c2.receiveImmediate()); Assert.assertNull(c3.receiveImmediate()); sendSession.close(); session.close(); }
Example 15
Source File: ClusterTestBase.java From activemq-artemis with Apache License 2.0 | 4 votes |
protected void sendInRange(final int node, final String address, final int msgStart, final int msgEnd, final boolean durable, final String filterVal, final AtomicInteger duplicateDetectionSeq) throws Exception { ClientSessionFactory sf = sfs[node]; if (sf == null) { throw new IllegalArgumentException("No sf at " + node); } ClientSession session = sf.createSession(false, false, false); try { ClientProducer producer = session.createProducer(address); for (int i = msgStart; i < msgEnd; i++) { ClientMessage message = session.createMessage(durable); if (filterVal != null) { message.putStringProperty(ClusterTestBase.FILTER_PROP, new SimpleString(filterVal)); } if (duplicateDetectionSeq != null) { String str = Integer.toString(duplicateDetectionSeq.incrementAndGet()); message.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID, new SimpleString(str)); } message.putIntProperty(ClusterTestBase.COUNT_PROP, i); if (isLargeMessage()) { message.setBodyInputStream(createFakeLargeStream(getLargeMessageSize())); } producer.send(message); if (i % 100 == 0) { session.commit(); } } session.commit(); } finally { session.close(); } }
Example 16
Source File: ActiveMQ.java From activemq-artemis with Apache License 2.0 | 4 votes |
public static void setHttpHeader(ClientMessage message, String name, String value) { message.putStringProperty(HttpHeaderProperty.toPropertyName(name), value); }
Example 17
Source File: ConsumerWindowSizeTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testMultipleImmediate() throws Exception { final int NUMBER_OF_MESSAGES = 200; ActiveMQServer server = createServer(false, isNetty()); server.start(); locator.setConsumerWindowSize(0); final ClientSessionFactory sf = createSessionFactory(locator); { ClientSession session = sf.createSession(false, false, false); session.createQueue(new QueueConfiguration("testWindow")); session.close(); } Thread[] threads = new Thread[10]; final AtomicInteger errors = new AtomicInteger(0); final CountDownLatch latchStart = new CountDownLatch(1); final AtomicInteger received = new AtomicInteger(0); for (int i = 0; i < threads.length; i++) { threads[i] = new Thread() { @Override public void run() { try { ClientSession session = sf.createSession(false, false); ClientConsumer consumer = session.createConsumer("testWindow"); session.start(); latchStart.await(10, TimeUnit.SECONDS); while (true) { if (received.incrementAndGet() > NUMBER_OF_MESSAGES) { received.decrementAndGet(); break; } ClientMessage msg = consumer.receive(1000); msg.acknowledge(); session.commit(); } } catch (Throwable e) { e.printStackTrace(); errors.incrementAndGet(); } } }; threads[i].start(); } ClientSession senderSession = sf.createSession(false, false); ClientProducer producer = senderSession.createProducer("testWindow"); ClientMessage sent = senderSession.createMessage(true); sent.putStringProperty("hello", "world"); for (int i = 0; i < NUMBER_OF_MESSAGES; i++) { producer.send(sent); senderSession.commit(); } latchStart.countDown(); for (Thread t : threads) { t.join(); } Assert.assertEquals(0, errors.get()); Assert.assertEquals(NUMBER_OF_MESSAGES, received.get()); }
Example 18
Source File: LVQRecoveryTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@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 19
Source File: QueueBrowserTest.java From activemq-artemis with Apache License 2.0 | 3 votes |
@Test public void testConsumerBrowserWithStringSelector() throws Exception { ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, true, true); session.createQueue(new QueueConfiguration(QUEUE).setDurable(false)); ClientProducer producer = session.createProducer(QUEUE); final int numMessages = 100; for (int i = 0; i < numMessages; i++) { ClientMessage message = createTextMessage(session, "m" + i); if (i % 2 == 0) { message.putStringProperty(new SimpleString("color"), new SimpleString("RED")); } producer.send(message); } ClientConsumer consumer = session.createConsumer(QUEUE, new SimpleString("color = 'RED'"), true); for (int i = 0; i < numMessages; i += 2) { ClientMessage message2 = consumer.receive(1000); Assert.assertEquals("m" + i, message2.getBodyBuffer().readString()); } session.close(); }
Example 20
Source File: ConsumerFilterTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
@Test public void testTwoConsumers() throws Exception { ClientConsumer consumer2 = session.createConsumer("foo", "animal='elephant'"); //Create and consume message that matches the first consumer's filter ClientMessage message = session.createMessage(false); message.putStringProperty("animal", "giraffe"); producer.send(message); ClientMessage received = consumer.receive(10000); assertNotNull(received); assertEquals("giraffe", received.getStringProperty("animal")); assertNull(consumer.receiveImmediate()); assertNull(consumer2.receiveImmediate()); //Create and consume another message that matches the first consumer's filter message = session.createMessage(false); message.putStringProperty("animal", "giraffe"); producer.send(message); received = consumer.receive(10000); assertNotNull(received); assertEquals("giraffe", received.getStringProperty("animal")); assertNull(consumer.receiveImmediate()); assertNull(consumer2.receiveImmediate()); //Create and consume a message that matches the second consumer's filter message = session.createMessage(false); message.putStringProperty("animal", "elephant"); producer.send(message); received = consumer2.receive(10000); assertNotNull(received); assertEquals("elephant", received.getStringProperty("animal")); assertNull(consumer.receiveImmediate()); assertNull(consumer2.receiveImmediate()); //Create and consume another message that matches the second consumer's filter message = session.createMessage(false); message.putStringProperty("animal", "elephant"); producer.send(message); received = consumer2.receive(1000); assertNotNull(received); assertEquals("elephant", received.getStringProperty("animal")); assertNull(consumer.receiveImmediate()); assertNull(consumer2.receiveImmediate()); session.close(); }