Search in sources :

Example 1 with DirectEndpoint

use of org.apache.camel.component.direct.DirectEndpoint in project camel by apache.

the class SamplingThrottlerTest method sendExchangesThroughDroppingThrottler.

private void sendExchangesThroughDroppingThrottler(List<Exchange> sentExchanges, int messages) throws Exception {
    ProducerTemplate myTemplate = context.createProducerTemplate();
    DirectEndpoint targetEndpoint = resolveMandatoryEndpoint("direct:sample", DirectEndpoint.class);
    for (int i = 0; i < messages; i++) {
        Exchange e = targetEndpoint.createExchange();
        e.getIn().setBody("<message>" + i + "</message>");
        // only send if we are still started
        if (context.getStatus().isStarted()) {
            myTemplate.send(targetEndpoint, e);
            sentExchanges.add(e);
            Thread.sleep(100);
        }
    }
    myTemplate.stop();
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) DirectEndpoint(org.apache.camel.component.direct.DirectEndpoint) DirectEndpoint(org.apache.camel.component.direct.DirectEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Aggregations

Exchange (org.apache.camel.Exchange)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 DirectEndpoint (org.apache.camel.component.direct.DirectEndpoint)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1