use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class SjmsBatchConsumerTest method testConsumptionMultipleConsumerEndpoints.
/**
* Checks whether multiple consumer endpoints can operate in parallel.
*/
@Test
public void testConsumptionMultipleConsumerEndpoints() throws Exception {
final int completionTimeout = 2000;
final int completionSize = 5;
final String queueName = getQueueName();
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from("direct:in").split().body().multicast().toF("sjms:%s", queueName + "A").toF("sjms:%s", queueName + "B").end();
fromF("sjms-batch:%s?completionTimeout=%s&completionSize=%s&aggregationStrategy=#testStrategy", queueName + "A", completionTimeout, completionSize).routeId("batchConsumerA").to("mock:outA");
fromF("sjms-batch:%s?completionTimeout=%s&completionSize=%s&aggregationStrategy=#testStrategy", queueName + "B", completionTimeout, completionSize).routeId("batchConsumerB").to("mock:outB");
}
});
context.start();
int messageCount = 5;
assertTrue(messageCount < SjmsBatchEndpoint.DEFAULT_COMPLETION_SIZE);
MockEndpoint mockOutA = getMockEndpoint("mock:outA");
// everything batched together
mockOutA.expectedMessageCount(1);
MockEndpoint mockOutB = getMockEndpoint("mock:outB");
// everything batched together
mockOutB.expectedMessageCount(1);
template.sendBody("direct:in", generateStrings(messageCount));
assertMockEndpointsSatisfied();
assertFirstMessageBodyOfLength(mockOutA, messageCount);
assertFirstMessageBodyOfLength(mockOutB, messageCount);
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class SjmsBatchConsumerTest method testConsumptionCompletionSize.
@Test
public void testConsumptionCompletionSize() throws Exception {
final int completionSize = 5;
// size-based only
final int completionTimeout = -1;
final String queueName = getQueueName();
context.addRoutes(new TransactedSendHarness(queueName));
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
fromF("sjms-batch:%s?completionTimeout=%s&completionSize=%s&aggregationStrategy=#testStrategy", queueName, completionTimeout, completionSize).routeId("batchConsumer").startupOrder(10).log(LoggingLevel.DEBUG, "${body.size}").to("mock:batches");
}
});
context.start();
int messageCount = 100;
MockEndpoint mockBatches = getMockEndpoint("mock:batches");
mockBatches.expectedMessageCount(messageCount / completionSize);
template.sendBody("direct:in", generateStrings(messageCount));
mockBatches.assertIsSatisfied();
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class SjmsBatchConsumerTest method testConsumptionSendEmptyMessageWhenIdle.
@Test
public void testConsumptionSendEmptyMessageWhenIdle() throws Exception {
final int completionInterval = 2000;
// timeout-based only
final int completionSize = -1;
final String queueName = getQueueName();
context.addRoutes(new TransactedSendHarness(queueName));
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
fromF("sjms-batch:%s?completionInterval=%s&completionSize=%s&sendEmptyMessageWhenIdle=true&aggregationStrategy=#testStrategy", queueName, completionInterval, completionSize).routeId("batchConsumer").startupOrder(10).to("mock:batches");
}
});
context.start();
int messageCount = 50;
assertTrue(messageCount < SjmsBatchEndpoint.DEFAULT_COMPLETION_SIZE);
MockEndpoint mockBatches = getMockEndpoint("mock:batches");
// trigger a couple of empty messages
mockBatches.expectedMinimumMessageCount(3);
template.sendBody("direct:in", generateStrings(messageCount));
mockBatches.assertIsSatisfied();
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class SjmsBatchEndpointTest method testConsumerTopic.
@Test(expected = FailedToCreateRouteException.class)
public void testConsumerTopic() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("sjms-batch:topic:in?aggregationStrategy=#aggStrategy").to("mock:out");
}
});
context.start();
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class SjmsBatchEndpointTest method testProducerFailure.
@Test(expected = FailedToCreateRouteException.class)
public void testProducerFailure() throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from("direct:in").to("sjms-batch:testQueue?aggregationStrategy=#unknown");
}
});
context.start();
}
Aggregations