You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Matt Sicker <bo...@gmail.com> on 2015/11/24 22:46:56 UTC

Am I using headers right?

In my application, I use headers (and occasionally properties) to include
metadata about a message that generally needs to be available in multiple
endpoints. I use JMS in areas which copies all headers (but not
properties), so I use headers for this purpose. I'm looking at possibly
switching my middleware, but I'm noticing that a lot of camel components
don't bother sending message headers either and instead rely on the body
only.

I don't want to do something ridiculous like how SOAP works by including
both headers and a body as the actual message body, but a lot of these
components provide no alternatives. Am I using headers properly, or is this
a terrible abuse of headers?

-- 
Matt Sicker <bo...@gmail.com>

Re: Am I using headers right?

Posted by Matt Sicker <bo...@gmail.com>.
Here's an example of what I like to do:

Use the REST DSL to expose routes. Each REST endpoint forwards the Java
object along with the headers given by the endpoint (corresponding to HTTP
headers, path parameters, and query parameters) to a dedicated queue (or
topic) for each REST endpoint. Using the JMS component, this all works just
fine. However, if I wanted to replace this middleware with something like
Kafka, Hazelcast, or even something amusing like IRC or XMPP, I lose all my
headers. I don't want to change the message body because that is typically
the contents of the POST/PUT body.

On 25 November 2015 at 11:39, Joakim Bjørnstad <jo...@gmail.com> wrote:

> Yes, you typically use them for route internal metadata.
>
> But they are not lost when they enter and return from an endpoint,
> unless you or the component creates a fresh new exchange.
>
> Please also see this SO:
>
> http://stackoverflow.com/questions/10330998/passing-values-between-processors-in-apache-camel
>
>
> On Wed, Nov 25, 2015 at 4:00 PM, Matt Sicker <bo...@gmail.com> wrote:
> > Properties get lost even more often than headers, though. They're only
> > copied when the entire Exchange is used instead of the message body or
> the
> > Message object. I use them for temporary metadata between Processors,
> > beans, etc.
> >
> > On 25 November 2015 at 06:54, Joakim Bjørnstad <jo...@gmail.com>
> wrote:
> >
> >> Hello,
> >>
> >> If you need metadata or a value on multiple endpoints, or to be used
> >> internally in your routes, it is better to put them in the
> >> exchangeProperties. Then copy them out to headers, when needed. Since
> >> headers are meant to be used at the protocol/component in/out, there
> >> is no guarantee they persist or be unchanged when the message returns.
> >> Also reduces unwanted metadata leaking out of your routes, for example
> >> to JMS, HTTP/SOAP as you mentioned.
> >>
> >>
> >>
> >> On Wed, Nov 25, 2015 at 12:52 AM, Matt Sicker <bo...@gmail.com> wrote:
> >> > I filter out what headers to send when making REST calls through http4
> >> for
> >> > instance, so that's not an issue. When I make internal calls to
> networked
> >> > services (e.g., Kafka, Hazelcast, or pretty much anything other than
> the
> >> > message brokering components), I lose all my headers until the
> response
> >> > message is handled (and only some components save those headers).
> >> >
> >> > On 24 November 2015 at 16:36, ychawla <pr...@gmail.com>
> >> wrote:
> >> >
> >> >> That sounds sensible to me.  The headers are for message and exchange
> >> >> metadata.  Just be careful to not send them over the wire when you
> call
> >> an
> >> >> external component.
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> View this message in context:
> >> >>
> >>
> http://camel.465427.n5.nabble.com/Am-I-using-headers-right-tp5774363p5774365.html
> >> >> Sent from the Camel - Users mailing list archive at Nabble.com.
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Matt Sicker <bo...@gmail.com>
> >>
> >>
> >>
> >> --
> >> Kind regards
> >> Joakim Bjørnstad
> >>
> >
> >
> >
> > --
> > Matt Sicker <bo...@gmail.com>
>
>
>
> --
> Kind regards
> Joakim Bjørnstad
>



-- 
Matt Sicker <bo...@gmail.com>

Re: Am I using headers right?

Posted by Joakim Bjørnstad <jo...@gmail.com>.
Yes, you typically use them for route internal metadata.

But they are not lost when they enter and return from an endpoint,
unless you or the component creates a fresh new exchange.

Please also see this SO:
http://stackoverflow.com/questions/10330998/passing-values-between-processors-in-apache-camel


