org.apache.activemq.artemis.api.core.client.ClientMessage Java Examples
The following examples show how to use
org.apache.activemq.artemis.api.core.client.ClientMessage.
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: MultipleThreadFilterOneTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * @throws ActiveMQException */ private void sendMessages(int msgs) throws ActiveMQException { ClientProducer producer = prodSession.createProducer(ADDRESS); for (int i = 0; i < msgs; i++) { ClientMessage message = prodSession.createMessage(true); message.putIntProperty("prodNR", i % nThreads); producer.send(message); if (i % 100 == 0) { prodSession.commit(); } } prodSession.commit(); producer.close(); }
Example #2
Source File: SSLSecurityNotificationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
protected static ClientMessage[] consumeMessages(final int expected, final ClientConsumer consumer) throws Exception { ClientMessage[] messages = new ClientMessage[expected]; ClientMessage m = null; for (int i = 0; i < expected; i++) { m = consumer.receive(500); Assert.assertNotNull("expected to received " + expected + " messages, got only " + i, m); messages[i] = m; m.acknowledge(); } m = consumer.receiveImmediate(); Assert.assertNull("received one more message than expected (" + expected + ")", m); return messages; }
Example #3
Source File: NIOMultiThreadCompactorStressTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * @param numberOfMessagesExpected * @param queue * @throws ActiveMQException */ private void drainQueue(final int numberOfMessagesExpected, final SimpleString queue) throws ActiveMQException { ClientSession sess = sf.createSession(true, true); ClientConsumer consumer = sess.createConsumer(queue); sess.start(); for (int i = 0; i < numberOfMessagesExpected; i++) { ClientMessage msg = consumer.receive(5000); Assert.assertNotNull(msg); if (i % 100 == 0) { // System.out.println("Received #" + i + " on thread after start"); } msg.acknowledge(); } Assert.assertNull(consumer.receiveImmediate()); sess.close(); }
Example #4
Source File: ReceiveTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testReceiveThrowsExceptionWhenHandlerSet() throws Exception { ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession(false, true, true); session.createQueue(new QueueConfiguration(queueA).setAddress(addressA).setDurable(false)); ClientConsumer cc = session.createConsumer(queueA); session.start(); cc.setMessageHandler(new MessageHandler() { @Override public void onMessage(final ClientMessage message) { } }); try { cc.receive(); Assert.fail("should throw exception"); } catch (ActiveMQIllegalStateException ise) { //ok } catch (ActiveMQException e) { Assert.fail("Invalid Exception type:" + e.getType()); } session.close(); }
Example #5
Source File: RingQueueTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testNonDestructiveWithConsumerClose() throws Exception { ServerLocator locator = createNettyNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0); ClientSessionFactory sf = createSessionFactory(locator); ClientSession clientSession = addClientSession(sf.createSession(false, true, true)); clientSession.createQueue(new QueueConfiguration(qName).setAddress(address).setRingSize(1L).setNonDestructive(true)); clientSession.start(); final Queue queue = server.locateQueue(qName); assertEquals(1, queue.getRingSize()); ClientProducer producer = clientSession.createProducer(address); ClientMessage m0 = createTextMessage(clientSession, "hello" + 0); producer.send(m0); Wait.assertTrue(() -> queue.getMessageCount() == 1); ClientConsumer consumer = clientSession.createConsumer(qName); Wait.assertTrue(() -> queue.getDeliveringCount() == 1); consumer.close(); Wait.assertTrue(() -> queue.getDeliveringCount() == 0); Wait.assertTrue(() -> queue.getMessageCount() == 1); }
Example #6
Source File: RoutingTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testRouteToSingleTemporaryQueue() throws Exception { ClientSession sendSession = cf.createSession(false, true, true); sendSession.createQueue(new QueueConfiguration(queueA).setAddress(addressA).setDurable(false).setTemporary(true)); 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 #7
Source File: SecurityNotificationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
protected static ClientMessage[] consumeMessages(final int expected, final ClientConsumer consumer) throws Exception { ClientMessage[] messages = new ClientMessage[expected]; ClientMessage m = null; for (int i = 0; i < expected; i++) { m = consumer.receive(500); Assert.assertNotNull("expected to received " + expected + " messages, got only " + i, m); messages[i] = m; m.acknowledge(); } m = consumer.receiveImmediate(); Assert.assertNull("received one more message than expected (" + expected + ")", m); return messages; }
Example #8
Source File: NotificationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testBINDING_ADDEDWithMatchingFilter() throws Exception { SimpleString queue = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString(); boolean durable = RandomUtil.randomBoolean(); notifConsumer.close(); notifConsumer = session.createConsumer(notifQueue.toString(), ManagementHelper.HDR_ROUTING_NAME + "= '" + queue + "'"); NotificationTest.flush(notifConsumer); long start = System.currentTimeMillis(); session.createQueue(new QueueConfiguration(queue).setAddress(address).setDurable(durable)); ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer); Assert.assertEquals(BINDING_ADDED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertEquals(queue.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME).toString()); Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString()); Assert.assertTrue(notifications[0].getTimestamp() >= start); Assert.assertTrue((long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP) >= start); Assert.assertEquals(notifications[0].getTimestamp(), (long) notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP)); session.deleteQueue(queue); }
Example #9
Source File: ArtemisBenchmarkProducer.java From openmessaging-benchmark with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<Void> sendAsync(Optional<String> key, byte[] payload) { ClientMessage msg = session.createMessage(true /* durable */ ); msg.setTimestamp(System.currentTimeMillis()); msg.getBodyBuffer().writeBytes(payload); CompletableFuture<Void> future = new CompletableFuture<>(); try { producer.send(msg, message -> { future.complete(null); }); } catch (ActiveMQException e) { future.completeExceptionally(e); } return future; }
Example #10
Source File: ScaleDownHandler.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void scaleDownDuplicateIDs(Map<SimpleString, List<Pair<byte[], Long>>> duplicateIDMap, ClientSessionFactory sessionFactory, SimpleString managementAddress, String user, String password) throws Exception { try (ClientSession session = sessionFactory.createSession(user, password, true, false, false, false, 0); ClientProducer producer = session.createProducer(managementAddress)) { //todo - https://issues.jboss.org/browse/HORNETQ-1336 for (Map.Entry<SimpleString, List<Pair<byte[], Long>>> entry : duplicateIDMap.entrySet()) { ClientMessage message = session.createMessage(false); List<Pair<byte[], Long>> list = entry.getValue(); String[] array = new String[list.size()]; for (int i = 0; i < list.size(); i++) { Pair<byte[], Long> pair = list.get(i); array[i] = new String(pair.getA()); } ManagementHelper.putOperationInvocation(message, ResourceNames.BROKER, "updateDuplicateIdCache", entry.getKey().toString(), array); producer.send(message); } } }
Example #11
Source File: TopicClusterTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void checkInternalProperty(Message... msgs) throws Exception { boolean checked = false; for (Message m : msgs) { ActiveMQMessage hqMessage = (ActiveMQMessage) m; ClientMessage coreMessage = hqMessage.getCoreMessage(); Set<SimpleString> coreProps = coreMessage.getPropertyNames(); boolean exist = false; for (SimpleString prop : coreProps) { if (prop.startsWith(org.apache.activemq.artemis.api.core.Message.HDR_ROUTE_TO_IDS)) { exist = true; break; } } if (exist) { Enumeration enumProps = m.getPropertyNames(); while (enumProps.hasMoreElements()) { String propName = (String) enumProps.nextElement(); assertFalse("Shouldn't be in jms property: " + propName, propName.startsWith(org.apache.activemq.artemis.api.core.Message.HDR_ROUTE_TO_IDS.toString())); } checked = true; } } assertTrue(checked); }
Example #12
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 #13
Source File: QueueControlTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testMoveMessagesToUnknownQueue() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); SimpleString queue = RandomUtil.randomSimpleString(); SimpleString unknownQueue = RandomUtil.randomSimpleString(); session.createQueue(new QueueConfiguration(queue).setAddress(address).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); QueueControl queueControl = createManagementControl(address, queue); assertMessageMetrics(queueControl, 1, durable); // moved all messages to unknown queue try { queueControl.moveMessages(null, unknownQueue.toString()); Assert.fail("operation must fail if the other queue does not exist"); } catch (Exception e) { } Assert.assertEquals(1, getMessageCount(queueControl)); assertMessageMetrics(queueControl, 1, durable); consumeMessages(1, session, queue); session.deleteQueue(queue); }
Example #14
Source File: ArtemisProducerManager.java From quarkus with Apache License 2.0 | 5 votes |
public void send(String body) { try (ClientSession session = connection.createSession()) { ClientMessage message = session.createMessage(true); message.getBodyBuffer().writeString(body); try (ClientProducer producer = session.createProducer("test-core")) { producer.send(message); } } catch (ActiveMQException e) { throw new RuntimeException("Could not send message", e); } }
Example #15
Source File: ExpiryAddressTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testExpireWithWildcardAddressSettings() throws Exception { SimpleString ea = new SimpleString("EA"); SimpleString qName = new SimpleString("q1"); SimpleString eq = new SimpleString("EA1"); AddressSettings addressSettings = new AddressSettings().setExpiryAddress(ea); server.getAddressSettingsRepository().addMatch("*", addressSettings); clientSession.createQueue(new QueueConfiguration(eq).setAddress(ea).setDurable(false)); clientSession.createQueue(new QueueConfiguration(qName).setDurable(false)); ClientProducer producer = clientSession.createProducer(qName); ClientMessage clientMessage = createTextMessage(clientSession, "heyho!"); clientMessage.setExpiration(System.currentTimeMillis()); producer.send(clientMessage); clientSession.start(); ClientConsumer clientConsumer = clientSession.createConsumer(qName); ClientMessage m = clientConsumer.receiveImmediate(); Assert.assertNull(m); clientConsumer.close(); clientConsumer = clientSession.createConsumer(eq); m = clientConsumer.receive(500); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!"); m.acknowledge(); }
Example #16
Source File: ClusteredBridgeTestBase.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void sendMessages(String queueName, int num) throws ActiveMQException { ClientSession session = sessionFactory.createSession(); ClientProducer producer = session.createProducer(queueName); for (int i = 0; i < num; i++) { ClientMessage m = session.createMessage(true); m.putStringProperty("bridge-message", "hello " + index); index++; producer.send(m); } session.close(); }
Example #17
Source File: DivertTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testProperties() throws Exception { final String testAddress = "testAddress"; final SimpleString queue = SimpleString.toSimpleString("queue"); final int COUNT = 25; ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig(), false)); server.start(); server.createQueue(new QueueConfiguration(queue).setAddress(testAddress + (COUNT)).setRoutingType(RoutingType.ANYCAST)); for (int i = 0; i < COUNT; i++) { server.deployDivert(new DivertConfiguration() .setName("divert" + i) .setAddress(testAddress + i) .setForwardingAddress(testAddress + (i + 1))); } ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, true, true); session.start(); ClientProducer producer = session.createProducer(new SimpleString(testAddress + "0")); ClientConsumer consumer1 = session.createConsumer(queue); ClientMessage message = session.createMessage(false); producer.send(message); message = consumer1.receive(DivertTest.TIMEOUT); Assert.assertNotNull(message); message.acknowledge(); Assert.assertEquals("testAddress" + COUNT, message.getAddress()); Assert.assertEquals("testAddress" + (COUNT - 1), message.getStringProperty(Message.HDR_ORIGINAL_ADDRESS)); }
Example #18
Source File: TemporaryQueueTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testPaginStoreIsRemovedWhenQueueIsDeleted() throws Exception { SimpleString queue = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString(); session.createQueue(new QueueConfiguration(queue).setAddress(address).setDurable(false).setTemporary(true)); ClientProducer producer = session.createProducer(address); ClientMessage msg = session.createMessage(false); producer.send(msg); session.start(); ClientConsumer consumer = session.createConsumer(queue); ClientMessage message = consumer.receive(500); assertNotNull(message); message.acknowledge(); SimpleString[] storeNames = server.getPagingManager().getStoreNames(); assertTrue(Arrays.asList(storeNames).contains(address)); consumer.close(); session.deleteQueue(queue); session.close(); storeNames = server.getPagingManager().getStoreNames(); assertFalse(Arrays.asList(storeNames).contains(address)); }
Example #19
Source File: DeadLetterAddressTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testBasicSend2times() throws Exception { SimpleString dla = new SimpleString("DLA"); SimpleString qName = new SimpleString("q1"); AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(2).setDeadLetterAddress(dla); server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings); SimpleString dlq = new SimpleString("DLQ1"); clientSession.createQueue(new QueueConfiguration(dlq).setAddress(dla).setDurable(false)); clientSession.createQueue(new QueueConfiguration(qName).setDurable(false)); ClientProducer producer = clientSession.createProducer(qName); producer.send(createTextMessage(clientSession, "heyho!")); clientSession.start(); ClientConsumer clientConsumer = clientSession.createConsumer(qName); ClientMessage m = clientConsumer.receive(5000); m.acknowledge(); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!"); // force a cancel clientSession.rollback(); clientSession.start(); m = clientConsumer.receive(5000); m.acknowledge(); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!"); // force a cancel clientSession.rollback(); m = clientConsumer.receiveImmediate(); Assert.assertNull(m); clientConsumer.close(); clientConsumer = clientSession.createConsumer(dlq); m = clientConsumer.receive(5000); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!"); }
Example #20
Source File: QueueControlTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testCountDeliveringMessageCountNoGroupNoFilter() throws Exception { SimpleString key = new SimpleString("key"); long matchingValue = RandomUtil.randomLong(); long unmatchingValue = matchingValue + 1; SimpleString address = RandomUtil.randomSimpleString(); SimpleString queue = RandomUtil.randomSimpleString(); session.createQueue(new QueueConfiguration(queue).setAddress(address).setDurable(false)); ClientProducer producer = session.createProducer(address); ClientMessage matchingMessage = session.createMessage(false); matchingMessage.putLongProperty(key, matchingValue); ClientMessage unmatchingMessage = session.createMessage(false); unmatchingMessage.putLongProperty(key, unmatchingValue); producer.send(matchingMessage); producer.send(unmatchingMessage); producer.send(matchingMessage); session.commit(); QueueControl queueControl = createManagementControl(address, queue); String result = queueControl.countDeliveringMessages(null, null); JsonObject jsonObject = JsonUtil.readJsonObject(result); Assert.assertEquals(0, jsonObject.getInt("null")); ClientConsumer consumer = session.createConsumer(queue, null, 1024 * 1024, 1, false); ClientMessage message = consumer.receive(500); Assert.assertNotNull(message); result = queueControl.countDeliveringMessages(null, null); jsonObject = JsonUtil.readJsonObject(result); Assert.assertEquals(3, jsonObject.getInt("null")); consumer.close(); session.deleteQueue(queue); }
Example #21
Source File: ActiveMQMessageHandlerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testSimpleMessageReceivedOnQueueManyMessagesAndInterruptTimeout() throws Exception { final int SIZE = 14; ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setCallTimeout(500L); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); CountDownLatch latch = new CountDownLatch(SIZE); CountDownLatch latchDone = new CountDownLatch(SIZE); MultipleEndpoints endpoint = new MultipleEndpoints(latch, latchDone, true); DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false); qResourceAdapter.endpointActivation(endpointFactory, spec); ClientSession session = locator.createSessionFactory().createSession(); ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED); for (int i = 0; i < SIZE; i++) { ClientMessage message = session.createMessage(true); message.getBodyBuffer().writeString("teststring" + i); clientProducer.send(message); } session.close(); assertTrue(latch.await(5, TimeUnit.SECONDS)); qResourceAdapter.endpointDeactivation(endpointFactory, spec); latchDone.await(5, TimeUnit.SECONDS); assertEquals(SIZE, endpoint.messages.intValue()); //half onmessage interrupted assertEquals(SIZE / 2, endpoint.interrupted.intValue()); qResourceAdapter.stop(); }
Example #22
Source File: WildcardConfigurationTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testBasicWildcardRouting() throws Exception { SimpleString addressAB = new SimpleString("a/b"); 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)); 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); }
Example #23
Source File: WildCardRoutingTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testWildcardRoutingQueuesAddedAfter() throws Exception { SimpleString addressAB = new SimpleString("a.b"); 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(queueName).setAddress(address).setDurable(false)); ClientProducer producer = clientSession.createProducer(addressAB); ClientProducer producer2 = clientSession.createProducer(addressAC); ClientConsumer clientConsumer = clientSession.createConsumer(queueName); clientSession.createQueue(new QueueConfiguration(queueName1).setAddress(addressAB).setDurable(false)); clientSession.createQueue(new QueueConfiguration(queueName2).setAddress(addressAC).setDurable(false)); 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); }
Example #24
Source File: AutoCreateExpiryResourcesTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testAutoDeletionAndRecreationOfExpiryResources() throws Exception { SimpleString expiryQueueName = getDefaultExpiryQueueName(addressA); triggerExpiration(); // consume the message from the DLQ so it will be auto-deleted ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory sessionFactory = createSessionFactory(locator); ClientSession session = addClientSession(sessionFactory.createSession(true, true)); Wait.assertTrue(() -> server.locateQueue(expiryQueueName) != null, 2000, 100); ClientConsumer consumer = session.createConsumer(expiryQueueName); session.start(); ClientMessage message = consumer.receive(); assertNotNull(message); message.acknowledge(); consumer.close(); session.close(); sessionFactory.close(); locator.close(); Wait.assertTrue(() -> server.locateQueue(expiryQueueName) == null, 2000, 100); server.destroyQueue(queueA); triggerExpiration(); Wait.assertTrue(() -> server.getAddressInfo(expiryAddress) != null, 2000, 100); Wait.assertTrue(() -> server.locateQueue(expiryQueueName) != null, 2000, 100); }
Example #25
Source File: WildCardRoutingTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testWildcardRoutingWithHashMultiLengthAddresses() throws Exception { SimpleString addressAB = new SimpleString("a.b.c.f"); SimpleString addressAC = new SimpleString("a.c.f"); SimpleString address = new SimpleString("a.#.f"); 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.receive(500); Assert.assertNotNull(m); Assert.assertEquals("m2", m.getBodyBuffer().readString()); m.acknowledge(); m = clientConsumer.receiveImmediate(); Assert.assertNull(m); }
Example #26
Source File: EmbeddedActiveMQResource.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Adds properties to a ClientMessage * * @param message * @param properties */ public static void addMessageProperties(ClientMessage message, Map<String, Object> properties) { if (properties != null && properties.size() > 0) { for (Map.Entry<String, Object> property : properties.entrySet()) { message.putObjectProperty(property.getKey(), property.getValue()); } } }
Example #27
Source File: RandomReattachTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void onMessage(ClientMessage message) { try { onMessageAssert(message); } catch (AssertionError e) { e.printStackTrace(); // System.out -> junit reports errors.add(e); } }
Example #28
Source File: SessionStopStartTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private int getMessageEncodeSize(final SimpleString address) throws Exception { ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession(false, true, true); ClientMessage message = session.createMessage(false); // we need to set the destination so we can calculate the encodesize correctly message.setAddress(address); int encodeSize = message.getEncodeSize(); session.close(); cf.close(); return encodeSize; }
Example #29
Source File: RingQueueTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testNonDestructive() throws Exception { ServerLocator locator = createNettyNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0); ClientSessionFactory sf = createSessionFactory(locator); ClientSession clientSession = addClientSession(sf.createSession(false, true, true)); clientSession.createQueue(new QueueConfiguration(qName).setAddress(address).setRingSize(1L).setNonDestructive(true)); clientSession.start(); final Queue queue = server.locateQueue(qName); assertEquals(1, queue.getRingSize()); ClientProducer producer = clientSession.createProducer(address); ClientMessage message = createTextMessage(clientSession, "hello" + 0); producer.send(message); for (int i = 0; i < 5; i++) { Wait.assertTrue(() -> queue.getMessageCount() == 1); message = createTextMessage(clientSession, "hello" + (i + 1)); producer.send(message); final int finalI = i + 1; Wait.assertTrue(() -> queue.getMessagesReplaced() == finalI); Wait.assertTrue(() -> queue.getMessageCount() == 1); ClientConsumer consumer = clientSession.createConsumer(qName); message = consumer.receiveImmediate(); assertNotNull(message); message.acknowledge(); // non-destructive! consumer.close(); assertEquals("hello" + (i + 1), message.getBodyBuffer().readString()); } }
Example #30
Source File: CoreClientOverOneWaySSLTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testOneWaySSLWithGoodClientCipherSuite() throws Exception { createCustomSslServer(); String text = RandomUtil.randomString(); tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true); tc.getParams().put(TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME, storeType); tc.getParams().put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, CLIENT_SIDE_TRUSTSTORE); tc.getParams().put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, PASSWORD); tc.getParams().put(TransportConstants.ENABLED_CIPHER_SUITES_PROP_NAME, getSuitableCipherSuite()); tc.getParams().put(TransportConstants.ENABLED_PROTOCOLS_PROP_NAME, "TLSv1.2"); ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc)); ClientSessionFactory sf = null; try { sf = createSessionFactory(locator); } catch (ActiveMQNotConnectedException e) { Assert.fail(); } ClientSession session = sf.createSession(false, true, true); session.createQueue(new QueueConfiguration(CoreClientOverOneWaySSLTest.QUEUE).setDurable(false)); ClientProducer producer = session.createProducer(CoreClientOverOneWaySSLTest.QUEUE); ClientMessage message = createTextMessage(session, text); producer.send(message); ClientConsumer consumer = session.createConsumer(CoreClientOverOneWaySSLTest.QUEUE); session.start(); Message m = consumer.receive(1000); Assert.assertNotNull(m); Assert.assertEquals(text, m.getBodyBuffer().readString()); }