camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CAMEL-2795) ProducerCache send() should use the UnitOfWork to wrap the exchange
Date Mon, 07 Jun 2010 11:10:51 GMT

    [ https://issues.apache.org/activemq/browse/CAMEL-2795?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59972#action_59972
] 

Claus Ibsen commented on CAMEL-2795:
------------------------------------

Well what we can do is when creating a *new* Exchange then we can let it be under an unit
of work.

I think this patch is better. Where we let {{target}} be the producer to process the Exchange.
And if its a new Exchange its being wrapped by an {{UnitOfWorkProcessor}} which is the way
you should do it. Its how Camel does it for routes etc.

{code}
    protected Exchange sendExchange(final Endpoint endpoint, ExchangePattern pattern,
                                    final Processor processor, Exchange exchange) throws Exception
{
        return doInProducer(endpoint, exchange, pattern, new ProducerCallback<Exchange>()
{
            public Exchange doInProducer(Producer producer, Exchange exchange, ExchangePattern
pattern) throws Exception {
                // target is the producer executing the exchange
                Processor target = producer;

                if (exchange == null) {
                    exchange = pattern != null ? producer.createExchange(pattern) : producer.createExchange();
                    // if creating new exchange than wrap in unit of work
                    target = new UnitOfWorkProcessor(producer);
                }

                if (processor != null) {
                    // lets populate using the processor callback
                    processor.process(exchange);
                }

                // now lets dispatch
                if (LOG.isDebugEnabled()) {
                    LOG.debug(">>>> " + endpoint + " " + exchange);
                }

                // set property which endpoint we send to
                exchange.setProperty(Exchange.TO_ENDPOINT, endpoint.getEndpointUri());

                // send the exchange using the processor
                StopWatch watch = new StopWatch();
                try {
                    target.process(exchange);
                } finally {
                    // emit event that the exchange was sent to the endpoint
                    long timeTaken = watch.stop();
                    EventHelper.notifyExchangeSent(exchange.getContext(), exchange, endpoint,
timeTaken);
                }
                return exchange;
            }
        });
    }
{code}

> ProducerCache send() should use the UnitOfWork to wrap the exchange
> -------------------------------------------------------------------
>
>                 Key: CAMEL-2795
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2795
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Willem Jiang
>            Assignee: Willem Jiang
>             Fix For: 2.4.0
>
>
> In this way the UnitOfWork of the exchange  which is sent by the DefaultProducerTemplate
can be used rightly.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message