Search in sources :

Example 1 with WildFlyCamelContext

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

the class DynamoDBIntegrationTest method testKeyValueOperations.

@Test
public void testKeyValueOperations() throws Exception {
    AmazonDynamoDBClient client = provider.getClient();
    Assume.assumeNotNull("AWS client not null", client);
    DynamoDBUtils.assertNoStaleTables(client, "before");
    try {
        try {
            TableDescription description = DynamoDBUtils.createTable(client, tableName);
            Assert.assertEquals("ACTIVE", description.getTableStatus());
            WildFlyCamelContext camelctx = new WildFlyCamelContext();
            camelctx.getNamingContext().bind("ddbClientA", client);
            camelctx.addRoutes(new RouteBuilder() {

                @Override
                public void configure() throws Exception {
                    from("direct:start").to("aws-ddb://" + tableName + "?amazonDDBClient=#ddbClientA");
                }
            });
            camelctx.start();
            try {
                DynamoDBUtils.putItem(camelctx, "Book 103 Title");
                String result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
                Assert.assertEquals("Book 103 Title", result);
                DynamoDBUtils.updItem(camelctx, "Book 103 Update");
                result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
                Assert.assertEquals("Book 103 Update", result);
            } finally {
                camelctx.stop();
            }
        } finally {
            DynamoDBUtils.deleteTable(client, tableName);
        }
    } finally {
        DynamoDBUtils.assertNoStaleTables(client, "after");
    }
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) RouteBuilder(org.apache.camel.builder.RouteBuilder) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) Test(org.junit.Test)

Example 2 with WildFlyCamelContext

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

the class EC2IntegrationTest method testCreateInstance.

@Test
public void testCreateInstance() throws Exception {
    AmazonEC2Client ec2Client = provider.getClient();
    Assume.assumeNotNull("AWS client not null", ec2Client);
    assertNoStaleInstances(ec2Client, "before");
    try {
        WildFlyCamelContext camelctx = new WildFlyCamelContext();
        camelctx.getNamingContext().bind("ec2Client", ec2Client);
        camelctx.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("direct:createAndRun").to("aws-ec2://TestDomain?amazonEc2Client=#ec2Client&operation=createAndRunInstances");
                from("direct:terminate").to("aws-ec2://TestDomain?amazonEc2Client=#ec2Client&operation=terminateInstances");
            }
        });
        camelctx.start();
        try {
            // Create and run an instance
            Map<String, Object> headers = new HashMap<>();
            headers.put(EC2Constants.IMAGE_ID, "ami-02ace471");
            headers.put(EC2Constants.INSTANCE_TYPE, InstanceType.T2Micro);
            headers.put(EC2Constants.SUBNET_ID, EC2Utils.getSubnetId(ec2Client));
            headers.put(EC2Constants.INSTANCE_MIN_COUNT, 1);
            headers.put(EC2Constants.INSTANCE_MAX_COUNT, 1);
            headers.put(EC2Constants.INSTANCES_TAGS, Arrays.asList(new Tag("Name", "wildfly-camel")));
            ProducerTemplate template = camelctx.createProducerTemplate();
            RunInstancesResult result1 = template.requestBodyAndHeaders("direct:createAndRun", null, headers, RunInstancesResult.class);
            String instanceId = result1.getReservation().getInstances().get(0).getInstanceId();
            System.out.println("InstanceId: " + instanceId);
            // Terminate the instance
            headers = new HashMap<>();
            headers.put(EC2Constants.INSTANCES_IDS, Collections.singleton(instanceId));
            TerminateInstancesResult result2 = template.requestBodyAndHeaders("direct:terminate", null, headers, TerminateInstancesResult.class);
            Assert.assertEquals(instanceId, result2.getTerminatingInstances().get(0).getInstanceId());
        } finally {
            camelctx.stop();
        }
    } finally {
        assertNoStaleInstances(ec2Client, "after");
    }
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) HashMap(java.util.HashMap) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Tag(com.amazonaws.services.ec2.model.Tag) Test(org.junit.Test)

Example 3 with WildFlyCamelContext

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

the class SESIntegrationTest method sendSimpleMessage.

@Test
public void sendSimpleMessage() throws Exception {
    AmazonSimpleEmailServiceClient sesClient = provider.getClient();
    Assume.assumeNotNull("AWS client not null", sesClient);
    WildFlyCamelContext camelctx = new WildFlyCamelContext();
    camelctx.getNamingContext().bind("sesClient", sesClient);
    camelctx.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:start").to("aws-ses://" + SESUtils.FROM + "?amazonSESClient=#sesClient");
        }
    });
    camelctx.start();
    try {
        Exchange exchange = ExchangeBuilder.anExchange(camelctx).withHeader(SesConstants.SUBJECT, SESUtils.SUBJECT).withHeader(SesConstants.TO, Collections.singletonList(SESUtils.TO)).withBody("Hello world!").build();
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Exchange result = producer.send("direct:start", exchange);
        String messageId = result.getIn().getHeader(SesConstants.MESSAGE_ID, String.class);
        Assert.assertNotNull("MessageId not null", messageId);
    } finally {
        camelctx.stop();
    }
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) AmazonSimpleEmailServiceClient(com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 4 with WildFlyCamelContext

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

the class ReactorIntegrationTest method createWildFlyCamelContext.

private CamelContext createWildFlyCamelContext() throws Exception {
    WildFlyCamelContext camelctx = new WildFlyCamelContext();
    if (boundAlready.compareAndSet(false, true)) {
        Context jndictx = camelctx.getNamingContext();
        jndictx.bind("hello", new SampleBean());
    }
    return camelctx;
}
Also used : Context(javax.naming.Context) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext)

Example 5 with WildFlyCamelContext

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

the class SNSIntegrationTest method sendInOnly.

@Test
public void sendInOnly() 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("snsClientA", snsClient);
            camelctx.addRoutes(new RouteBuilder() {

                public void configure() {
                    from("direct:start").to("aws-sns://" + topicName + "?amazonSNSClient=#snsClientA");
                }
            });
            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(SnsConstants.SUBJECT, "This is my subject");
                        exchange.getIn().setBody("This is my message text.");
                    }
                });
                Assert.assertNotNull(exchange.getIn().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)

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