Search in sources :

Example 6 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class SNSIntegrationTest method sendInOut.

@Test
public void sendInOut() throws Exception {
    AmazonSNSClient snsClient = provider.getClient();
    Assume.assumeNotNull("AWS client not null", snsClient);
    assertNoStaleTopic(snsClient, "before");
    try {
        final String arn = snsClient.createTopic(topicName).getTopicArn();
        try {
            WildFlyCamelContext camelctx = new WildFlyCamelContext();
            camelctx.getNamingContext().bind("snsClientB", snsClient);
            camelctx.addRoutes(new RouteBuilder() {

                public void configure() {
                    from("direct:start").to("aws-sns://" + topicName + "?amazonSNSClient=#snsClientB");
                }
            });
            camelctx.start();
            try {
                ProducerTemplate producer = camelctx.createProducerTemplate();
                Exchange exchange = producer.send("direct:start", ExchangePattern.InOut, new Processor() {

                    public void process(Exchange exchange) throws Exception {
                        exchange.getIn().setHeader(SnsConstants.SUBJECT, "This is my subject");
                        exchange.getIn().setBody("This is my message text.");
                    }
                });
                Assert.assertNotNull(exchange.getOut().getHeader(SnsConstants.MESSAGE_ID));
            } finally {
                camelctx.stop();
            }
        } finally {
            snsClient.deleteTopic(arn);
        }
    } finally {
        assertNoStaleTopic(snsClient, "after");
    }
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient) Test(org.junit.Test)

Example 7 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class SQSIntegrationTest method sendInOnly.

@Test
public void sendInOnly() throws Exception {
    AmazonSQSClient sqsClient = provider.getClient();
    Assume.assumeNotNull("AWS client not null", sqsClient);
    assertNoStaleQueue(sqsClient, "before");
    try {
        final String url = sqsClient.createQueue(queueName).getQueueUrl();
        try {
            WildFlyCamelContext camelctx = new WildFlyCamelContext();
            camelctx.getNamingContext().bind("sqsClient", sqsClient);
            camelctx.addRoutes(new RouteBuilder() {

                public void configure() {
                    from("direct:start").to("aws-sqs://" + queueName + "?amazonSQSClient=#sqsClient");
                    from("aws-sqs://" + queueName + "?amazonSQSClient=#sqsClient").to("mock:result");
                }
            });
            MockEndpoint mockep = camelctx.getEndpoint("mock:result", MockEndpoint.class);
            mockep.expectedMessageCount(1);
            camelctx.start();
            try {
                ProducerTemplate producer = camelctx.createProducerTemplate();
                producer.send("direct:start", ExchangePattern.InOnly, new Processor() {

                    public void process(Exchange exchange) throws Exception {
                        exchange.getIn().setBody("This is my message text.");
                    }
                });
                mockep.assertIsSatisfied();
                Exchange exchange = mockep.getExchanges().get(0);
                Assert.assertEquals("This is my message text.", exchange.getIn().getBody());
                Assert.assertNotNull(exchange.getIn().getHeader(SqsConstants.MESSAGE_ID));
                Assert.assertNotNull(exchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE));
                Assert.assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getIn().getHeader(SqsConstants.MD5_OF_BODY));
                Assert.assertNotNull(exchange.getIn().getHeader(SqsConstants.ATTRIBUTES));
                Assert.assertNotNull(exchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES));
            } finally {
                camelctx.stop();
            }
        } finally {
            sqsClient.deleteQueue(url);
        }
    } finally {
        assertNoStaleQueue(sqsClient, "after");
    }
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AmazonSQSClient(com.amazonaws.services.sqs.AmazonSQSClient) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 8 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class KinesisIntegrationTest method send.

