You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Muhammad Ichsan <ic...@gmail.com> on 2010/10/12 13:36:45 UTC
Immutable object
Dear Camel Experts
I have an object which becomes the main message to be transported
across camel routes. So, I don't use String or other simple object.
That's why I have to use converter.
@Converter
public class InternalMessageConverter {
@Converter
public static InputStream toText(InternalMessage iMsg) {
return new ByteArrayInputStream(iMsg.toString().getBytes());
}
}
The problem is at this route:
<route>
....
<wireTap uri="activemq:log.transaction" /><!-- Log the iMessage -->
<choice>
<when>
<simple>${in.header.nextDestination} != null</simple>
<wireTap uri="direct:invokeInBackground" />
</when>
</choice>
</route>
<route>
<from uri="direct:invokeInBackground" />
<to uri="bean:modifier?method=modify" />
<!-- Send to create reversal TX log -->
<wireTap uri="activemq:log.transaction" /><!-- Log the modified iMessage -->
</route>
When I send a message, the log.transaction will have the same messages
which are both modified. I expect that I will have two different
messages inside log.transaction (the unmodified and the modified one).
Because the first wireTap sends the unmodified message to log but the
second one sends the modified message. How to achieve this?
Thanks
--
~The best men are men who benefit to others
http://michsan.web.id 一緒に勉強しましょう!
Yang berkualitas memang beda rasanya!
http://rizqi-cookies.com
Re: Immutable object
Posted by Muhammad Ichsan <ic...@gmail.com>.
On Thu, Oct 14, 2010 at 4:06 PM, Willem Jiang <wi...@gmail.com> wrote:
>> So, Camel will use the same instance across Camel routes?
>>
>> I failed to replace the message into getIn().setBody() with the
>> message clone. It triggers time out exception. May be it's because I'm
>> not quite understand about inOut trick. This situation forces me to
>> have Camel call clone-service bean before getting into modification
>> bean. And it works.
>>
>
> Deep copying will introduce the performance issue to camel, you have to do
> it yourself. Basically Camel will copy the message headers and message body
> and exchange properties from first exchange to a new next exchange when it
> passes the next exchange to another process.
So, it's about performance issue. I see that...
What a good explanation! Thanks!
--
~The best men are men who benefit to others
http://michsan.web.id 一緒に勉強しましょう!
Yang berkualitas memang beda rasanya!
http://rizqi-cookies.com
Re: Immutable object
Posted by Willem Jiang <wi...@gmail.com>.
On 10/14/10 4:39 PM, Muhammad Ichsan wrote:
> On Thu, Oct 14, 2010 at 3:23 PM, Willem Jiang<wi...@gmail.com> wrote:
>> st create a new copy of internalMessage in the modify method and set it to
>> the message body after the modification ?
>
> So, Camel will use the same instance across Camel routes?
>
> I failed to replace the message into getIn().setBody() with the
> message clone. It triggers time out exception. May be it's because I'm
> not quite understand about inOut trick. This situation forces me to
> have Camel call clone-service bean before getting into modification
> bean. And it works.
>
Deep copying will introduce the performance issue to camel, you have to
do it yourself. Basically Camel will copy the message headers and
message body and exchange properties from first exchange to a new next
exchange when it passes the next exchange to another process.
--
Willem
----------------------------------
Open Source Integration: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: http://twitter.com/willemjiang
Re: Immutable object
Posted by Muhammad Ichsan <ic...@gmail.com>.
On Thu, Oct 14, 2010 at 3:23 PM, Willem Jiang <wi...@gmail.com> wrote:
> st create a new copy of internalMessage in the modify method and set it to
> the message body after the modification ?
So, Camel will use the same instance across Camel routes?
I failed to replace the message into getIn().setBody() with the
message clone. It triggers time out exception. May be it's because I'm
not quite understand about inOut trick. This situation forces me to
have Camel call clone-service bean before getting into modification
bean. And it works.
--
~The best men are men who benefit to others
http://michsan.web.id 一緒に勉強しましょう!
Yang berkualitas memang beda rasanya!
http://rizqi-cookies.com
Re: Immutable object
Posted by Willem Jiang <wi...@gmail.com>.
Maybe your InternalMessage is not full copied.
Can you just create a new copy of internalMessage in the modify method
and set it to the message body after the modification ?
BTW, you can change the wireTap uri to a log endpoint, it could be easy
track the message.
Willem
On 10/12/10 7:36 PM, Muhammad Ichsan wrote:
> Dear Camel Experts
>
> I have an object which becomes the main message to be transported
> across camel routes. So, I don't use String or other simple object.
> That's why I have to use converter.
>
> @Converter
> public class InternalMessageConverter {
>
> @Converter
> public static InputStream toText(InternalMessage iMsg) {
> return new ByteArrayInputStream(iMsg.toString().getBytes());
> }
> }
>
> The problem is at this route:
>
> <route>
> ....
> <wireTap uri="activemq:log.transaction" /><!-- Log the iMessage -->
>
> <choice>
> <when>
> <simple>${in.header.nextDestination} != null</simple>
> <wireTap uri="direct:invokeInBackground" />
> </when>
> </choice>
> </route>
>
>
> <route>
> <from uri="direct:invokeInBackground" />
>
> <to uri="bean:modifier?method=modify" />
>
> <!-- Send to create reversal TX log -->
> <wireTap uri="activemq:log.transaction" /><!-- Log the modified iMessage -->
> </route>
>
>
> When I send a message, the log.transaction will have the same messages
> which are both modified. I expect that I will have two different
> messages inside log.transaction (the unmodified and the modified one).
> Because the first wireTap sends the unmodified message to log but the
> second one sends the modified message. How to achieve this?
>
> Thanks
>
--
Willem
----------------------------------
Open Source Integration: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: http://twitter.com/willemjiang