Java Code Examples for org.apache.activemq.artemis.api.core.client.ClientMessage#getObjectProperty()
The following examples show how to use
org.apache.activemq.artemis.api.core.client.ClientMessage#getObjectProperty() .
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: ActiveMQTestBase.java From activemq-artemis with Apache License 2.0 | 6 votes |
protected final void receiveMessages(ClientConsumer consumer, final int start, final int msgCount, final boolean ack) throws ActiveMQException { for (int i = start; i < msgCount; i++) { ClientMessage message = consumer.receive(1000); Assert.assertNotNull("Expecting a message " + i, message); // sendCallNumber is just a debugging measure. Object prop = message.getObjectProperty(SEND_CALL_NUMBER); if (prop == null) prop = Integer.valueOf(-1); final int actual = message.getIntProperty("counter").intValue(); Assert.assertEquals("expected=" + i + ". Got: property['counter']=" + actual + " sendNumber=" + prop, i, actual); assertMessageBody(i, message); if (ack) message.acknowledge(); } }
Example 2
Source File: RequestorTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void onMessage(final ClientMessage request) { try { ClientMessage reply = session.createMessage(false); SimpleString replyTo = (SimpleString) request.getObjectProperty(ClientMessageImpl.REPLYTO_HEADER_NAME); long value = (Long) request.getObjectProperty(key); reply.putLongProperty(key, value); ClientProducer replyProducer = session.createProducer(replyTo); replyProducer.send(reply); request.acknowledge(); } catch (ActiveMQException e) { e.printStackTrace(); } }
Example 3
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 4
Source File: ClusterTestBase.java From activemq-artemis with Apache License 2.0 | 4 votes |
protected void verifyReceiveAllInRangeNotBefore(final boolean ack, final long firstReceiveTime, final int msgStart, final int msgEnd, final int... consumerIDs) throws Exception { boolean outOfOrder = false; String firstOutOfOrderMessage = null; for (int consumerID : consumerIDs) { ConsumerHolder holder = consumers[consumerID]; if (holder == null) { throw new IllegalArgumentException("No consumer at " + consumerID); } for (int j = msgStart; j < msgEnd; j++) { ClientMessage message = holder.consumer.receive(WAIT_TIMEOUT); if (message == null) { log.debug("*** dumping consumers:"); dumpConsumers(); Assert.fail("consumer " + consumerID + " did not receive message " + j); } if (isLargeMessage()) { checkMessageBody(message); } if (ack) { message.acknowledge(); } if (firstReceiveTime != -1) { Assert.assertTrue("Message received too soon", System.currentTimeMillis() >= firstReceiveTime); } if (j != (Integer) message.getObjectProperty(ClusterTestBase.COUNT_PROP)) { if (firstOutOfOrderMessage == null) { firstOutOfOrderMessage = "expected " + j + " received " + message.getObjectProperty(ClusterTestBase.COUNT_PROP); } outOfOrder = true; log.debug("Message j=" + j + " was received out of order = " + message.getObjectProperty(ClusterTestBase.COUNT_PROP)); log.debug("Message j=" + j + " was received out of order = " + message.getObjectProperty(ClusterTestBase.COUNT_PROP)); } } } Assert.assertFalse("Messages were consumed out of order::" + firstOutOfOrderMessage, outOfOrder); }
Example 5
Source File: ClusterTestBase.java From activemq-artemis with Apache License 2.0 | 4 votes |
protected int[] getReceivedOrder(final int consumerID, final boolean ack) throws Exception { ConsumerHolder consumer = consumers[consumerID]; if (consumer == null) { throw new IllegalArgumentException("No consumer at " + consumerID); } List<Integer> ints = new ArrayList<>(); ClientMessage message = null; do { message = consumer.consumer.receive(500); if (message != null) { if (isLargeMessage()) { checkMessageBody(message); } if (ack) { message.acknowledge(); } int count = (Integer) message.getObjectProperty(ClusterTestBase.COUNT_PROP); ints.add(count); } } while (message != null); int[] res = new int[ints.size()]; int j = 0; for (Integer i : ints) { res[j++] = i; } if (ack) { // just to flush acks consumers[consumerID].session.commit(); } return res; }
Example 6
Source File: MultiThreadRandomReattachTestBase.java From activemq-artemis with Apache License 2.0 | 4 votes |
private void consumeMessages(final Set<ClientConsumer> consumers, final int numMessages, final int threadNum) throws Exception { // We make sure the messages arrive in the order they were sent from a particular producer Map<ClientConsumer, Map<Integer, Integer>> counts = new HashMap<>(); for (int i = 0; i < numMessages; i++) { for (ClientConsumer consumer : consumers) { Map<Integer, Integer> consumerCounts = counts.get(consumer); if (consumerCounts == null) { consumerCounts = new HashMap<>(); counts.put(consumer, consumerCounts); } ClientMessage msg = consumer.receive(MultiThreadRandomReattachTestBase.RECEIVE_TIMEOUT); Assert.assertNotNull(msg); int tn = (Integer) msg.getObjectProperty(new SimpleString("threadnum")); int cnt = (Integer) msg.getObjectProperty(new SimpleString("count")); Integer c = consumerCounts.get(tn); if (c == null) { c = new Integer(cnt); } if (tn == threadNum && cnt != c.intValue()) { throw new Exception("Invalid count, expected " + tn + ": " + c + " got " + cnt); } c++; // Wrap if (c == numMessages) { c = 0; } consumerCounts.put(tn, c); msg.acknowledge(); } } }
Example 7
Source File: MultiThreadRandomReattachTestBase.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override public synchronized void onMessage(final ClientMessage message) { try { message.acknowledge(); } catch (ActiveMQException me) { log.error("Failed to process", me); } if (done) { return; } int threadNum = (Integer) message.getObjectProperty(new SimpleString("threadnum")); int cnt = (Integer) message.getObjectProperty(new SimpleString("count")); Integer c = counts.get(threadNum); if (c == null) { c = new Integer(cnt); } if (tn == threadNum && cnt != c.intValue()) { failure = "Invalid count, expected " + threadNum + ":" + c + " got " + cnt; log.error(failure); latch.countDown(); } if (!checkSize(message)) { failure = "Invalid size on message"; log.error(failure); latch.countDown(); } if (tn == threadNum && c == numMessages - 1) { done = true; latch.countDown(); } c++; // Wrap around at numMessages if (c == numMessages) { c = 0; } counts.put(threadNum, c); }