@Test
public void send() throws Exception {
    AmazonKinesisClient kinClient = provider.getClient();
    Assume.assumeNotNull("AWS client not null", kinClient);
    assertNoStaleStreams(kinClient, "before");
    try {
        KinesisUtils.createStream(kinClient, streamName);
        try {
            WildFlyCamelContext camelctx = new WildFlyCamelContext();
            camelctx.getNamingContext().bind("kinClient", kinClient);
            camelctx.addRoutes(new RouteBuilder() {

                public void configure() {
                    from("direct:start").to("aws-kinesis://" + streamName + "?amazonKinesisClient=#kinClient");
                    from("aws-kinesis://" + streamName + "?amazonKinesisClient=#kinClient").to("mock:result");
                }
            });
            MockEndpoint mockep = camelctx.getEndpoint("mock:result", MockEndpoint.class);
            mockep.expectedMessageCount(2);
            camelctx.start();
            try {
                ProducerTemplate producer = camelctx.createProducerTemplate();
                Exchange exchange = producer.send("direct:start", ExchangePattern.InOnly, new Processor() {

                    public void process(Exchange exchange) throws Exception {
                        exchange.getIn().setHeader(KinesisConstants.PARTITION_KEY, "partition-1");
                        exchange.getIn().setBody("Kinesis Event 1.");
                    }
                });
                Assert.assertNull(exchange.getException());
                exchange = producer.send("direct:start", ExchangePattern.InOut, new Processor() {

                    public void process(Exchange exchange) throws Exception {
                        exchange.getIn().setHeader(KinesisConstants.PARTITION_KEY, "partition-1");
                        exchange.getIn().setBody("Kinesis Event 2.");
                    }
                });
                Assert.assertNull(exchange.getException());
                mockep.assertIsSatisfied();
                assertResultExchange(mockep.getExchanges().get(0), "Kinesis Event 1.", "partition-1");
                assertResultExchange(mockep.getExchanges().get(1), "Kinesis Event 2.", "partition-1");
            } finally {
                camelctx.stop();
            }
        } finally {
            kinClient.deleteStream(streamName);
        }
    } finally {
        assertNoStaleStreams(kinClient, "after");
    }
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) AmazonKinesisClient(com.amazonaws.services.kinesis.AmazonKinesisClient) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 9 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class GuavaEventIntegrationTest method shouldReceiveMessageFromCamel.

@Test
public void shouldReceiveMessageFromCamel() throws Exception {
    WildFlyCamelContext camelctx = new WildFlyCamelContext();
    camelctx.getNamingContext().bind("eventBusB", eventBus);
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("guava-eventbus:eventBusB");
        }
    });
    camelctx.start();
    try {
        String message = "message";
        eventBus.register(this);
        ProducerTemplate producer = camelctx.createProducerTemplate();
        producer.sendBody("direct:start", message);
        Assert.assertEquals(message, receivedEvent);
    } finally {
        camelctx.stop();
    }
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 10 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class CaffeineCacheIntegrationTest method before.

@Before
public void before() throws NamingException {
    camelctx = new WildFlyCamelContext();
    Context jndi = camelctx.getNamingContext();
    jndi.rebind("cache", cache);
    jndi.rebind("cacheRl", cacheRl);
    jndi.rebind("cacheSc", cacheSc);
}
Also used : Context(javax.naming.Context) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Before(org.junit.Before)

Aggregations

WildFlyCamelContext (org.wildfly.extension.camel.WildFlyCamelContext)26 Test (org.junit.Test)20 RouteBuilder (org.apache.camel.builder.RouteBuilder)18 ProducerTemplate (org.apache.camel.ProducerTemplate)14 Exchange (org.apache.camel.Exchange)8 Context (javax.naming.Context)6 Processor (org.apache.camel.Processor)6 HashMap (java.util.HashMap)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 CamelContext (org.apache.camel.CamelContext)3 Before (org.junit.Before)3 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)2 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)2 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)2 AmazonSNSClient (com.amazonaws.services.sns.AmazonSNSClient)2 List (java.util.List)2 InitialContext (javax.naming.InitialContext)2 CamelContextFactory (org.wildfly.extension.camel.CamelContextFactory)2 AmazonCloudWatchClient (com.amazonaws.services.cloudwatch.AmazonCloudWatchClient)1 DimensionFilter (com.amazonaws.services.cloudwatch.model.DimensionFilter)1