Search in sources :

Example 41 with ActiveMQTextMessage

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();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Session(javax.jms.Session) ServerSession(javax.jms.ServerSession) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 42 with ActiveMQTextMessage

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;
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 43 with ActiveMQTextMessage

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);
    }
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) Command(org.apache.activemq.command.Command) IOException(java.io.IOException) MessageNotWriteableException(javax.jms.MessageNotWriteableException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 44 with ActiveMQTextMessage

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;
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) MessageId(org.apache.activemq.command.MessageId)

Example 45 with ActiveMQTextMessage

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;
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) MessageId(org.apache.activemq.command.MessageId)

Aggregations

ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)71 Test (org.junit.Test)36 TextMessage (javax.jms.TextMessage)16 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)14 Message (javax.jms.Message)10 MessageProducer (javax.jms.MessageProducer)10 MessageConsumer (javax.jms.MessageConsumer)9 MessageId (org.apache.activemq.command.MessageId)9 JMSException (javax.jms.JMSException)7 ActiveMQBytesMessage (org.apache.activemq.command.ActiveMQBytesMessage)7 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)6 MessageReference (org.apache.activemq.broker.region.MessageReference)6 Queue (org.apache.activemq.broker.region.Queue)6 ActiveMQMapMessage (org.apache.activemq.command.ActiveMQMapMessage)6 ActiveMQObjectMessage (org.apache.activemq.command.ActiveMQObjectMessage)6 ActiveMQStreamMessage (org.apache.activemq.command.ActiveMQStreamMessage)6 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)6 SystemUsage (org.apache.activemq.usage.SystemUsage)6 MutableSpan (brave.handler.MutableSpan)5 MessageNotWriteableException (javax.jms.MessageNotWriteableException)5