use of org.apache.camel.management.event.ExchangeSentEvent in project camel by apache.
the class MyLoggingSentEventNotifer method notify.
public void notify(EventObject event) throws Exception {
if (event instanceof ExchangeSentEvent) {
ExchangeSentEvent sent = (ExchangeSentEvent) event;
log.info("Took " + sent.getTimeTaken() + " millis to send to: " + sent.getEndpoint());
}
}
use of org.apache.camel.management.event.ExchangeSentEvent in project camel by apache.
the class AsyncEndpointEventNotifierSendingTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
DefaultCamelContext context = new DefaultCamelContext(createRegistry());
context.getManagementStrategy().addEventNotifier(new EventNotifierSupport() {
public void notify(EventObject event) throws Exception {
events.add(event);
}
public boolean isEnabled(EventObject event) {
return event instanceof ExchangeSendingEvent || event instanceof ExchangeSentEvent;
}
@Override
protected void doStart() throws Exception {
}
@Override
protected void doStop() throws Exception {
}
});
return context;
}
use of org.apache.camel.management.event.ExchangeSentEvent in project camel by apache.
the class EventNotifierFailureHandledEventsTest method testExchangeDoTryDoCatch.
public void testExchangeDoTryDoCatch() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").doTry().throwException(new IllegalArgumentException("Damn")).doCatch(IllegalArgumentException.class).to("mock:dead").end();
}
});
context.start();
getMockEndpoint("mock:dead").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
assertEquals(12, events.size());
assertIsInstanceOf(CamelContextStartingEvent.class, events.get(0));
assertIsInstanceOf(RouteAddedEvent.class, events.get(1));
assertIsInstanceOf(RouteStartedEvent.class, events.get(2));
assertIsInstanceOf(CamelContextStartedEvent.class, events.get(3));
assertIsInstanceOf(ExchangeSendingEvent.class, events.get(4));
assertIsInstanceOf(ExchangeCreatedEvent.class, events.get(5));
ExchangeFailureHandlingEvent e0 = assertIsInstanceOf(ExchangeFailureHandlingEvent.class, events.get(6));
assertEquals("should NOT be DLC", false, e0.isDeadLetterChannel());
assertIsInstanceOf(ExchangeSendingEvent.class, events.get(7));
assertIsInstanceOf(ExchangeSentEvent.class, events.get(8));
ExchangeFailureHandledEvent e = assertIsInstanceOf(ExchangeFailureHandledEvent.class, events.get(9));
assertEquals("should NOT be DLC", false, e.isDeadLetterChannel());
assertFalse("should not be marked as failure handled as it was continued instead", e.isHandled());
assertTrue("should be continued", e.isContinued());
// onException will handle the exception
assertIsInstanceOf(ExchangeCompletedEvent.class, events.get(10));
// and the last event should be the direct:start
assertIsInstanceOf(ExchangeSentEvent.class, events.get(11));
ExchangeSentEvent sent = (ExchangeSentEvent) events.get(11);
assertEquals("direct://start", sent.getEndpoint().getEndpointUri());
}
use of org.apache.camel.management.event.ExchangeSentEvent in project camel by apache.
the class EventNotifierExchangeSentTest method testExchangeSentRecipient.
public void testExchangeSentRecipient() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBodyAndHeader("direct:foo", "Hello World", "foo", "direct:cool,direct:start");
assertMockEndpointsSatisfied();
// give it time to complete
Thread.sleep(200);
assertEquals(12, events.size());
ExchangeSendingEvent e0 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(0));
ExchangeSendingEvent e1 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(1));
ExchangeSentEvent e2 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(2));
ExchangeSendingEvent e3 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(3));
ExchangeSendingEvent e4 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(4));
ExchangeSentEvent e5 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(5));
ExchangeSendingEvent e6 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(6));
ExchangeSentEvent e7 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(7));
ExchangeSendingEvent e8 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(8));
ExchangeSentEvent e9 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(9));
ExchangeSentEvent e10 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(10));
ExchangeSentEvent e11 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(11));
assertEquals("direct://foo", e0.getEndpoint().getEndpointUri());
assertEquals("direct://cool", e1.getEndpoint().getEndpointUri());
assertEquals("direct://cool", e2.getEndpoint().getEndpointUri());
assertEquals("direct://start", e3.getEndpoint().getEndpointUri());
assertEquals("log://foo", e4.getEndpoint().getEndpointUri());
assertEquals("log://foo", e5.getEndpoint().getEndpointUri());
assertEquals("direct://bar", e6.getEndpoint().getEndpointUri());
assertEquals("direct://bar", e7.getEndpoint().getEndpointUri());
assertEquals("mock://result", e8.getEndpoint().getEndpointUri());
assertEquals("mock://result", e9.getEndpoint().getEndpointUri());
assertEquals("direct://start", e10.getEndpoint().getEndpointUri());
assertEquals("direct://foo", e11.getEndpoint().getEndpointUri());
}
use of org.apache.camel.management.event.ExchangeSentEvent in project camel by apache.
the class EventNotifierExchangeSentTest method testExchangeWireTap.
public void testExchangeWireTap() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:tap", "Hello World");
assertMockEndpointsSatisfied();
// give it time to complete
Thread.sleep(200);
assertEquals(6, events.size());
// we should find log:foo which we tapped
// which runs async so they can be in random order
boolean found = false;
boolean found2 = false;
for (EventObject event : events) {
if (event instanceof ExchangeSendingEvent) {
ExchangeSendingEvent sending = (ExchangeSendingEvent) event;
String uri = sending.getEndpoint().getEndpointUri();
if ("log://foo".equals(uri)) {
found = true;
}
} else if (event instanceof ExchangeSentEvent) {
ExchangeSentEvent sent = (ExchangeSentEvent) event;
String uri = sent.getEndpoint().getEndpointUri();
if ("log://foo".equals(uri)) {
found2 = true;
}
}
}
assertTrue("We should find log:foo being wire tapped", found);
assertTrue("We should find log:foo being wire tapped", found2);
}
Aggregations