Search in sources :

Example 71 with PollingConsumer

use of org.apache.camel.PollingConsumer in project wildfly-camel by wildfly-extras.

the class SJMSIntegrationTest method testMessageConsumerRoute.

@Test
public void testMessageConsumerRoute() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("sjms:queue:" + QUEUE_NAME + "?connectionFactory=ConnectionFactory").transform(body().prepend("Hello ")).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", result);
        } finally {
            connection.close();
        }
    } finally {
        camelctx.stop();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) PollingConsumer(org.apache.camel.PollingConsumer) ConnectionFactory(javax.jms.ConnectionFactory) RouteBuilder(org.apache.camel.builder.RouteBuilder) Connection(javax.jms.Connection) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Example 72 with PollingConsumer

use of org.apache.camel.PollingConsumer 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)

Example 73 with PollingConsumer

use of org.apache.camel.PollingConsumer in project wildfly-swarm by wildfly-swarm.

the class JMSIntegrationTest method testMessageConsumerRoute.

@Test
public void testMessageConsumerRoute() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("jms:queue:" + Main.QUEUE_NAME + "?connectionFactory=ConnectionFactory").transform(body().prepend("Hello ")).to("direct:end");
        }
    });
    camelctx.start();
    PollingConsumer consumer = camelctx.getEndpoint("direct:end").createPollingConsumer();
    consumer.start();
    try {
        // Send a message to the queue
        InitialContext initialctx = new InitialContext();
        ConnectionFactory cfactory = (ConnectionFactory) initialctx.lookup("java:/ConnectionFactory");
        Connection connection = cfactory.createConnection();
        try {
            sendMessage(connection, Main.QUEUE_JNDI_NAME, "Kermit");
            String result = consumer.receive().getIn().getBody(String.class);
            Assert.assertEquals("Hello Kermit", result);
        } finally {
            connection.close();
        }
    } finally {
        camelctx.stop();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) PollingConsumer(org.apache.camel.PollingConsumer) ConnectionFactory(javax.jms.ConnectionFactory) RouteBuilder(org.apache.camel.builder.RouteBuilder) Connection(javax.jms.Connection) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) JMSException(javax.jms.JMSException) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Aggregations

PollingConsumer (org.apache.camel.PollingConsumer)73 Exchange (org.apache.camel.Exchange)41 Test (org.junit.Test)27 HashMap (java.util.HashMap)21 CamelContext (org.apache.camel.CamelContext)21 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)21 RouteBuilder (org.apache.camel.builder.RouteBuilder)19 Endpoint (org.apache.camel.Endpoint)10 Connection (javax.jms.Connection)9 Transactional (org.springframework.transaction.annotation.Transactional)9 ConnectionFactory (javax.jms.ConnectionFactory)7 JMSException (javax.jms.JMSException)7 MessageConversionException (org.springframework.jms.support.converter.MessageConversionException)5 ProducerTemplate (org.apache.camel.ProducerTemplate)4 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)4 Message (javax.jms.Message)3 Session (javax.jms.Session)3 TextMessage (javax.jms.TextMessage)3 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)3 File (java.io.File)2