Search in sources :

Example 51 with ActiveMQTextMessage

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

the class DummyMessageQuery method execute.

@Override
public void execute(ActiveMQDestination destination, MessageListener listener) throws Exception {
    LOG.info("Initial query is creating: " + MESSAGE_COUNT + " messages");
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        ActiveMQTextMessage message = new ActiveMQTextMessage();
        message.setText("Initial message: " + i + " loaded from query");
        listener.onMessage(message);
    }
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 52 with ActiveMQTextMessage

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

the class SelectorTest method testXPathSelectors.

public void testXPathSelectors() throws Exception {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    message.setJMSType("xml");
    message.setText("<root><a key='first' num='1'/><b key='second' num='2'>b</b></root>");
    assertSelector(message, "XPATH 'root/a'", true);
    assertSelector(message, "XPATH '//root/b'", true);
    assertSelector(message, "XPATH 'root/c'", false);
    assertSelector(message, "XPATH '//root/b/text()=\"b\"'", true);
    assertSelector(message, "XPATH '//root/b=\"b\"'", true);
    assertSelector(message, "XPATH '//root/b=\"c\"'", false);
    assertSelector(message, "XPATH '//root/b!=\"c\"'", true);
    assertSelector(message, "XPATH '//root/*[@key=''second'']'", true);
    assertSelector(message, "XPATH '//root/*[@key=''third'']'", false);
    assertSelector(message, "XPATH '//root/a[@key=''first'']'", true);
    assertSelector(message, "XPATH '//root/a[@num=1]'", true);
    assertSelector(message, "XPATH '//root/a[@key=''second'']'", false);
    assertSelector(message, "XPATH '/root/*[@key=''first'' or @key=''third'']'", true);
    assertSelector(message, "XPATH '//root/*[@key=''third'' or @key=''forth'']'", false);
    assertSelector(message, "XPATH '/root/b=''b'' and /root/b[@key=''second'']'", true);
    assertSelector(message, "XPATH '/root/b=''b'' and /root/b[@key=''first'']'", false);
    assertSelector(message, "XPATH 'not(//root/a)'", false);
    assertSelector(message, "XPATH 'not(//root/c)'", true);
    assertSelector(message, "XPATH '//root/a[not(@key=''first'')]'", false);
    assertSelector(message, "XPATH '//root/a[not(not(@key=''first''))]'", true);
    assertSelector(message, "XPATH 'string(//root/b)'", true);
    assertSelector(message, "XPATH 'string(//root/a)'", false);
    assertSelector(message, "XPATH 'sum(//@num) < 10'", true);
    assertSelector(message, "XPATH 'sum(//@num) > 10'", false);
    assertSelector(message, "XPATH '//root/a[@num > 1]'", false);
    assertSelector(message, "XPATH '//root/b[@num > 1]'", true);
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 53 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project webcert by sklintyg.

the class NotificationServiceImplTest method createTextMessage.

private TextMessage createTextMessage(String s) throws JMSException {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    message.setText(s);
    return message;
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 54 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project wildfly-camel by wildfly-extras.

the class ActiveMQIntegrationTest method testCustomMessageConverter.

@Test
public void testCustomMessageConverter() throws Exception {
    MessageConverter converter = new MessageConverter() {

        @Override
        public Message toMessage(Object o, Session session) throws JMSException, MessageConversionException {
            return null;
        }

        @Override
        public Object fromMessage(Message message) throws JMSException, MessageConversionException {
            TextMessage originalMessage = (TextMessage) message;
            TextMessage modifiedMessage = new ActiveMQTextMessage();
            modifiedMessage.setText(originalMessage.getText() + " Modified");
            return modifiedMessage;
        }
    };
    context.bind("messageConverter", converter);
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            fromF("activemq:queue:%s?connectionFactory=java:/ActiveMQConnectionFactory&messageConverter=#messageConverter", QUEUE_NAME).transform(simple("Hello ${body.getText()}")).to("seda:end");
        }
    });
    PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    pollingConsumer.start();
    camelctx.start();
    try {
        ConnectionFactory connectionFactory = lookupConnectionFactory();
        Connection con = connectionFactory.createConnection();
        try {
            sendMessage(con, "Kermit");
            String result = pollingConsumer.receive(3000).getIn().getBody(String.class);
            Assert.assertEquals("Hello Kermit Modified", result);
        } finally {
            con.close();
        }
    } finally {
        camelctx.stop();
        context.unbind("messageConverter");
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) PollingConsumer(org.apache.camel.PollingConsumer) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) RouteBuilder(org.apache.camel.builder.RouteBuilder) Connection(javax.jms.Connection) MessageConverter(org.springframework.jms.support.converter.MessageConverter) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) NamingException(javax.naming.NamingException) MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) JMSException(javax.jms.JMSException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 55 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project wildfly-camel by wildfly-extras.

the class JMSIntegrationTest method testCustomMessageConverter.

@Test
public void testCustomMessageConverter() throws Exception {
    MessageConverter converter = new MessageConverter() {

        @Override
        public Message toMessage(Object o, Session session) throws JMSException, MessageConversionException {
            return null;
        }

        @Override
        public Object fromMessage(Message message) throws JMSException, MessageConversionException {
            TextMessage originalMessage = (TextMessage) message;
            TextMessage modifiedMessage = new ActiveMQTextMessage();
            modifiedMessage.setText(originalMessage.getText() + " Modified");
            return modifiedMessage;
        }
    };
    initialctx.bind("messageConverter", converter);
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            fromF("jms:queue:%s?connectionFactory=ConnectionFactory&messageConverter=#messageConverter", QUEUE_NAME).transform(simple("Hello ${body.getText()}")).to("seda:end");
        }
    });
    camelctx.start();
    PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    consumer.start();
    try {
        // Send a message to the queue
        ConnectionFactory cfactory = (ConnectionFactory) initialctx.lookup("java:/ConnectionFactory");
        Connection connection = cfactory.createConnection();
        try {
            sendMessage(connection, QUEUE_JNDI_NAME, "Kermit");
            String result = consumer.receive(3000).getIn().getBody(String.class);
            Assert.assertEquals("Hello Kermit Modified", result);
        } finally {
            connection.close();
        }
    } finally {
        camelctx.stop();
        initialctx.unbind("messageConverter");
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) PollingConsumer(org.apache.camel.PollingConsumer) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(javax.jms.Message) JmsMessage(org.apache.camel.component.jms.JmsMessage) TextMessage(javax.jms.TextMessage) RouteBuilder(org.apache.camel.builder.RouteBuilder) Connection(javax.jms.Connection) MessageConverter(org.springframework.jms.support.converter.MessageConverter) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) JMSException(javax.jms.JMSException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) 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