use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class RedeliveryPolicyTest method testInitialRedeliveryDelayOne.
public void testInitialRedeliveryDelayOne() throws Exception {
// Receive a message with the JMS API
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(1000);
policy.setUseExponentialBackOff(false);
policy.setMaximumRedeliveries(1);
connection.start();
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
ActiveMQQueue destination = new ActiveMQQueue("TEST");
MessageProducer producer = session.createProducer(destination);
MessageConsumer consumer = session.createConsumer(destination);
// Send the messages
producer.send(session.createTextMessage("1st"));
producer.send(session.createTextMessage("2nd"));
session.commit();
TextMessage m;
m = (TextMessage) consumer.receive(100);
assertNotNull(m);
assertEquals("1st", m.getText());
session.rollback();
m = (TextMessage) consumer.receive(100);
assertNull(m);
m = (TextMessage) consumer.receive(2000);
assertNotNull(m);
assertEquals("1st", m.getText());
m = (TextMessage) consumer.receive(100);
assertNotNull(m);
assertEquals("2nd", m.getText());
session.commit();
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class MessageListenerRedeliveryTest method testQueueSessionListenerExceptionDlq.
public void testQueueSessionListenerExceptionDlq() throws Exception {
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("queue-" + getName());
MessageProducer producer = createProducer(session, queue);
Message message = createTextMessage(session);
producer.send(message);
final Message[] dlqMessage = new Message[1];
ActiveMQDestination dlqDestination = new ActiveMQQueue("ActiveMQ.DLQ");
MessageConsumer dlqConsumer = session.createConsumer(dlqDestination);
final CountDownLatch gotDlqMessage = new CountDownLatch(1);
dlqConsumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
LOG.info("DLQ Message Received: " + message);
dlqMessage[0] = message;
gotDlqMessage.countDown();
}
});
MessageConsumer consumer = session.createConsumer(queue);
final int maxDeliveries = getRedeliveryPolicy().getMaximumRedeliveries();
final CountDownLatch gotMessage = new CountDownLatch(maxDeliveries);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
LOG.info("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);
LOG.info("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.ActiveMQQueue in project activemq-artemis by apache.
the class QueueConsumerPriorityTest method testQueueConsumerPriority.
public void testQueueConsumerPriority() throws JMSException, InterruptedException {
Connection conn = createConnection(true);
Session consumerLowPriority = null;
Session consumerHighPriority = null;
Session senderSession = null;
try {
consumerLowPriority = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumerHighPriority = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(consumerHighPriority);
senderSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
String queueName = getClass().getName();
ActiveMQQueue low = new ActiveMQQueue(queueName + "?consumer.priority=1");
MessageConsumer lowConsumer = consumerLowPriority.createConsumer(low);
ActiveMQQueue high = new ActiveMQQueue(queueName + "?consumer.priority=2");
MessageConsumer highConsumer = consumerLowPriority.createConsumer(high);
ActiveMQQueue senderQueue = new ActiveMQQueue(queueName);
MessageProducer producer = senderSession.createProducer(senderQueue);
Message msg = senderSession.createTextMessage("test");
for (int i = 0; i < 10000; i++) {
producer.send(msg);
assertNotNull("null on iteration: " + i, highConsumer.receive(500));
}
assertNull(lowConsumer.receive(2000));
} finally {
conn.close();
}
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class RedeliveryPolicyTest method testNornalRedeliveryPolicyDelaysDeliveryOnRollback.
/**
* @throws Exception
*/
public void testNornalRedeliveryPolicyDelaysDeliveryOnRollback() throws Exception {
// Receive a message with the JMS API
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(0);
policy.setRedeliveryDelay(500);
connection.start();
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
ActiveMQQueue destination = new ActiveMQQueue(getName());
MessageProducer producer = session.createProducer(destination);
MessageConsumer consumer = session.createConsumer(destination);
// Send the messages
producer.send(session.createTextMessage("1st"));
producer.send(session.createTextMessage("2nd"));
session.commit();
TextMessage m;
m = (TextMessage) consumer.receive(1000);
assertNotNull(m);
assertEquals("1st", m.getText());
session.rollback();
// No delay on first rollback..
m = (TextMessage) consumer.receive(100);
assertNotNull(m);
session.rollback();
// Show subsequent re-delivery delay is incrementing.
m = (TextMessage) consumer.receive(100);
assertNull(m);
m = (TextMessage) consumer.receive(700);
assertNotNull(m);
assertEquals("1st", m.getText());
session.rollback();
// The message gets redelivered after 500 ms every time since
// we are not using exponential backoff.
m = (TextMessage) consumer.receive(100);
assertNull(m);
m = (TextMessage) consumer.receive(700);
assertNotNull(m);
assertEquals("1st", m.getText());
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class Main method main.
/**
* @param args
*/
public static void main(String[] args) {
try {
BrokerService broker = new BrokerService();
broker.setPersistent(false);
// String brokerDir = "xbean:...;
// System.setProperty("activemq.base", brokerDir);
// BrokerService broker = BrokerFactory.createBroker(new URI(brokerDir + "/activemq.xml"));
// for running on Java 5 without mx4j
ManagementContext managementContext = broker.getManagementContext();
managementContext.setFindTigerMbeanServer(true);
managementContext.setUseMBeanServer(true);
managementContext.setCreateConnector(false);
broker.setUseJmx(true);
// broker.setPlugins(new BrokerPlugin[] { new
// ConnectionDotFilePlugin(), new UDPTraceBrokerPlugin() });
broker.addConnector("tcp://localhost:61616");
broker.addConnector("stomp://localhost:61613");
broker.start();
// lets publish some messages so that there is some stuff to browse
DefaultQueueSender.main(new String[] { "Prices.Equity.IBM" });
DefaultQueueSender.main(new String[] { "Prices.Equity.MSFT" });
// lets create a dummy couple of consumers
if (createConsumers) {
Connection connection = new ActiveMQConnectionFactory().createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createConsumer(new ActiveMQQueue("Orders.IBM"));
session.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 100");
Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
session2.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 200");
} else {
// Lets wait for the broker
broker.waitUntilStopped();
}
} catch (Exception e) {
System.out.println("Failed: " + e);
e.printStackTrace();
}
}
Aggregations