use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class MessageListenerRedeliveryTest method testQueueSessionListenerExceptionDlq.
@Test
public void testQueueSessionListenerExceptionDlq() throws Exception {
redeliverConnection.start();
Session session = redeliverConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
String qname = "queue-testQueueSessionListenerExceptionDlq";
Queue queue = session.createQueue(qname);
this.makeSureCoreQueueExist(qname);
MessageProducer producer = createProducer(session, queue);
Message message = createTextMessage(session);
producer.send(message);
final Message[] dlqMessage = new Message[1];
ActiveMQDestination dlqDestination = new ActiveMQQueue("ActiveMQ.DLQ");
this.makeSureCoreQueueExist("ActiveMQ.DLQ");
MessageConsumer dlqConsumer = session.createConsumer(dlqDestination);
final CountDownLatch gotDlqMessage = new CountDownLatch(1);
dlqConsumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
System.out.println("DLQ Message Received: " + message);
dlqMessage[0] = message;
gotDlqMessage.countDown();
}
});
MessageConsumer consumer = session.createConsumer(queue);
final int maxDeliveries = getRedeliveryPolicy().getMaximumRedeliveries();
System.out.println("max redlivery: " + maxDeliveries);
final CountDownLatch gotMessage = new CountDownLatch(maxDeliveries);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
System.out.println("Message Received: " + message);
gotMessage.countDown();
throw new RuntimeException(getName() + " force a redelivery");
}
});
assertTrue("got message before retry expiry", gotMessage.await(20, TimeUnit.SECONDS));
// check DLQ
assertTrue("got dlq message", gotDlqMessage.await(20, TimeUnit.SECONDS));
// check DLQ message cause is captured
message = dlqMessage[0];
assertNotNull("dlq message captured", message);
String cause = message.getStringProperty(ActiveMQMessage.DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY);
System.out.println("DLQ'd message cause reported as: " + cause);
assertTrue("cause 'cause' exception is remembered", cause.contains("RuntimeException"));
assertTrue("is correct exception", cause.contains(getName()));
assertTrue("cause exception is remembered", cause.contains("Throwable"));
assertTrue("cause policy is remembered", cause.contains("RedeliveryPolicy"));
session.close();
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class JmsTopicRequestReplyTest method onMessage.
/**
* Use the asynchronous subscription mechanism
*/
@Override
public void onMessage(Message message) {
try {
TextMessage requestMessage = (TextMessage) message;
System.out.println("Received request from " + requestDestination);
System.out.println(requestMessage.toString());
Destination replyDestination = requestMessage.getJMSReplyTo();
// TODO
// String value =
// ActiveMQDestination.getClientId((ActiveMQDestination)
// replyDestination);
// assertEquals("clientID from the temporary destination must be the
// same", clientSideClientID, value);
TextMessage replyMessage = serverSession.createTextMessage("Hello: " + requestMessage.getText());
replyMessage.setJMSCorrelationID(requestMessage.getJMSMessageID());
if (dynamicallyCreateProducer) {
replyProducer = serverSession.createProducer(replyDestination);
replyProducer.send(replyMessage);
} else {
replyProducer.send(replyDestination, replyMessage);
}
System.out.println("Sent reply to " + replyDestination);
System.out.println(replyMessage.toString());
} catch (JMSException e) {
onException(e);
}
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class JMSConsumer12Test method testStartAfterSend.
@Test
public void testStartAfterSend() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQDestination destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination);
// Send the messages
sendMessages(session, destination, 1);
// Start the conncection after the message was sent.
connection.start();
// Make sure only 1 message was delivered.
assertNotNull(consumer.receive(1000));
assertNull(consumer.receiveNoWait());
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class JMSConsumer11Test method testPrefetch1MessageNotDispatched.
@Test
public void testPrefetch1MessageNotDispatched() throws Exception {
// Set prefetch to 1
connection.getPrefetchPolicy().setAll(1);
connection.start();
Session session = connection.createSession(true, 0);
ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
MessageConsumer consumer = session.createConsumer(destination);
// Send 2 messages to the destination.
sendMessages(session, destination, 2);
session.commit();
// The prefetch should fill up with 1 message.
// Since prefetch is still full, the 2nd message should get dispatched
// to another consumer.. lets create the 2nd consumer test that it does
// make sure it does.
ActiveMQConnection connection2 = (ActiveMQConnection) factory.createConnection();
connection2.start();
Session session2 = connection2.createSession(true, 0);
MessageConsumer consumer2 = session2.createConsumer(destination);
System.out.println("consumer receiving ...");
// Pick up the first message.
Message message1 = consumer.receive(1000);
System.out.println("received1: " + message1);
assertNotNull(message1);
System.out.println("consumer 2 receiving...");
// Pick up the 2nd messages.
Message message2 = consumer2.receive(5000);
System.out.println("received2: " + message2);
assertNotNull(message2);
System.out.println("committing sessions !! " + session.getClass().getName());
session.commit();
System.out.println("committed session, now 2");
session2.commit();
System.out.println("all committed");
Message m = consumer.receiveNoWait();
System.out.println("received 3: " + m);
assertNull(m);
try {
connection2.close();
} catch (Throwable e) {
System.err.println("exception e: " + e);
e.printStackTrace();
}
System.out.println("Test finished!!");
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class JMSConsumer13Test method testReceiveMessageWithConsumer.
@Test
public void testReceiveMessageWithConsumer() throws Exception {
// Receive a message with the JMS API
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQDestination destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination);
// Send the messages
sendMessages(session, destination, 1);
// Make sure only 1 message was delivered.
Message m = consumer.receive(1000);
assertNotNull(m);
assertEquals("0", ((TextMessage) m).getText());
assertNull(consumer.receiveNoWait());
}
Aggregations