use of org.apache.camel.Producer in project camel by apache.
the class MulticastProcessor method setToEndpoint.
protected static void setToEndpoint(Exchange exchange, Processor processor) {
if (processor instanceof Producer) {
Producer producer = (Producer) processor;
exchange.setProperty(Exchange.TO_ENDPOINT, producer.getEndpoint().getEndpointUri());
}
}
use of org.apache.camel.Producer in project camel by apache.
the class DeferServiceFactory method createProducer.
/**
* Creates the {@link Producer} which is deferred started until {@link org.apache.camel.CamelContext} is being started.
* <p/>
* When the producer is started, it re-lookup the endpoint to capture any changes such as the endpoint has been intercepted.
* This allows the producer to react and send messages to the updated endpoint.
*
* @param endpoint the endpoint
* @return the producer which will be deferred started until {@link org.apache.camel.CamelContext} has been started
* @throws Exception can be thrown if there is an error starting the producer
* @see org.apache.camel.impl.DeferProducer
*/
public static Producer createProducer(Endpoint endpoint) throws Exception {
Producer producer = new DeferProducer(endpoint);
endpoint.getCamelContext().deferStartService(producer, true);
return producer;
}
use of org.apache.camel.Producer in project camel by apache.
the class SedaEndpointTest method testSedaEndpoint.
public void testSedaEndpoint() throws Exception {
SedaEndpoint seda = new SedaEndpoint("seda://foo", context.getComponent("seda"), queue);
assertNotNull(seda);
assertEquals(1000, seda.getSize());
assertSame(queue, seda.getQueue());
assertEquals(1, seda.getConcurrentConsumers());
Producer prod = seda.createProducer();
seda.onStarted((SedaProducer) prod);
assertEquals(1, seda.getProducers().size());
Consumer cons = seda.createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
// do nothing
}
});
seda.onStarted((SedaConsumer) cons);
assertEquals(1, seda.getConsumers().size());
assertEquals(0, seda.getExchanges().size());
}
use of org.apache.camel.Producer in project camel by apache.
the class SedaEndpointTest method testSedaEndpointUnboundedQueue.
public void testSedaEndpointUnboundedQueue() throws Exception {
BlockingQueue<Exchange> unbounded = new LinkedBlockingQueue<Exchange>();
SedaEndpoint seda = new SedaEndpoint("seda://foo", context.getComponent("seda"), unbounded);
assertNotNull(seda);
assertEquals(Integer.MAX_VALUE, seda.getSize());
assertSame(unbounded, seda.getQueue());
assertEquals(1, seda.getConcurrentConsumers());
Producer prod = seda.createProducer();
seda.onStarted((SedaProducer) prod);
assertEquals(1, seda.getProducers().size());
Consumer cons = seda.createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
// do nothing
}
});
seda.onStarted((SedaConsumer) cons);
assertEquals(1, seda.getConsumers().size());
assertEquals(0, seda.getExchanges().size());
}
use of org.apache.camel.Producer in project camel by apache.
the class RetryRouteScopedUntilRecipientListIssueTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
context.addEndpoint("fail", new DefaultEndpoint() {
public Producer createProducer() throws Exception {
return new DefaultProducer(this) {
public void process(Exchange exchange) throws Exception {
exchange.setException(new IllegalArgumentException("Damn"));
}
};
}
public Consumer createConsumer(Processor processor) throws Exception {
return null;
}
@Override
protected String createEndpointUri() {
return "fail";
}
public boolean isSingleton() {
return true;
}
});
context.addEndpoint("not-fail", new DefaultEndpoint() {
public Producer createProducer() throws Exception {
return new DefaultProducer(this) {
public void process(Exchange exchange) throws Exception {
// noop
}
};
}
public Consumer createConsumer(Processor processor) throws Exception {
return null;
}
@Override
protected String createEndpointUri() {
return "not-fail";
}
public boolean isSingleton() {
return true;
}
});
return context;
}
Aggregations