use of org.apache.camel.impl.ThrottlingInflightRoutePolicy in project camel by apache.
the class BackpressurePublisherRoutePolicyTest method testThatBackpressureCausesTemporaryRouteStop.
@Test
public void testThatBackpressureCausesTemporaryRouteStop() throws Exception {
CountDownLatch generationLatch = new CountDownLatch(25);
new RouteBuilder() {
@Override
public void configure() throws Exception {
ThrottlingInflightRoutePolicy policy = new ThrottlingInflightRoutePolicy();
policy.setMaxInflightExchanges(10);
policy.setScope(ThrottlingInflightRoutePolicy.ThrottlingScope.Route);
policy.setResumePercentOfMax(70);
policy.setLoggingLevel(LoggingLevel.INFO);
from("timer:tick?period=50&repeatCount=35").id("policy-route").routePolicy(policy).process(x -> generationLatch.countDown()).to("reactive-streams:pub");
}
}.addRoutesToCamelContext(context);
CountDownLatch receptionLatch = new CountDownLatch(35);
Publisher<Exchange> pub = CamelReactiveStreams.get(context()).fromStream("pub", Exchange.class);
TestSubscriber<Exchange> subscriber = new TestSubscriber<Exchange>() {
@Override
public void onNext(Exchange o) {
super.onNext(o);
receptionLatch.countDown();
}
};
subscriber.setInitiallyRequested(10);
pub.subscribe(subscriber);
// Add another (fast) subscription that should not affect the backpressure on the route
Observable.fromPublisher(pub).subscribe();
context.start();
// after 25 messages are generated
generationLatch.await(5, TimeUnit.SECONDS);
// The number of exchanges should be 10 (requested by the subscriber), so 35-10=25
assertEquals(25, receptionLatch.getCount());
// fire a delayed request from the subscriber (required by camel core)
subscriber.request(1);
Thread.sleep(250);
StatefulService service = (StatefulService) context().getRoute("policy-route").getConsumer();
// ensure the route is stopped or suspended
assertTrue(service.isStopped() || service.isSuspended());
// request all the remaining exchanges
subscriber.request(24);
assertTrue(receptionLatch.await(5, TimeUnit.SECONDS));
// The reception latch has gone to 0
}
use of org.apache.camel.impl.ThrottlingInflightRoutePolicy in project camel by apache.
the class JmsThrottlingInflightRoutePolicyTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
ThrottlingInflightRoutePolicy policy = new ThrottlingInflightRoutePolicy();
policy.setMaxInflightExchanges(10);
policy.setResumePercentOfMax(50);
policy.setScope(ThrottlingInflightRoutePolicy.ThrottlingScope.Route);
from("activemq:queue:foo?concurrentConsumers=20").routePolicy(policy).delay(100).to("log:foo?groupSize=10").to("mock:result");
}
};
}
Aggregations