Java 类org.apache.camel.management.event.ExchangeSendingEvent 实例源码

项目:Camel    文件:AsyncEndpointEventNotifierSendingTest.java   
public void testAsyncEndpointEventNotifier() throws Exception {
    getMockEndpoint("mock:before").expectedBodiesReceived("Hello Camel");
    getMockEndpoint("mock:result").expectedBodiesReceived("Bye Camel");

    String reply = template.requestBody("direct:start", "Hello Camel", String.class);
    assertEquals("Bye Camel", reply);

    assertMockEndpointsSatisfied();

    assertEquals(8, events.size());

    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(0));
    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(1));
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(2));
    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(3));
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(4));
    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(5));
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(6));
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(7));
}
项目:Camel    文件:MultiContextEventNotifierTest.java   
@Test
@InSequence(2)
public void sendMessageToDefaultCamelContextInbound(List<Class> events) throws InterruptedException {
    defaultOutbound.expectedMessageCount(1);
    defaultOutbound.expectedBodiesReceived("test-default");
    defaultOutbound.message(0).exchange().matches(fromCamelContext("camel-cdi"));

    defaultInbound.sendBody("test-default");

    assertIsSatisfied(2L, TimeUnit.SECONDS, defaultOutbound);

    assertThat("Events fired are incorrect", events,
        contains(
            CamelContextStartingEvent.class,
            CamelContextStartedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeCreatedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeSentEvent.class,
            ExchangeCompletedEvent.class,
            ExchangeSentEvent.class));
}
项目:Camel    文件:MultiContextEventNotifierTest.java   
@Test
@InSequence(3)
public void sendMessageToFirstCamelContextInbound(@ContextName("first") List<Class> events) throws InterruptedException {
    firstOutbound.expectedMessageCount(1);
    firstOutbound.expectedBodiesReceived("test-first");
    firstOutbound.expectedHeaderReceived("context", "first");
    firstOutbound.message(0).exchange().matches(fromCamelContext("first"));

    firstInbound.sendBody("test-first");

    assertIsSatisfied(2L, TimeUnit.SECONDS, firstOutbound);

    assertThat("Events fired are incorrect", events,
        contains(
            CamelContextStartingEvent.class,
            CamelContextStartedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeCreatedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeSentEvent.class,
            ExchangeCompletedEvent.class,
            ExchangeSentEvent.class));
}
项目:Camel    文件:MultiContextEventNotifierTest.java   
@Test
@InSequence(4)
public void sendMessageToSecondCamelContextInbound(@ContextName("second") List<Class> events) throws InterruptedException {
    secondOutbound.expectedMessageCount(1);
    secondOutbound.expectedBodiesReceived("test-second");
    secondOutbound.expectedHeaderReceived("context", "second");
    secondOutbound.message(0).exchange().matches(fromCamelContext("second"));

    secondInbound.sendBody("test-second");

    assertIsSatisfied(2L, TimeUnit.SECONDS, secondOutbound);

    assertThat("Events fired are incorrect", events,
        contains(
            CamelContextStartingEvent.class,
            CamelContextStartedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeCreatedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeSentEvent.class,
            ExchangeCompletedEvent.class,
            ExchangeSentEvent.class));
}
项目:Camel    文件:CamelEventNotifierTest.java   
@Test
@InSequence(2)
public void sendMessageToInbound(List<Class> events) throws InterruptedException {
    outbound.expectedMessageCount(1);
    outbound.expectedBodiesReceived("test");

    inbound.sendBody("test");

    assertIsSatisfied(2L, TimeUnit.SECONDS, outbound);

    assertThat("Events fired are incorrect!", events,
        contains(
            CamelContextStartingEvent.class,
            CamelContextStartedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeCreatedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeSentEvent.class,
            ExchangeCompletedEvent.class,
            ExchangeSentEvent.class));
}
项目:Camel    文件:CamelEventNotifierTest.java   
@Test
@InSequence(3)
public void stopCamelContext(CamelContext context, List<Class> events) throws Exception {
    context.stop();

    assertThat("Events fired are incorrect!", events,
        contains(
            CamelContextStartingEvent.class,
            CamelContextStartedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeCreatedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeSentEvent.class,
            ExchangeCompletedEvent.class,
            ExchangeSentEvent.class,
            CamelContextStoppingEvent.class,
            CamelContextStoppedEvent.class));
}
项目:cleverbus    文件:RequestSendingEventNotifier.java   
@Override
protected void doNotify(ExchangeSendingEvent event) throws Exception {
    String endpointUri = event.getEndpoint().getEndpointUri();

    if (filter(endpointUri, endpointFilterPattern)) {
        Message msg = event.getExchange().getIn().getHeader(AsynchConstants.MSG_HEADER, Message.class);

        // create request a transforms data to string to store
        String reqBody = transformBody(((Exchange) event.getSource()).getIn());
        String joinId = createResponseJoinId(event.getExchange());

        Request req = Request.createRequest(endpointUri, joinId, reqBody, msg);

        try {
            // save request
            requestResponseService.insertRequest(req);

            // add to exchange for later use when response arrives
            event.getExchange().getIn().setHeader(SAVE_REQ_HEADER, req);
        } catch (Exception ex) {
            Log.error("Request didn't saved.", ex);
        }
    }
}
项目:camel-cdi    文件:MultiContextEventNotifierTest.java   
@Test
@InSequence(2)
public void sendMessageToDefaultCamelContextInbound(@Named("defaultContext") List<Class> events) throws InterruptedException {
    defaultOutbound.expectedMessageCount(1);
    defaultOutbound.expectedBodiesReceived("test-default");
    defaultOutbound.message(0).exchange().matches(fromCamelContext("camel-cdi"));

    defaultInbound.sendBody("test-default");

    assertIsSatisfied(2L, TimeUnit.SECONDS, defaultOutbound);

    assertThat("Events fired are incorrect", events,
        contains(
            CamelContextStartingEvent.class,
            CamelContextStartedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeCreatedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeSentEvent.class,
            ExchangeCompletedEvent.class,
            ExchangeSentEvent.class));
}
项目:camel-cdi    文件:MultiContextEventNotifierTest.java   
@Test
@InSequence(3)
public void sendMessageToFirstCamelContextInbound(@ContextName("first") List<Class> events) throws InterruptedException {
    firstOutbound.expectedMessageCount(1);
    firstOutbound.expectedBodiesReceived("test-first");
    firstOutbound.expectedHeaderReceived("context", "first");
    firstOutbound.message(0).exchange().matches(fromCamelContext("first"));

    firstInbound.sendBody("test-first");

    assertIsSatisfied(2L, TimeUnit.SECONDS, firstOutbound);

    assertThat("Events fired are incorrect", events,
        contains(
            CamelContextStartingEvent.class,
            CamelContextStartedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeCreatedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeSentEvent.class,
            ExchangeCompletedEvent.class,
            ExchangeSentEvent.class));
}
项目:camel-cdi    文件:MultiContextEventNotifierTest.java   
@Test
@InSequence(4)
public void sendMessageToSecondCamelContextInbound(@ContextName("second") List<Class> events) throws InterruptedException {
    secondOutbound.expectedMessageCount(1);
    secondOutbound.expectedBodiesReceived("test-second");
    secondOutbound.expectedHeaderReceived("context", "second");
    secondOutbound.message(0).exchange().matches(fromCamelContext("second"));

    secondInbound.sendBody("test-second");

    assertIsSatisfied(2L, TimeUnit.SECONDS, secondOutbound);

    assertThat("Events fired are incorrect", events,
        contains(
            CamelContextStartingEvent.class,
            CamelContextStartedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeCreatedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeSentEvent.class,
            ExchangeCompletedEvent.class,
            ExchangeSentEvent.class));
}
项目:camel-cdi    文件:CamelEventNotifierTest.java   
@Test
@InSequence(2)
public void sendMessageToInbound(List<Class> events) throws InterruptedException {
    outbound.expectedMessageCount(1);
    outbound.expectedBodiesReceived("test");

    inbound.sendBody("test");

    assertIsSatisfied(2L, TimeUnit.SECONDS, outbound);

    assertThat("Events fired are incorrect!", events,
        contains(
            CamelContextStartingEvent.class,
            CamelContextStartedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeCreatedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeSentEvent.class,
            ExchangeCompletedEvent.class,
            ExchangeSentEvent.class));
}
项目:camel-cdi    文件:CamelEventNotifierTest.java   
@Test
@InSequence(3)
public void stopCamelContext(CamelContext context, List<Class> events) throws Exception {
    context.stop();

    assertThat("Events fired are incorrect!", events,
        contains(
            CamelContextStartingEvent.class,
            CamelContextStartedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeCreatedEvent.class,
            ExchangeSendingEvent.class,
            ExchangeSentEvent.class,
            ExchangeCompletedEvent.class,
            ExchangeSentEvent.class,
            CamelContextStoppingEvent.class,
            CamelContextStoppedEvent.class));
}
项目:Camel    文件:DefaultRuntimeEndpointRegistry.java   
@Override
public boolean isEnabled(EventObject event) {
    return enabled && event instanceof ExchangeCreatedEvent
            || event instanceof ExchangeSendingEvent
            || event instanceof RouteAddedEvent
            || event instanceof RouteRemovedEvent;
}
项目:Camel    文件:RoutingSlipEventNotifierTest.java   
@Override
public void notify(EventObject event) throws Exception {
    if (event instanceof ExchangeSendingEvent) {
        sending++;
    } else {
        sent++;
    }
}
项目:Camel    文件:EnricherSendEventTest.java   
@Override
public void notify(EventObject event) throws Exception {

    if (event instanceof ExchangeSendingEvent) {
        exchangeSendingEvent.incrementAndGet();
    } else if (event instanceof ExchangeSentEvent) {
        exchangeSentEvent.incrementAndGet();
    }
}
项目:Camel    文件:EventNotifierEventsTest.java   
public void testExchangeFailed() throws Exception {
    try {
        template.sendBody("direct:fail", "Hello World");
        fail("Should have thrown an exception");
    } catch (Exception e) {
        // expected
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
    }

    assertEquals(10, events.size());
    assertIsInstanceOf(CamelContextStartingEvent.class, events.get(0));
    assertIsInstanceOf(RouteAddedEvent.class, events.get(1));
    assertIsInstanceOf(RouteAddedEvent.class, events.get(2));
    assertIsInstanceOf(RouteStartedEvent.class, events.get(3));
    assertIsInstanceOf(RouteStartedEvent.class, events.get(4));
    assertIsInstanceOf(CamelContextStartedEvent.class, events.get(5));
    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(6));
    assertIsInstanceOf(ExchangeCreatedEvent.class, events.get(7));
    assertIsInstanceOf(ExchangeFailedEvent.class, events.get(8));
    // this is the sent using the produce template to start the test
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(9));

    context.stop();

    assertEquals(16, events.size());
    assertIsInstanceOf(CamelContextStoppingEvent.class, events.get(10));
    assertIsInstanceOf(RouteStoppedEvent.class, events.get(11));
    assertIsInstanceOf(RouteRemovedEvent.class, events.get(12));
    assertIsInstanceOf(RouteStoppedEvent.class, events.get(13));
    assertIsInstanceOf(RouteRemovedEvent.class, events.get(14));
    assertIsInstanceOf(CamelContextStoppedEvent.class, events.get(15));
}
项目:Camel    文件:EventNotifierExchangeSentTest.java   
public void testExchangeSent() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(1);

    template.sendBody("direct:start", "Hello World");

    assertMockEndpointsSatisfied();

    assertEquals(8, 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));
    ExchangeSentEvent e4 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(4));
    ExchangeSendingEvent e5 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(5));
    ExchangeSentEvent e6 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(6));
    ExchangeSentEvent e7 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(7));

    assertEquals("direct://start", e0.getEndpoint().getEndpointUri());

    assertEquals("log://foo", e1.getEndpoint().getEndpointUri());
    assertEquals("log://foo", e2.getEndpoint().getEndpointUri());

    assertEquals("direct://bar", e3.getEndpoint().getEndpointUri());
    assertEquals("direct://bar", e4.getEndpoint().getEndpointUri());
    long time = e4.getTimeTaken();
    assertTrue("Should take about 0.5 sec, was: " + time, time > 400);

    assertEquals("mock://result", e5.getEndpoint().getEndpointUri());
    assertEquals("mock://result", e6.getEndpoint().getEndpointUri());

    assertEquals("direct://start", e7.getEndpoint().getEndpointUri());
    time = e7.getTimeTaken();
    assertTrue("Should take about 0.5 sec, was: " + time, time > 400);
}
项目:Camel    文件:EventNotifierExchangeSentTest.java   
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());
}
项目:Camel    文件:EventNotifierRedeliveryEventsTest.java   
public void testExchangeRedeliverySync() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            errorHandler(deadLetterChannel("mock:dead").maximumRedeliveries(4).redeliveryDelay(0));

            from("direct:start").throwException(new IllegalArgumentException("Damn"));
        }
    });
    context.start();

    getMockEndpoint("mock:dead").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    assertTrue(oneExchangeDone.matchesMockWaitTime());

    assertEquals(12, events.size());

    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(0));
    assertIsInstanceOf(ExchangeCreatedEvent.class, events.get(1));
    ExchangeRedeliveryEvent e = assertIsInstanceOf(ExchangeRedeliveryEvent.class, events.get(2));
    assertEquals(1, e.getAttempt());
    e = assertIsInstanceOf(ExchangeRedeliveryEvent.class, events.get(3));
    assertEquals(2, e.getAttempt());
    e = assertIsInstanceOf(ExchangeRedeliveryEvent.class, events.get(4));
    assertEquals(3, e.getAttempt());
    e = assertIsInstanceOf(ExchangeRedeliveryEvent.class, events.get(5));
    assertEquals(4, e.getAttempt());
    assertIsInstanceOf(ExchangeFailureHandlingEvent.class, events.get(6));
    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(7));
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(8));
    assertIsInstanceOf(ExchangeFailureHandledEvent.class, events.get(9));
    assertIsInstanceOf(ExchangeCompletedEvent.class, events.get(10));
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(11));
}
项目:Camel    文件:EventNotifierRedeliveryEventsTest.java   
public void testExchangeRedeliveryAsync() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            errorHandler(deadLetterChannel("mock:dead").maximumRedeliveries(4).asyncDelayedRedelivery().redeliveryDelay(10));

            from("direct:start").throwException(new IllegalArgumentException("Damn"));
        }
    });
    context.start();

    getMockEndpoint("mock:dead").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    assertTrue(oneExchangeDone.matchesMockWaitTime());

    assertEquals(12, events.size());

    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(0));
    assertIsInstanceOf(ExchangeCreatedEvent.class, events.get(1));
    ExchangeRedeliveryEvent e = assertIsInstanceOf(ExchangeRedeliveryEvent.class, events.get(2));
    assertEquals(1, e.getAttempt());
    e = assertIsInstanceOf(ExchangeRedeliveryEvent.class, events.get(3));
    assertEquals(2, e.getAttempt());
    e = assertIsInstanceOf(ExchangeRedeliveryEvent.class, events.get(4));
    assertEquals(3, e.getAttempt());
    e = assertIsInstanceOf(ExchangeRedeliveryEvent.class, events.get(5));
    assertEquals(4, e.getAttempt());

    // since its async the ordering of the rest can be different depending per OS and timing
}
项目:Camel    文件:EventNotifierExchangeSentParallelTest.java   
public void testExchangeSentRecipient() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(1);

    template.sendBodyAndHeader("direct:foo", "Hello World", "foo", "direct:cool,direct:start");

    // wait for the message to be fully done using oneExchangeDone
    assertMockEndpointsSatisfied();
    assertTrue(oneExchangeDone.matchesMockWaitTime());

    // stop Camel to let all the events complete
    context.stop();

    assertTrue("Should be 11 or more, was: " + events.size(), events.size() >= 11);

    // we run parallel so just assert we got 6 sending and 6 sent events
    int sent = 0;
    int sending = 0;
    for (EventObject event : events) {
        if (event instanceof ExchangeSendingEvent) {
            sending++;
        } else {
            sent++;
        }
    }

    assertTrue("There should be 5 or more, was " + sending, sending >= 5);
    assertTrue("There should be 5 or more, was " + sent, sent >= 5);
}
项目:Camel    文件:MultipleEventNotifierEventsTest.java   
public void testExchangeFailed() throws Exception {
    try {
        template.sendBody("direct:fail", "Hello World");
        fail("Should have thrown an exception");
    } catch (Exception e) {
        // expected
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
    }

    assertEquals(10, events.size());
    assertIsInstanceOf(CamelContextStartingEvent.class, events.get(0));
    assertIsInstanceOf(RouteAddedEvent.class, events.get(1));
    assertIsInstanceOf(RouteAddedEvent.class, events.get(2));
    assertIsInstanceOf(RouteStartedEvent.class, events.get(3));
    assertIsInstanceOf(RouteStartedEvent.class, events.get(4));
    assertIsInstanceOf(CamelContextStartedEvent.class, events.get(5));
    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(6));
    assertIsInstanceOf(ExchangeCreatedEvent.class, events.get(7));
    assertIsInstanceOf(ExchangeFailedEvent.class, events.get(8));
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(9));

    assertEquals(4, events2.size());

    context.stop();
    assertIsInstanceOf(ExchangeSendingEvent.class, events2.get(0));
    assertIsInstanceOf(ExchangeCreatedEvent.class, events2.get(1));
    assertIsInstanceOf(ExchangeFailedEvent.class, events2.get(2));
    assertIsInstanceOf(ExchangeSentEvent.class, events2.get(3));

    assertEquals(16, events.size());
    assertIsInstanceOf(CamelContextStoppingEvent.class, events.get(10));
    assertIsInstanceOf(RouteStoppedEvent.class, events.get(11));
    assertIsInstanceOf(RouteRemovedEvent.class, events.get(12));
    assertIsInstanceOf(RouteStoppedEvent.class, events.get(13));
    assertIsInstanceOf(RouteRemovedEvent.class, events.get(14));
    assertIsInstanceOf(CamelContextStoppedEvent.class, events.get(15));

    assertEquals(4, events2.size());
}
项目:Camel    文件:ZipkinTracer.java   
private void clientRequest(Brave brave, String serviceName, ExchangeSendingEvent event) {
    ClientSpanThreadBinder clientBinder = brave.clientSpanThreadBinder();
    ServerSpanThreadBinder serverBinder = brave.serverSpanThreadBinder();

    // reuse existing span if we do multiple requests from the same
    ZipkinState state = event.getExchange().getProperty(ZipkinState.KEY, ZipkinState.class);
    if (state == null) {
        state = new ZipkinState();
        event.getExchange().setProperty(ZipkinState.KEY, state);
    }
    // if we started from a server span then lets reuse that when we call a downstream service
    ServerSpan last = state.peekServerSpan();
    if (last != null) {
        serverBinder.setCurrentSpan(last);
    }

    brave.clientRequestInterceptor().handle(new ZipkinClientRequestAdapter(this, serviceName, event.getExchange(), event.getEndpoint()));

    // store span after request
    Span span = clientBinder.getCurrentClientSpan();
    state.pushClientSpan(span);
    // and reset binder
    clientBinder.setCurrentSpan(null);
    serverBinder.setCurrentSpan(null);

    if (span != null && LOG.isDebugEnabled()) {
        String traceId = "" + span.getTrace_id();
        String spanId = "" + span.getId();
        String parentId = span.getParent_id() != null ? "" + span.getParent_id() : null;
        if (LOG.isDebugEnabled()) {
            if (parentId != null) {
                LOG.debug(String.format("clientRequest [service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId));
            } else {
                LOG.debug(String.format("clientRequest [service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId));
            }
        }
    }
}
项目:Camel    文件:ZipkinTracer.java   
@Override
public boolean isEnabled(EventObject event) {
    return event instanceof ExchangeSendingEvent
            || event instanceof ExchangeSentEvent
            || event instanceof ExchangeCreatedEvent
            || event instanceof ExchangeCompletedEvent
            || event instanceof ExchangeFailedEvent;
}
项目:Camel    文件:RoutingSlipEventNotifierTest.java   
@Override
public boolean isEnabled(EventObject event) {
    return event instanceof ExchangeSendingEvent || event instanceof ExchangeSentEvent;
}
项目:Camel    文件:EventNotifierFailureHandledEventsTest.java   
public void testExchangeDeadLetterChannel() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            errorHandler(deadLetterChannel("mock:dead"));

            from("direct:start").throwException(new IllegalArgumentException("Damn"));
        }
    });
    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 be DLC", true, e0.isDeadLetterChannel());
    assertEquals("mock://dead", e0.getDeadLetterUri());

    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(7));
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(8));

    ExchangeFailureHandledEvent e = assertIsInstanceOf(ExchangeFailureHandledEvent.class, events.get(9));
    assertEquals("should be DLC", true, e.isDeadLetterChannel());
    assertTrue("should be marked as failure handled", e.isHandled());
    assertFalse("should not be continued", e.isContinued());
    SendProcessor send = assertIsInstanceOf(SendProcessor.class, e.getFailureHandler());
    assertEquals("mock://dead", send.getDestination().getEndpointUri());
    assertEquals("mock://dead", e.getDeadLetterUri());

    // dead letter channel will mark the exchange as completed
    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());
}
项目:Camel    文件:EventNotifierFailureHandledEventsTest.java   
public void testExchangeOnException() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            onException(IllegalArgumentException.class).handled(true).to("mock:dead");

            from("direct:start").throwException(new IllegalArgumentException("Damn"));
        }
    });
    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());
    assertTrue("should be marked as failure handled", e.isHandled());
    assertFalse("should not 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());
}
项目:Camel    文件:EventNotifierFailureHandledEventsTest.java   
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());
}
项目:Camel    文件:MultipleEventNotifierEventsTest.java   
public void testExchangeDone() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(1);

    template.sendBody("direct:start", "Hello World");

    assertMockEndpointsSatisfied();

    assertEquals(14, events.size());
    assertIsInstanceOf(CamelContextStartingEvent.class, events.get(0));
    assertIsInstanceOf(RouteAddedEvent.class, events.get(1));
    assertIsInstanceOf(RouteAddedEvent.class, events.get(2));
    assertIsInstanceOf(RouteStartedEvent.class, events.get(3));
    assertIsInstanceOf(RouteStartedEvent.class, events.get(4));
    assertIsInstanceOf(CamelContextStartedEvent.class, events.get(5));
    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(6));
    assertIsInstanceOf(ExchangeCreatedEvent.class, events.get(7));
    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(8));
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(9));
    assertIsInstanceOf(ExchangeSendingEvent.class, events.get(10));
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(11));
    assertIsInstanceOf(ExchangeCompletedEvent.class, events.get(12));
    assertIsInstanceOf(ExchangeSentEvent.class, events.get(13));

    assertEquals(8, events2.size());
    assertIsInstanceOf(ExchangeSendingEvent.class, events2.get(0));
    assertIsInstanceOf(ExchangeCreatedEvent.class, events2.get(1));
    assertIsInstanceOf(ExchangeSendingEvent.class, events2.get(2));
    assertIsInstanceOf(ExchangeSentEvent.class, events2.get(3));
    assertIsInstanceOf(ExchangeSendingEvent.class, events2.get(4));
    assertIsInstanceOf(ExchangeSentEvent.class, events2.get(5));
    assertIsInstanceOf(ExchangeCompletedEvent.class, events2.get(6));
    assertIsInstanceOf(ExchangeSentEvent.class, events2.get(7));

    context.stop();

    assertEquals(20, events.size());
    assertIsInstanceOf(CamelContextStoppingEvent.class, events.get(14));
    assertIsInstanceOf(RouteStoppedEvent.class, events.get(15));
    assertIsInstanceOf(RouteRemovedEvent.class, events.get(16));
    assertIsInstanceOf(RouteStoppedEvent.class, events.get(17));
    assertIsInstanceOf(RouteRemovedEvent.class, events.get(18));
    assertIsInstanceOf(CamelContextStoppedEvent.class, events.get(19));

    assertEquals(8, events2.size());
}
项目:Camel    文件:CamelEventEndpointTest.java   
@Test
public void camelAllEvents(@Uri("mock:events") MockEndpoint events) {
    assertThat("Events fired are incorrect!", events.getExchanges(),
        // We cannot rely on the delivery order of the camel context started event being fired and observed by both CDI event endpoints
        either(
            contains(
                // Started route: route1
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(RouteStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started route: route2
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(RouteStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started CamelContext: camel-cdi
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(CamelContextStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started CamelContext: camel-cdi (for CdiEventEndpoint<CamelContextStartedEvent> started)
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class)))
        )).or(
            contains(
                // Started route: route1
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(RouteStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started route: route2
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(RouteStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started CamelContext: camel-cdi (for CdiEventEndpoint<CamelContextStartedEvent> started)
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started CamelContext: camel-cdi
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(CamelContextStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class)))
            )
        )
    );
}
项目:camel-cdi    文件:CamelEventEndpointTest.java   
@Test
public void camelAllEvents(@Uri("mock:events") MockEndpoint events) {
    assertThat("Events fired are incorrect!", events.getExchanges(),
        // We cannot rely on the delivery order of the camel context started event being fired and observed by both CDI event endpoints
        either(
            contains(
                // Started route: route1
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(RouteStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started route: route2
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(RouteStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started CamelContext: camel-cdi
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(CamelContextStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started CamelContext: camel-cdi (for CdiEventEndpoint<CamelContextStartedEvent> started)
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class)))
        )).or(
            contains(
                // Started route: route1
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(RouteStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started route: route2
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(RouteStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started CamelContext: camel-cdi (for CdiEventEndpoint<CamelContextStartedEvent> started)
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class))),
                // Started CamelContext: camel-cdi
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCreatedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSendingEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(CamelContextStartedEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeSentEvent.class))),
                hasProperty("in", hasProperty("body", instanceOf(ExchangeCompletedEvent.class)))
            )
        )
    );
}