Search in sources :

Example 1 with TestPartiallySerializableObject

use of org.apache.camel.component.rabbitmq.testbeans.TestPartiallySerializableObject 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)

Example 2 with TestPartiallySerializableObject

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

the class RabbitMQInOutIntTest method partiallySerializeTest.

@Test
public void partiallySerializeTest() throws InterruptedException, IOException {
    TestPartiallySerializableObject foo = new TestPartiallySerializableObject();
    foo.setName("foobar");
    try {
        TestPartiallySerializableObject reply = template.requestBodyAndHeader("direct:rabbitMQ", foo, RabbitMQConstants.EXCHANGE_NAME, EXCHANGE, TestPartiallySerializableObject.class);
    } catch (CamelExecutionException e) {
    // expected
    }
    // Make sure we didn't crash the one Consumer thread
    String reply2 = template.requestBodyAndHeader("direct:rabbitMQ", "partiallySerializeTest1", RabbitMQConstants.EXCHANGE_NAME, EXCHANGE, String.class);
    assertEquals("partiallySerializeTest1 response", reply2);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) TestPartiallySerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestPartiallySerializableObject) Test(org.junit.Test)

Aggregations

CamelExecutionException (org.apache.camel.CamelExecutionException)2 TestPartiallySerializableObject (org.apache.camel.component.rabbitmq.testbeans.TestPartiallySerializableObject)2 IOException (java.io.IOException)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 TestSerializableObject (org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject)1 Test (org.junit.Test)1