You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Ade <ad...@googlemail.com> on 2010/10/08 12:21:10 UTC

Should we (could we?) make Exchanges serializable?

I've never been a fan of Java serialization; however, I've been working with
a Camel user who wants to be able to serialize an exchange and place the
whole thing on a JMS queue. The motivation is that they want to set the
exchange up to be subsequently persisted in a database for audit purposes,
but they want to separate the writing to a queue (relatively fast and
asynchronous) from the act of persisting to a database. 

In order to achieve this, they've had to create their own serializable
versions of Exchange, Header, Property, Message and Attachments. This works,
but it's painful to have to write and maintain that extra code. 

So. Just curious: would it be possible to modify the Camel core API and make
Exchanges etc. serializable? Interested to hear people's thoughts on this.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Should-we-could-we-make-Exchanges-serializable-tp3204367p3204367.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Should we (could we?) make Exchanges serializable?

Posted by Hadrian Zbarcea <hz...@gmail.com>.
Christian,

That's the gist of it, yes. You have to decide if you want to marshal the properties as well.

You are correct. The problem (stated another way) is that the exchange itself has no semantic outside of it's context, so what the holder does is to extract from the exchange the elements that are relevant by themselves, bundle them together (including the exchange id for correlation if needed) and serialize them. Probably not the most intuitive of names, but that's the purpose it serves.

Cheers,
Hadrian



On Oct 8, 2010, at 4:18 PM, Christian Müller wrote:

> I'm the camel user Ade is working with. :o)
> If I understood correct, we should code something like this on the sender
> side (we use Camel 2.2):
> 
> Serializable holder = DefaultExchangeHolder.marshal(exchange);
> exchange.getIn().setBody(holder);
> 
> and on the receiver side:
> 
> holder = exchange.getIn().getBody(DefaultExchangeHolder.class);
> DefaultExchangeHolder.unmarshal(exchange, holder);
> 
> I'm right?
> 
> @Hadrian: Make the Exchange serializable is a problem because the exchange
> has references to the hole Camel context and many other objects (which are
> not serializable) or is there another reason?
> 
> Thanks,
> Christian


Re: Should we (could we?) make Exchanges serializable?

Posted by Christian Müller <ch...@gmail.com>.
I'm the camel user Ade is working with. :o)
If I understood correct, we should code something like this on the sender
side (we use Camel 2.2):

Serializable holder = DefaultExchangeHolder.marshal(exchange);
exchange.getIn().setBody(holder);

and on the receiver side:

holder = exchange.getIn().getBody(DefaultExchangeHolder.class);
DefaultExchangeHolder.unmarshal(exchange, holder);

I'm right?

@Hadrian: Make the Exchange serializable is a problem because the exchange
has references to the hole Camel context and many other objects (which are
not serializable) or is there another reason?

Thanks,
Christian

Re: Should we (could we?) make Exchanges serializable?

Posted by Hadrian Zbarcea <hz...@gmail.com>.
It's ok for Messages to be Serializable. The Exchange imho should not.
So sure, wanna raise a jira?

Thanks
Hadrian

On Oct 8, 2010, at 10:51 AM, Björn Bength wrote:

