You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by marioradev <ma...@softwareag.com> on 2013/11/29 10:27:41 UTC

Persist headers when using cache

Hi there,

We are using cache component to persist our messages. Before persisting  and
emitting we add some extra specific headers to the event/message that we use
when it is received. However only the message body (payload) is persisted.
We need also headers to be persisted. I have searched for some property that
could specify that but could not find anything.

Could this behaviour of cache component be handled/managed in some way? Is
this behaviour done for some reason this way? Could you suggest us some
solution about this problem - we could explicitly add headers to the body
and serialize them but this is an expensive operation which should be done
on both sides - from the emitter and consumer. Any other proposals?

Regards, Mario.



--
View this message in context: http://camel.465427.n5.nabble.com/Persist-headers-when-using-cache-tp5744069.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Persist headers when using cache

Posted by Willem Jiang <wi...@gmail.com>.
The message header value could not be Serializable and camel cannot decide which header need to be put into the cache, and if you put a map instance into the message header it could make the things worse. I think you can take advantage of the Camel TypeConverter[1] by apply your customer converter which can turn the message body with the header to be the object you want to set to the Cache.

[1]http://camel.apache.org/type-converter.html
-- 
Willem Jiang
Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
          http://jnn.iteye.com (Chinese)
Twitter: willemjiang 
Weibo: 姜宁willem


On December 3, 2013 at 10:18:05 PM, shindito (atanas.shindov@gmail.com) wrote:
>
>I don't think that the persistence configuration influences how the cache
>component writes the exchanges into the cache.
>When performing add or update operations, the
>*org.apache.camel.component.cache.CacheProducer* class uses its
>createElementFromBody() method which takes the in message body from the
>exchange and creates a cache element from it. The message headers are not
>considered at all, thus the headers loss.
>
>Unfortunately, it seems that whether headers should be considered when
>creating the cache element is not customizable.
>
>*@Camel team*: what is you recommendation for this use case: we put some
>custom headers when creating a message and need them on the consumer side
>(after they have been sent to and consumed from the cache component)?
>One option would be to story the headers as part of the body before passing
>the message to the cache, and then extracting them back from it before the
>consumed message is passed to the processor, but will add overhead that we
>would like to avoid.
>
>Best regards,
>Atanas
>
>
>
>--
>View this message in context: http://camel.465427.n5.nabble.com/Persist-headers-when-using-cache-tp5744069p5744244.html
>Sent from the Camel - Users mailing list archive at Nabble.com.
>


Re: Persist headers when using cache

Posted by shindito <at...@gmail.com>.
I don't think that the persistence configuration influences how the cache
component writes the exchanges into the cache.
When performing add or update operations, the
*org.apache.camel.component.cache.CacheProducer* class uses its
createElementFromBody() method which takes the in message body from the
exchange and creates a cache element from it. The message headers are not
considered at all, thus the headers loss.

Unfortunately, it seems that whether headers should be considered when
creating the cache element is not customizable.

*@Camel team*: what is you recommendation for this use case: we put some
custom headers when creating a message and need them on the consumer side
(after they have been sent to and consumed from the cache component)?
One option would be to story the headers as part of the body before passing
the message to the cache, and then extracting them back from it before the
consumed message is passed to the processor, but will add overhead that we
would like to avoid.

Best regards,
Atanas



--
View this message in context: http://camel.465427.n5.nabble.com/Persist-headers-when-using-cache-tp5744069p5744244.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Persist headers when using cache

Posted by marioradev <ma...@softwareag.com>.
EventDrivenConsumerRoute[Endpoint[cache://http-namespaces-softwareag-com-EDA-WebM-Sample-PulsePressRelease-default]
->
Channel[sendTo(Endpoint[nervDefaultJMS://topic:Event::WebM::Sample::Pulse::PressRelease?disableReplyTo=true])]]



--
View this message in context: http://camel.465427.n5.nabble.com/Persist-headers-when-using-cache-tp5744069p5744189.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Persist headers when using cache

Posted by Willem Jiang <wi...@gmail.com>.
Can I have a look at your route?
I’m not sure how you did the persistent.

-- 
Willem Jiang
Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
          http://jnn.iteye.com (Chinese)
Twitter: willemjiang 
Weibo: 姜宁willem


On November 29, 2013 at 5:31:53 PM, marioradev (mario.radev@softwareag.com) wrote:
>
>Hi there,
>
>We are using cache component to persist our messages. Before persisting and
>emitting we add some extra specific headers to the event/message that we use
>when it is received. However only the message body (payload) is persisted.
>We need also headers to be persisted. I have searched for some property that
>could specify that but could not find anything.
>
>Could this behaviour of cache component be handled/managed in some way? Is
>this behaviour done for some reason this way? Could you suggest us some
>solution about this problem - we could explicitly add headers to the body
>and serialize them but this is an expensive operation which should be done
>on both sides - from the emitter and consumer. Any other proposals?
>
>Regards, Mario.
>
>
>
>--
>View this message in context: http://camel.465427.n5.nabble.com/Persist-headers-when-using-cache-tp5744069.html
>Sent from the Camel - Users mailing list archive at Nabble.com.
>