use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class RedeliveryPolicyTest method testRepeatedRedeliveryReceiveNoCommit.
public void testRepeatedRedeliveryReceiveNoCommit() throws Exception {
connection.start();
Session dlqSession = connection.createSession(true, Session.SESSION_TRANSACTED);
ActiveMQQueue destination = new ActiveMQQueue("TEST");
MessageProducer producer = dlqSession.createProducer(destination);
// Send the messages
producer.send(dlqSession.createTextMessage("1st"));
dlqSession.commit();
MessageConsumer dlqConsumer = dlqSession.createConsumer(new ActiveMQQueue("ActiveMQ.DLQ"));
final int maxRedeliveries = 4;
for (int i = 0; i <= maxRedeliveries + 1; i++) {
connection = (ActiveMQConnection) factory.createConnection(userName, password);
connections.add(connection);
// Receive a message with the JMS API
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(0);
policy.setUseExponentialBackOff(false);
policy.setMaximumRedeliveries(maxRedeliveries);
connection.start();
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(destination);
ActiveMQTextMessage m = ((ActiveMQTextMessage) consumer.receive(4000));
if (i <= maxRedeliveries) {
assertEquals("1st", m.getText());
assertEquals(i, m.getRedeliveryCounter());
} else {
assertNull("null on exceeding redelivery count", m);
}
connection.close();
connections.remove(connection);
}
// We should be able to get the message off the DLQ now.
TextMessage m = (TextMessage) dlqConsumer.receive(1000);
assertNotNull("Got message from DLQ", m);
assertEquals("1st", m.getText());
String cause = m.getStringProperty(ActiveMQMessage.DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY);
assertTrue("cause exception has policy ref", cause.contains("RedeliveryPolicy"));
dlqSession.commit();
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class ActiveMQTextMessageTest method createObject.
@Override
public Object createObject() throws Exception {
ActiveMQTextMessage info = new ActiveMQTextMessage();
populateObject(info);
return info;
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class UdpTestSupport method assertSendTextMessage.
protected void assertSendTextMessage(ActiveMQDestination destination, String text) throws MessageNotWriteableException {
large = true;
ActiveMQTextMessage expected = new ActiveMQTextMessage();
expected.setText(text);
expected.setDestination(destination);
try {
LOG.info("About to send message of type: " + expected.getClass());
producer.oneway(expected);
// lets send a dummy command to ensure things don't block if we
// discard the last one
// keepalive does not have a commandId...
// producer.oneway(new KeepAliveInfo());
producer.oneway(new ProducerInfo());
producer.oneway(new ProducerInfo());
Command received = assertCommandReceived();
assertTrue("Should have received an ActiveMQTextMessage but was: " + received, received instanceof ActiveMQTextMessage);
ActiveMQTextMessage actual = (ActiveMQTextMessage) received;
assertEquals("getDestination", expected.getDestination(), actual.getDestination());
assertEquals("getText", expected.getText(), actual.getText());
LOG.info("Received text message with: " + actual.getText().length() + " character(s)");
} catch (Exception e) {
LOG.info("Caught: " + e);
e.printStackTrace();
fail("Failed to send to transport: " + e);
}
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class QueueDuplicatesFromStoreTest method getMessage.
private Message getMessage(int i) throws Exception {
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setMessageId(new MessageId(mesageIdRoot + i));
message.setDestination(destination);
message.setPersistent(true);
message.setResponseRequired(true);
message.setText("Msg:" + i + " " + text);
assertEquals(message.getMessageId().getProducerSequenceId(), i);
return message;
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class QueueOptimizedDispatchExceptionTest method getMessage.
private Message getMessage(int i) throws Exception {
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setMessageId(new MessageId(mesageIdRoot + i));
message.setDestination(destination);
message.setPersistent(false);
message.setResponseRequired(true);
message.setText("Msg:" + i + " " + text);
assertEquals(message.getMessageId().getProducerSequenceId(), i);
return message;
}
Aggregations