Search in sources :

Example 51 with Producer

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());
    }
}
Also used : Producer(org.apache.camel.Producer)

Example 52 with Producer

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;
}
Also used : DeferProducer(org.apache.camel.impl.DeferProducer) Producer(org.apache.camel.Producer) DeferProducer(org.apache.camel.impl.DeferProducer)

Example 53 with 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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Producer(org.apache.camel.Producer) Consumer(org.apache.camel.Consumer)

Example 54 with Producer

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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Producer(org.apache.camel.Producer) Consumer(org.apache.camel.Consumer) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 55 with Producer

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DefaultEndpoint(org.apache.camel.impl.DefaultEndpoint) DefaultProducer(org.apache.camel.impl.DefaultProducer) Producer(org.apache.camel.Producer) Consumer(org.apache.camel.Consumer) DefaultProducer(org.apache.camel.impl.DefaultProducer) ExchangeException(org.apache.camel.ExchangeException)

Aggregations

Producer (org.apache.camel.Producer)198 Endpoint (org.apache.camel.Endpoint)140 Exchange (org.apache.camel.Exchange)138 Test (org.junit.Test)72 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)69 Processor (org.apache.camel.Processor)34 RouteBuilder (org.apache.camel.builder.RouteBuilder)23 Message (org.apache.camel.Message)21 CountDownLatch (java.util.concurrent.CountDownLatch)16 File (java.io.File)12 CamelContext (org.apache.camel.CamelContext)12 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)10 DefaultExchange (org.apache.camel.impl.DefaultExchange)9 Mockito.anyLong (org.mockito.Mockito.anyLong)9 Consumer (org.apache.camel.Consumer)8 FileDataSource (javax.activation.FileDataSource)7 AsyncProcessor (org.apache.camel.AsyncProcessor)7 DataHandler (javax.activation.DataHandler)6 Field (java.lang.reflect.Field)5 ExchangePattern (org.apache.camel.ExchangePattern)5