Search in sources :

Example 1 with TestNonSerializableObject

use of org.apache.camel.component.rabbitmq.testbeans.TestNonSerializableObject in project camel by apache.

the class RabbitMQInOutIntTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:rabbitMQ").id("producingRoute").setHeader("routeHeader", simple("routeHeader")).inOut(rabbitMQEndpoint);
            from(rabbitMQEndpoint).id("consumingRoute").log("Receiving message").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    if (exchange.getIn().getBody(TestSerializableObject.class) != null) {
                        TestSerializableObject foo = exchange.getIn().getBody(TestSerializableObject.class);
                        foo.setDescription("foobar");
                    } else if (exchange.getIn().getBody(TestPartiallySerializableObject.class) != null) {
                        TestPartiallySerializableObject foo = exchange.getIn().getBody(TestPartiallySerializableObject.class);
                        foo.setNonSerializableObject(new TestNonSerializableObject());
                        foo.setDescription("foobar");
                    } else if (exchange.getIn().getBody(String.class) != null) {
                        if (exchange.getIn().getBody(String.class).contains("header")) {
                            assertEquals(exchange.getIn().getHeader("String"), "String");
                            assertEquals(exchange.getIn().getHeader("routeHeader"), "routeHeader");
                        }
                        if (exchange.getIn().getBody(String.class).contains("Exception")) {
                            throw new IllegalArgumentException("Boom");
                        }
                        if (exchange.getIn().getBody(String.class).contains("TimeOut")) {
                            Thread.sleep(TIMEOUT_MS * 2);
                        }
                        exchange.getIn().setBody(exchange.getIn().getBody(String.class) + " response");
                    }
                }
            });
            from("direct:rabbitMQNoAutoAck").id("producingRouteNoAutoAck").setHeader("routeHeader", simple("routeHeader")).inOut(noAutoAckEndpoint);
            from(noAutoAckEndpoint).id("consumingRouteNoAutoAck").to(resultEndpoint).throwException(new IllegalStateException("test exception"));
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) TestSerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject) Processor(org.apache.camel.Processor) TestPartiallySerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestPartiallySerializableObject) RouteBuilder(org.apache.camel.builder.RouteBuilder) TestNonSerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestNonSerializableObject) CamelExecutionException(org.apache.camel.CamelExecutionException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 CamelExecutionException (org.apache.camel.CamelExecutionException)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 TestNonSerializableObject (org.apache.camel.component.rabbitmq.testbeans.TestNonSerializableObject)1 TestPartiallySerializableObject (org.apache.camel.component.rabbitmq.testbeans.TestPartiallySerializableObject)1 TestSerializableObject (org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject)1