FAQ
We have an object passing on the exchange.
We take it aside using wireTap, in order to add persist logic on it,
logging, and more. (that's why we don't use 'log' processor). We do it with
an in-memory queue (seda), with a bean in its other end.

*Problem*: As the object is passed by its pointer, it is the same object on
the original exchange and on the wireTapped exchange. This causes a
situation in which until the exchange is processed by the bean at the other
side of the wireTap, a property on our object is changed, and we persist a
different state of the object than we expected.

Is there a way to do a deep copy while wireTapping, so that our object is
copied and its state is snapshot?
Is there a better way of achieving what is described above?

thanks
ShlomiJ

--
View this message in context: http://camel.465427.n5.nabble.com/Concurrent-problem-with-message-Body-using-WireTap-tp5502505p5502505.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Search Discussions

  • Claus Ibsen at Feb 21, 2012 at 3:35 pm
    Hi

    You can use the onPrepareRef option. See details at
    http://camel.apache.org/wire-tap

    On Tue, Feb 21, 2012 at 4:26 PM, ShlomiJ wrote:
    We have an object passing on the exchange.
    We take it aside using wireTap, in order to add persist logic on it,
    logging, and more. (that's why we don't use 'log' processor). We do it with
    an in-memory queue (seda), with a bean in its other end.

    *Problem*: As the object is passed by its pointer, it is the same object on
    the original exchange and on the wireTapped exchange. This causes a
    situation in which until the exchange is processed by the bean at the other
    side of the wireTap, a property on our object is changed, and we persist a
    different state of the object than we expected.

    Is there a way to do a deep copy while wireTapping, so that our object is
    copied and its state is snapshot?
    Is there a better way of achieving what is described above?

    thanks
    ShlomiJ

    --
    View this message in context: http://camel.465427.n5.nabble.com/Concurrent-problem-with-message-Body-using-WireTap-tp5502505p5502505.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    Twitter: davsclaus, fusenews
    Blog: http://davsclaus.blogspot.com/
    Author of Camel in Action: http://www.manning.com/ibsen/
  • ShlomiJ at Feb 21, 2012 at 3:54 pm
    hi, see what I've found!

    The wireTap receives the *onPrepareRef *property, which "/allows you to do
    any custom logic, such as *deep-cloning* the message payload/".

    Thanks you Camel 2.8.0!

    ShlomiJ

    --
    View this message in context: http://camel.465427.n5.nabble.com/Concurrent-problem-with-message-Body-using-WireTap-tp5502505p5502576.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Ychawla at Jul 7, 2014 at 6:28 pm
    Hi Guys,
    Any hints on writing a processor that will do a deep clone? I am running
    into the same issue. I have a CXF Payload on my Exchange.

    Thanks,
    Yogesh



    --
    View this message in context: http://camel.465427.n5.nabble.com/Concurrent-problem-with-message-Body-using-WireTap-tp5502505p5753471.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Stanisław Kuś at Jul 7, 2014 at 6:44 pm
    Hi,

    this should help U:


    1.
    public class DeepCloningProcessor implements Processor {

    /* (non-Javadoc)
      * @see org.apache.camel.Processor#process(org.apache.camel.Exchange)
      */
    @Override
    public void process(Exchange exchange) throws Exception {

    Cloner cloner = new Cloner();
    StreamCache clone =
      cloner.deepClone(exchange.getIn().getBody(StreamCache.class));
    exchange.getIn().setBody(clone);

    }

    }

    2.
    call wireTap in Route Builder
    ".wireTap("direct:tapped").onPrepare(deepCloner)"

    3.
    Maven:

             <dependency>
          <groupId>uk.com.robust-it</groupId>
                 <artifactId>cloning</artifactId>
                 <version>1.9.0</version>
             </dependency>


    Best regards,

    Stanislaw


    On Mon, Jul 7, 2014 at 8:28 PM, ychawla wrote:

    Hi Guys,
    Any hints on writing a processor that will do a deep clone? I am running
    into the same issue. I have a CXF Payload on my Exchange.

    Thanks,
    Yogesh



    --
    View this message in context:
    http://camel.465427.n5.nabble.com/Concurrent-problem-with-message-Body-using-WireTap-tp5502505p5753471.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Ychawla at Jul 8, 2014 at 4:55 am
    Hi Guys,
    Any hints on writing a processor that will do a deep clone? I am running
    into the same issue.

    Thanks,
    Yogesh



    --
    View this message in context: http://camel.465427.n5.nabble.com/Concurrent-problem-with-message-Body-using-WireTap-tp5502505p5753470.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Jan Matèrne (jhm) at Jul 8, 2014 at 6:14 am
    Use Reflection or easier - one of the existing libraries
    https://code.google.com/p/cloning/
    http://www.genericdeepcopy.com/

    Jan
    -----Ursprüngliche Nachricht-----
    Von: ychawla
    Gesendet: Montag, 7. Juli 2014 20:03
    An: users@camel.apache.org
    Betreff: Re: Concurrent problem with message Body using WireTap

    Hi Guys,
    Any hints on writing a processor that will do a deep clone? I am
    running into the same issue.

    Thanks,
    Yogesh



    --
    View this message in context:
    http://camel.465427.n5.nabble.com/Concurrent-problem-with-message-Body-
    using-WireTap-tp5502505p5753470.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Stanisław Kuś at Jul 8, 2014 at 7:10 am
    Hi,

    in my previous mail U have a complete solution with Reflection-based Deep
    Cloning library.

    Best,
    Stanislaw

    On Tue, Jul 8, 2014 at 8:13 AM, Jan Matèrne (jhm) wrote:

    Use Reflection or easier - one of the existing libraries
    https://code.google.com/p/cloning/
    http://www.genericdeepcopy.com/

    Jan
    -----Ursprüngliche Nachricht-----
    Von: ychawla
    Gesendet: Montag, 7. Juli 2014 20:03
    An: users@camel.apache.org
    Betreff: Re: Concurrent problem with message Body using WireTap

    Hi Guys,
    Any hints on writing a processor that will do a deep clone? I am
    running into the same issue.

    Thanks,
    Yogesh



    --
    View this message in context:
    http://camel.465427.n5.nabble.com/Concurrent-problem-with-message-Body-
    using-WireTap-tp5502505p5753470.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Ychawla at Jul 10, 2014 at 1:39 pm
    Thanks Guys,
    The detailed solution that Stanislaw outlined worked perfectly.

    In ServiceMix, you will need to install the following libraries:

    install -s mvn:uk.com.robust-it/cloning
    install -s mvn:org.objenesis/objenesis/1.4


    Thanks for the assistance!



    --
    View this message in context: http://camel.465427.n5.nabble.com/Concurrent-problem-with-message-Body-using-WireTap-tp5502505p5753648.html
    Sent from the Camel - Users mailing list archive at Nabble.com.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedFeb 21, '12 at 3:29p
activeJul 10, '14 at 1:39p
posts9
users5
websitecamel.apache.org

People

Translate

site design / logo © 2021 Grokbase