On Wed, Nov 25, 2015 at 4:00 PM, Matt Sicker <bo...@gmail.com> wrote:
> Properties get lost even more often than headers, though. They're only
> copied when the entire Exchange is used instead of the message body or the
> Message object. I use them for temporary metadata between Processors,
> beans, etc.
>
> On 25 November 2015 at 06:54, Joakim Bjørnstad <jo...@gmail.com> wrote:
>
>> Hello,
>>
>> If you need metadata or a value on multiple endpoints, or to be used
>> internally in your routes, it is better to put them in the
>> exchangeProperties. Then copy them out to headers, when needed. Since
>> headers are meant to be used at the protocol/component in/out, there
>> is no guarantee they persist or be unchanged when the message returns.
>> Also reduces unwanted metadata leaking out of your routes, for example
>> to JMS, HTTP/SOAP as you mentioned.
>>
>>
>>
>> On Wed, Nov 25, 2015 at 12:52 AM, Matt Sicker <bo...@gmail.com> wrote:
>> > I filter out what headers to send when making REST calls through http4
>> for
>> > instance, so that's not an issue. When I make internal calls to networked
>> > services (e.g., Kafka, Hazelcast, or pretty much anything other than the
>> > message brokering components), I lose all my headers until the response
>> > message is handled (and only some components save those headers).
>> >
>> > On 24 November 2015 at 16:36, ychawla <pr...@gmail.com>
>> wrote:
>> >
>> >> That sounds sensible to me.  The headers are for message and exchange
>> >> metadata.  Just be careful to not send them over the wire when you call
>> an
>> >> external component.
>> >>
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://camel.465427.n5.nabble.com/Am-I-using-headers-right-tp5774363p5774365.html
>> >> Sent from the Camel - Users mailing list archive at Nabble.com.
>> >>
>> >
>> >
>> >
>> > --
>> > Matt Sicker <bo...@gmail.com>
>>
>>
>>
>> --
>> Kind regards
>> Joakim Bjørnstad
>>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>



-- 
Kind regards
Joakim Bjørnstad

Re: Am I using headers right?

Posted by Matt Sicker <bo...@gmail.com>.
Properties get lost even more often than headers, though. They're only
copied when the entire Exchange is used instead of the message body or the
Message object. I use them for temporary metadata between Processors,
beans, etc.

On 25 November 2015 at 06:54, Joakim Bjørnstad <jo...@gmail.com> wrote:

> Hello,
>
> If you need metadata or a value on multiple endpoints, or to be used
> internally in your routes, it is better to put them in the
> exchangeProperties. Then copy them out to headers, when needed. Since
> headers are meant to be used at the protocol/component in/out, there
> is no guarantee they persist or be unchanged when the message returns.
> Also reduces unwanted metadata leaking out of your routes, for example
> to JMS, HTTP/SOAP as you mentioned.
>
>
>
> On Wed, Nov 25, 2015 at 12:52 AM, Matt Sicker <bo...@gmail.com> wrote:
> > I filter out what headers to send when making REST calls through http4
> for
> > instance, so that's not an issue. When I make internal calls to networked
> > services (e.g., Kafka, Hazelcast, or pretty much anything other than the
> > message brokering components), I lose all my headers until the response
> > message is handled (and only some components save those headers).
> >
> > On 24 November 2015 at 16:36, ychawla <pr...@gmail.com>
> wrote:
> >
> >> That sounds sensible to me.  The headers are for message and exchange
> >> metadata.  Just be careful to not send them over the wire when you call
> an
> >> external component.
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://camel.465427.n5.nabble.com/Am-I-using-headers-right-tp5774363p5774365.html
> >> Sent from the Camel - Users mailing list archive at Nabble.com.
> >>
> >
> >
> >
> > --
> > Matt Sicker <bo...@gmail.com>
>
>
>
> --
> Kind regards
> Joakim Bjørnstad
>



-- 
Matt Sicker <bo...@gmail.com>

Re: Am I using headers right?

Posted by Joakim Bjørnstad <jo...@gmail.com>.
Hello,

If you need metadata or a value on multiple endpoints, or to be used
internally in your routes, it is better to put them in the
exchangeProperties. Then copy them out to headers, when needed. Since
headers are meant to be used at the protocol/component in/out, there
is no guarantee they persist or be unchanged when the message returns.
Also reduces unwanted metadata leaking out of your routes, for example
to JMS, HTTP/SOAP as you mentioned.



On Wed, Nov 25, 2015 at 12:52 AM, Matt Sicker <bo...@gmail.com> wrote:
> I filter out what headers to send when making REST calls through http4 for
> instance, so that's not an issue. When I make internal calls to networked
> services (e.g., Kafka, Hazelcast, or pretty much anything other than the
> message brokering components), I lose all my headers until the response
> message is handled (and only some components save those headers).
>
> On 24 November 2015 at 16:36, ychawla <pr...@gmail.com> wrote:
>
>> That sounds sensible to me.  The headers are for message and exchange
>> metadata.  Just be careful to not send them over the wire when you call an
>> external component.
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Am-I-using-headers-right-tp5774363p5774365.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>



-- 
Kind regards
Joakim Bjørnstad

Re: Am I using headers right?

Posted by Matt Sicker <bo...@gmail.com>.
I filter out what headers to send when making REST calls through http4 for
instance, so that's not an issue. When I make internal calls to networked
services (e.g., Kafka, Hazelcast, or pretty much anything other than the
message brokering components), I lose all my headers until the response
message is handled (and only some components save those headers).

On 24 November 2015 at 16:36, ychawla <pr...@gmail.com> wrote:

> That sounds sensible to me.  The headers are for message and exchange
> metadata.  Just be careful to not send them over the wire when you call an
> external component.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Am-I-using-headers-right-tp5774363p5774365.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Matt Sicker <bo...@gmail.com>

Re: Am I using headers right?

Posted by ychawla <pr...@gmail.com>.
That sounds sensible to me.  The headers are for message and exchange
metadata.  Just be careful to not send them over the wire when you call an
external component.



--
View this message in context: http://camel.465427.n5.nabble.com/Am-I-using-headers-right-tp5774363p5774365.html
Sent from the Camel - Users mailing list archive at Nabble.com.