Search in sources :

Example 56 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project syndesis-qe by syndesisio.

the class JMSUtils method getMessageText.

public static String getMessageText(String appName, String jmsProtocol, String user, String pass, Destination type, String destinationName) {
    Message m = getMessage(appName, jmsProtocol, user, pass, type, destinationName, 60000L);
    if (m == null) {
        return null;
    }
    String text = null;
    try {
        if (m instanceof JmsTextMessage) {
            text = ((JmsTextMessage) m).getText();
        } else if (m instanceof ActiveMQBytesMessage) {
            text = new String(((ActiveMQBytesMessage) m).getContent().getData());
        } else {
            text = ((ActiveMQTextMessage) m).getText();
        }
    } catch (JMSException e) {
        log.error("Unable to get text from message", e);
        e.printStackTrace();
    }
    log.debug("Got message: " + text);
    return text;
}
Also used : ActiveMQBytesMessage(org.apache.activemq.command.ActiveMQBytesMessage) JmsTextMessage(org.apache.qpid.jms.message.JmsTextMessage) Message(javax.jms.Message) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) ActiveMQBytesMessage(org.apache.activemq.command.ActiveMQBytesMessage) JMSException(javax.jms.JMSException) JmsTextMessage(org.apache.qpid.jms.message.JmsTextMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 57 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project rocketmq-externals by apache.

the class ActivemqSourceTaskTest method getMessageConnentTest.

@Test(expected = RuntimeException.class)
public void getMessageConnentTest() throws JMSException {
    String value = "hello rocketmq";
    ActivemqSourceTask task = new ActivemqSourceTask();
    TextMessage textMessage = new ActiveMQTextMessage();
    textMessage.setText(value);
    ByteBuffer buffer = task.getMessageConnent(textMessage);
    Assert.assertEquals(new String(buffer.array()), textMessage.getText());
    ObjectMessage objectMessage = new ActiveMQObjectMessage();
    objectMessage.setObject(value);
    buffer = task.getMessageConnent(objectMessage);
    Assert.assertEquals(new String(buffer.array()), "\"" + objectMessage.getObject().toString() + "\"");
    BytesMessage bytes = new ActiveMQBytesMessage();
    bytes.writeBytes(value.getBytes());
    bytes.reset();
    buffer = task.getMessageConnent(bytes);
    Assert.assertEquals(new String(buffer.array()), value);
    MapMessage mapMessage = new ActiveMQMapMessage();
    mapMessage.setString("hello", "rocketmq");
    buffer = task.getMessageConnent(mapMessage);
    Map<String, String> map = JSON.parseObject(buffer.array(), Map.class);
    Assert.assertEquals(map.get("hello"), "rocketmq");
    Assert.assertEquals(map.size(), 1);
    StreamMessage streamMessage = new ActiveMQStreamMessage();
    String valueTwo = null;
    for (int i = 0; i < 200; i++) {
        valueTwo = valueTwo + value;
    }
    streamMessage.writeBytes(valueTwo.getBytes());
    streamMessage.reset();
    buffer = task.getMessageConnent(streamMessage);
    Assert.assertEquals(new String(buffer.array()), valueTwo);
    task.getMessageConnent(null);
}
Also used : ActiveMQMapMessage(org.apache.activemq.command.ActiveMQMapMessage) ActiveMQObjectMessage(org.apache.activemq.command.ActiveMQObjectMessage) MapMessage(javax.jms.MapMessage) ActiveMQMapMessage(org.apache.activemq.command.ActiveMQMapMessage) ActiveMQBytesMessage(org.apache.activemq.command.ActiveMQBytesMessage) BytesMessage(javax.jms.BytesMessage) ActiveMQStreamMessage(org.apache.activemq.command.ActiveMQStreamMessage) ByteBuffer(java.nio.ByteBuffer) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) ObjectMessage(javax.jms.ObjectMessage) ActiveMQObjectMessage(org.apache.activemq.command.ActiveMQObjectMessage) ActiveMQBytesMessage(org.apache.activemq.command.ActiveMQBytesMessage) StreamMessage(javax.jms.StreamMessage) ActiveMQStreamMessage(org.apache.activemq.command.ActiveMQStreamMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 58 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project brave by openzipkin.

the class TracingMessageListenerTest method consumer_and_listener_have_names.

@Test
public void consumer_and_listener_have_names() {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    onMessageConsumed(message);
    assertThat(testSpanHandler.takeRemoteSpan(CONSUMER).name()).isEqualTo("receive");
    assertThat(testSpanHandler.takeLocalSpan().name()).isEqualTo("on-message");
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Test(org.junit.Test)

Example 59 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project brave by openzipkin.

the class TracingMessageListenerTest method consumer_span_starts_before_listener.

@Test
public void consumer_span_starts_before_listener() {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    onMessageConsumed(message);
    MutableSpan consumerSpan = testSpanHandler.takeRemoteSpan(CONSUMER);
    MutableSpan listenerSpan = testSpanHandler.takeLocalSpan();
    assertChildOf(listenerSpan, consumerSpan);
    assertSequential(consumerSpan, listenerSpan);
}
Also used : MutableSpan(brave.handler.MutableSpan) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Test(org.junit.Test)

Example 60 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project brave by openzipkin.

the class TracingMessageListenerTest method starts_new_trace_if_none_exists.

@Test
public void starts_new_trace_if_none_exists() {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    onMessageConsumed(message);
    testSpanHandler.takeRemoteSpan(CONSUMER);
    testSpanHandler.takeLocalSpan();
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Test(org.junit.Test)

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