use of org.apache.camel.PollingConsumer in project wildfly-camel by wildfly-extras.
the class AhcWSSIntegrationTest method testAsyncWssRoute.
@Test
public void testAsyncWssRoute() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("ahc-wss:" + WEBSOCKET_ENDPOINT);
from("ahc-wss:" + WEBSOCKET_ENDPOINT).to("seda:end");
}
});
WsComponent wsComponent = (WsComponent) camelctx.getComponent("ahc-wss");
wsComponent.setSslContextParameters(defineSSLContextClientParameters());
PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
consumer.start();
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
producer.sendBody("direct:start", "Kermit");
Exchange exchange = consumer.receive(1000);
Assert.assertEquals("Hello Kermit", exchange.getIn().getBody(String.class));
} finally {
camelctx.stop();
}
}
use of org.apache.camel.PollingConsumer in project wildfly-camel by wildfly-extras.
the class DynamoDBStreamsIntegrationTest method testKeyValueOperations.
@Test
public void testKeyValueOperations() throws Exception {
AmazonDynamoDBClient ddbClient = ddbProvider.getClient();
Assume.assumeNotNull("AWS client not null", ddbClient);
DynamoDBUtils.assertNoStaleTables(ddbClient, "before");
try {
try {
TableDescription description = DynamoDBUtils.createTable(ddbClient, tableName);
Assert.assertEquals("ACTIVE", description.getTableStatus());
WildFlyCamelContext camelctx = new WildFlyCamelContext();
camelctx.getNamingContext().bind("ddbClientB", ddbClient);
camelctx.getNamingContext().bind("dbsClientB", dbsProvider.getClient());
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("aws-ddb://" + tableName + "?amazonDDBClient=#ddbClientB");
from("aws-ddbstream://" + tableName + "?amazonDynamoDbStreamsClient=#dbsClientB").to("seda:end");
}
});
PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
pollingConsumer.start();
camelctx.start();
try {
DynamoDBUtils.putItem(camelctx, "Book 103 Title");
String result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
Assert.assertEquals("Book 103 Title", result);
Exchange exchange = pollingConsumer.receive(3000);
Assert.assertNull(exchange);
DynamoDBUtils.updItem(camelctx, "Book 103 Update");
result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
Assert.assertEquals("Book 103 Update", result);
exchange = pollingConsumer.receive(3000);
StreamRecord record = exchange.getIn().getBody(Record.class).getDynamodb();
Map<String, AttributeValue> oldImage = record.getOldImage();
Map<String, AttributeValue> newImage = record.getNewImage();
Assert.assertEquals("Book 103 Title", oldImage.get("Title").getS());
Assert.assertEquals("Book 103 Update", newImage.get("Title").getS());
} finally {
camelctx.stop();
}
} finally {
DynamoDBUtils.deleteTable(ddbClient, tableName);
}
} finally {
DynamoDBUtils.assertNoStaleTables(ddbClient, "after");
}
}
use of org.apache.camel.PollingConsumer in project wildfly-camel by wildfly-extras.
the class ActiveMQIntegrationTest 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;
}
};
context.bind("messageConverter", converter);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
fromF("activemq:queue:%s?connectionFactory=java:/ActiveMQConnectionFactory&messageConverter=#messageConverter", QUEUE_NAME).transform(simple("Hello ${body.getText()}")).to("seda:end");
}
});
PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
pollingConsumer.start();
camelctx.start();
try {
ConnectionFactory connectionFactory = lookupConnectionFactory();
Connection con = connectionFactory.createConnection();
try {
sendMessage(con, "Kermit");
String result = pollingConsumer.receive(3000).getIn().getBody(String.class);
Assert.assertEquals("Hello Kermit Modified", result);
} finally {
con.close();
}
} finally {
camelctx.stop();
context.unbind("messageConverter");
}
}
use of org.apache.camel.PollingConsumer in project wildfly-camel by wildfly-extras.
the class AhcWSIntegrationTest method testAsyncWsRoute.
@Test
public void testAsyncWsRoute() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("ahc-ws:" + WEBSOCKET_ENDPOINT);
from("ahc-ws:" + WEBSOCKET_ENDPOINT).to("seda:end");
}
});
PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
consumer.start();
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
producer.sendBody("direct:start", "Kermit");
Exchange exchange = consumer.receive(1000);
Assert.assertEquals("Hello Kermit", exchange.getIn().getBody(String.class));
} finally {
camelctx.stop();
}
}
use of org.apache.camel.PollingConsumer in project wildfly-camel by wildfly-extras.
the class AtomIntegrationTest method testConsumeAtomFeed.
@Test
public void testConsumeAtomFeed() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("atom://http://localhost:8080/atom-test/atom/feed?splitEntries=true").to("seda:end");
}
});
PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
pollingConsumer.start();
camelctx.start();
try {
Entry result = pollingConsumer.receive(5000).getIn().getBody(Entry.class);
Assert.assertEquals(FeedConstants.ENTRY_TITLE, result.getTitle());
Assert.assertEquals(FeedConstants.ENTRY_CONTENT, result.getContent());
} finally {
camelctx.stop();
}
}
Aggregations