> On a related issue regarding Serializable that occured to me:
> 
> We recently made a Wicket GUI interface for traced routes using
> org.apache.camel.processor.interceptor.jpa.JpaTraceEventMessage do
> store event messages.
> 
> We wanted to use this class directly in dao methods, for searching,
> listing and displaying in Wicket
> but as it's not Serializable we had to make our own version of the
> class to make Wicket really really happy.
> That would help when sending the jpa event message through jms,
> towards a jpa endpoint as well.
> 
> Couldn't you at least make this class Serializable as it only contains
> Strings and Date anyway?
> 
> Regards
> /Bjorn
> 
> On Fri, Oct 8, 2010 at 3:51 PM, Hadrian Zbarcea <hz...@gmail.com> wrote:
>> +1
>> fwiw, Hadrian
>> 
>> On Oct 8, 2010, at 7:05 AM, Claus Ibsen wrote:
>> 
>>> On Fri, Oct 8, 2010 at 12:21 PM, Ade <ad...@googlemail.com> wrote:
>>>> 
>>>> I've never been a fan of Java serialization; however, I've been working with
>>>> a Camel user who wants to be able to serialize an exchange and place the
>>>> whole thing on a JMS queue. The motivation is that they want to set the
>>>> exchange up to be subsequently persisted in a database for audit purposes,
>>>> but they want to separate the writing to a queue (relatively fast and
>>>> asynchronous) from the act of persisting to a database.
>>>> 
>>>> In order to achieve this, they've had to create their own serializable
>>>> versions of Exchange, Header, Property, Message and Attachments. This works,
>>>> but it's painful to have to write and maintain that extra code.
>>>> 
>>>> So. Just curious: would it be possible to modify the Camel core API and make
>>>> Exchanges etc. serializable? Interested to hear people's thoughts on this.
>>> 
>>> I dont think we should do this. We can not assume the data it contains
>>> can be serialized.
>>> 
>>> There is a DefaultExchangeHolder class which you can use to serialize
>>> and Exchange. It has the features to only transfer the objects which
>>> can be serialized.
>>> Its used by other components which supports the transferExchange
>>> options such as camel-jms, camel-mina, camel-netty, camel-hawtdb etc.
>>> 
>>> 
>>> 
>>> 
>>>> --
>>>> View this message in context: http://camel.465427.n5.nabble.com/Should-we-could-we-make-Exchanges-serializable-tp3204367p3204367.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>> 
>>> 
>>> 
>>> 
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>> 
>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>> 
>> 


Re: Should we (could we?) make Exchanges serializable?

Posted by Björn Bength <bj...@gmail.com>.
On a related issue regarding Serializable that occured to me:

We recently made a Wicket GUI interface for traced routes using
org.apache.camel.processor.interceptor.jpa.JpaTraceEventMessage do
store event messages.

We wanted to use this class directly in dao methods, for searching,
listing and displaying in Wicket
but as it's not Serializable we had to make our own version of the
class to make Wicket really really happy.
That would help when sending the jpa event message through jms,
towards a jpa endpoint as well.

Couldn't you at least make this class Serializable as it only contains
Strings and Date anyway?

Regards
/Bjorn

On Fri, Oct 8, 2010 at 3:51 PM, Hadrian Zbarcea <hz...@gmail.com> wrote:
> +1
> fwiw, Hadrian
>
> On Oct 8, 2010, at 7:05 AM, Claus Ibsen wrote:
>
>> On Fri, Oct 8, 2010 at 12:21 PM, Ade <ad...@googlemail.com> wrote:
>>>
>>> I've never been a fan of Java serialization; however, I've been working with
>>> a Camel user who wants to be able to serialize an exchange and place the
>>> whole thing on a JMS queue. The motivation is that they want to set the
>>> exchange up to be subsequently persisted in a database for audit purposes,
>>> but they want to separate the writing to a queue (relatively fast and
>>> asynchronous) from the act of persisting to a database.
>>>
>>> In order to achieve this, they've had to create their own serializable
>>> versions of Exchange, Header, Property, Message and Attachments. This works,
>>> but it's painful to have to write and maintain that extra code.
>>>
>>> So. Just curious: would it be possible to modify the Camel core API and make
>>> Exchanges etc. serializable? Interested to hear people's thoughts on this.
>>
>> I dont think we should do this. We can not assume the data it contains
>> can be serialized.
>>
>> There is a DefaultExchangeHolder class which you can use to serialize
>> and Exchange. It has the features to only transfer the objects which
>> can be serialized.
>> Its used by other components which supports the transferExchange
>> options such as camel-jms, camel-mina, camel-netty, camel-hawtdb etc.
>>
>>
>>
>>
>>> --
>>> View this message in context: http://camel.465427.n5.nabble.com/Should-we-could-we-make-Exchanges-serializable-tp3204367p3204367.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>
>

Re: Should we (could we?) make Exchanges serializable?

Posted by Hadrian Zbarcea <hz...@gmail.com>.
+1
fwiw, Hadrian

On Oct 8, 2010, at 7:05 AM, Claus Ibsen wrote:

> On Fri, Oct 8, 2010 at 12:21 PM, Ade <ad...@googlemail.com> wrote:
>> 
>> I've never been a fan of Java serialization; however, I've been working with
>> a Camel user who wants to be able to serialize an exchange and place the
>> whole thing on a JMS queue. The motivation is that they want to set the
>> exchange up to be subsequently persisted in a database for audit purposes,
>> but they want to separate the writing to a queue (relatively fast and
>> asynchronous) from the act of persisting to a database.
>> 
>> In order to achieve this, they've had to create their own serializable
>> versions of Exchange, Header, Property, Message and Attachments. This works,
>> but it's painful to have to write and maintain that extra code.
>> 
>> So. Just curious: would it be possible to modify the Camel core API and make
>> Exchanges etc. serializable? Interested to hear people's thoughts on this.
> 
> I dont think we should do this. We can not assume the data it contains
> can be serialized.
> 
> There is a DefaultExchangeHolder class which you can use to serialize
> and Exchange. It has the features to only transfer the objects which
> can be serialized.
> Its used by other components which supports the transferExchange
> options such as camel-jms, camel-mina, camel-netty, camel-hawtdb etc.
> 
> 
> 
> 
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Should-we-could-we-make-Exchanges-serializable-tp3204367p3204367.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>> 
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus


Re: Should we (could we?) make Exchanges serializable?

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Oct 8, 2010 at 12:21 PM, Ade <ad...@googlemail.com> wrote:
>
> I've never been a fan of Java serialization; however, I've been working with
> a Camel user who wants to be able to serialize an exchange and place the
> whole thing on a JMS queue. The motivation is that they want to set the
> exchange up to be subsequently persisted in a database for audit purposes,
> but they want to separate the writing to a queue (relatively fast and
> asynchronous) from the act of persisting to a database.
>
> In order to achieve this, they've had to create their own serializable
> versions of Exchange, Header, Property, Message and Attachments. This works,
> but it's painful to have to write and maintain that extra code.
>
> So. Just curious: would it be possible to modify the Camel core API and make
> Exchanges etc. serializable? Interested to hear people's thoughts on this.

I dont think we should do this. We can not assume the data it contains
can be serialized.

There is a DefaultExchangeHolder class which you can use to serialize
and Exchange. It has the features to only transfer the objects which
can be serialized.
Its used by other components which supports the transferExchange
options such as camel-jms, camel-mina, camel-netty, camel-hawtdb etc.




> --
> View this message in context: http://camel.465427.n5.nabble.com/Should-we-could-we-make-Exchanges-serializable-tp3204367p3204367.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Should we (could we?) make Exchanges serializable?

Posted by Adrian Trenaman <tr...@progress.com>.
  Thanks Claus for the quick response! Will propose the 
'transferExchange' approach.

Cheers,
Ade.

On 08/10/2010 12:02, Claus Ibsen wrote:
> Hi
>
> There is a transferExchange option on the JMS component
>
>
>
> On Fri, Oct 8, 2010 at 12:21 PM, Ade<ad...@googlemail.com>  wrote:
>> I've never been a fan of Java serialization; however, I've been working with
>> a Camel user who wants to be able to serialize an exchange and place the
>> whole thing on a JMS queue. The motivation is that they want to set the
>> exchange up to be subsequently persisted in a database for audit purposes,
>> but they want to separate the writing to a queue (relatively fast and
>> asynchronous) from the act of persisting to a database.
>>
>> In order to achieve this, they've had to create their own serializable
>> versions of Exchange, Header, Property, Message and Attachments. This works,
>> but it's painful to have to write and maintain that extra code.
>>
>> So. Just curious: would it be possible to modify the Camel core API and make
>> Exchanges etc. serializable? Interested to hear people's thoughts on this.
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Should-we-could-we-make-Exchanges-serializable-tp3204367p3204367.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>

Re: Should we (could we?) make Exchanges serializable?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

There is a transferExchange option on the JMS component



On Fri, Oct 8, 2010 at 12:21 PM, Ade <ad...@googlemail.com> wrote:
>
> I've never been a fan of Java serialization; however, I've been working with
> a Camel user who wants to be able to serialize an exchange and place the
> whole thing on a JMS queue. The motivation is that they want to set the
> exchange up to be subsequently persisted in a database for audit purposes,
> but they want to separate the writing to a queue (relatively fast and
> asynchronous) from the act of persisting to a database.
>
> In order to achieve this, they've had to create their own serializable
> versions of Exchange, Header, Property, Message and Attachments. This works,
> but it's painful to have to write and maintain that extra code.
>
> So. Just curious: would it be possible to modify the Camel core API and make
> Exchanges etc. serializable? Interested to hear people's thoughts on this.
> --
> View this message in context: http://camel.465427.n5.nabble.com/Should-we-could-we-make-Exchanges-serializable-tp3204367p3204367.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus