You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "senthil.arumugam" <se...@gmail.com> on 2010/08/24 15:34:17 UTC

Add header for each message

Hi,

I have created a producer interface to send messages to specified endpoint. 

Can I add a header to each message I send from my producer ? I would like to
get an example for the same. 

Is it possible to add an annotation in my producer like the below mentioned
? Will camel inject the property or header, when I am calling this method to
send a message ?

public interface Producer {
  void send(@Header(value="foo") String foo, Foo foo);
}

If camel injects header here, how can I check it using filter in my route
configuration with spring ?

Thanks in advance.

-SK
-- 
View this message in context: http://camel.465427.n5.nabble.com/Add-header-for-each-message-tp2651224p2651224.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Add header for each message

Posted by Willem Jiang <wi...@gmail.com>.
senthil.arumugam wrote:
> Hi Willem,
> 
> Our use case is, we need to save or update the entity.
> 
> For eg,
> 
> We have a message of instance Foo and we need to decide whether the instance
> to be saved or updated etc. This behavior is common across all the messages.
> 
> So we are wrapping Foo (actual message entity) with SampleMessage<T> which
> has a generic property and a String property of type.
> 
> Based on the type, we will route the message body to actual bean to process
> the same.
> 
> I meant by the term 'actual message', the entity which holds the body of the
> Message. 
> 
> I would be interested to hear from you, how did your thought process go when
> you got to think to replace proxy instance.

Oh, forget what I just said, I'm thinking your implementation is based 
on the proxy, but after thinking it twice the message body is 
BeanInvocation instance and it have nothing to do with your wrapping 
implementation.

> 
> Thanks,
> - SK

Willem

Re: Add header for each message

Posted by "senthil.arumugam" <se...@gmail.com>.
Hi Willem,

Our use case is, we need to save or update the entity.

For eg,

We have a message of instance Foo and we need to decide whether the instance
to be saved or updated etc. This behavior is common across all the messages.

So we are wrapping Foo (actual message entity) with SampleMessage<T> which
has a generic property and a String property of type.

Based on the type, we will route the message body to actual bean to process
the same.

I meant by the term 'actual message', the entity which holds the body of the
Message. 

I would be interested to hear from you, how did your thought process go when
you got to think to replace proxy instance.

Thanks,
- SK
-- 
View this message in context: http://camel.465427.n5.nabble.com/Add-header-for-each-message-tp2651224p2797605.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Add header for each message

Posted by "senthil.arumugam" <se...@gmail.com>.
Hi Willem,

I am using Camel 2.4.0 and let me try the same with 2.5-SNAPSHOT as you
mentioned and update the same once I am done.

Thanks,
- SK
-- 
View this message in context: http://camel.465427.n5.nabble.com/Add-header-for-each-message-tp2651224p2797607.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Add header for each message

Posted by Willem Jiang <wi...@gmail.com>.
senthil.arumugam wrote:
> Hi Willem,
> 
> I thank you for your reply. That was a way we were thinking, using which we
> can differentiate various messages and route them as needed.
> 
> Now we have achieved it by wrapping the actual message with another object
> of type Message which use generics to return the entity and holds a value
> type to differentiate the operation to be done on the entity.
Can you show me an example(or just a little test case) that you wrap the 
message with another generic Message? It could be interesting if the 
user still wants to use proxy to send out message.

> 
> But anyway, I would like to hear from you that how can I make use of Enum
> for type variable in the Wrapper class I use. When I try to use Enum, it
> threw me an exception with message saying cannot convert String to Enum.

Which version of Camel are you using?
We just fix a BeanConveter issue[1] last week. Can you try to use latest 
Camel 2.5-SNAPSHOT to verify it ?
If it doesn't work , please feel free to create a JIRA with your test 
case to show the error.

> Thank you,
> - SK

[1] https://issues.apache.org/activemq/browse/CAMEL-3082

Willem


Re: Add header for each message

Posted by "senthil.arumugam" <se...@gmail.com>.
Hi Willem,

I thank you for your reply. That was a way we were thinking, using which we
can differentiate various messages and route them as needed.

Now we have achieved it by wrapping the actual message with another object
of type Message which use generics to return the entity and holds a value
type to differentiate the operation to be done on the entity.

But anyway, I would like to hear from you that how can I make use of Enum
for type variable in the Wrapper class I use. When I try to use Enum, it
threw me an exception with message saying cannot convert String to Enum.

Thank you,
- SK
-- 
View this message in context: http://camel.465427.n5.nabble.com/Add-header-for-each-message-tp2651224p2797529.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Add header for each message

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

I wrote some test to implements your request and found current Proxy way 
can't not inject the header as you want, because Camel will create a 
BeanInvocation to hold the invocation information of the dynamical 
proxy. It is hard to tell the route to filter the header from you message.

If you are using the ProducerTemplate to send the message into the camel 
route , it could be more easy to implement your requirement :)


Willem


senthil.arumugam wrote:
> Hi,
> 
> I have created a producer interface to send messages to specified endpoint. 
> 
> Can I add a header to each message I send from my producer ? I would like to
> get an example for the same. 
> 
> Is it possible to add an annotation in my producer like the below mentioned
> ? Will camel inject the property or header, when I am calling this method to
> send a message ?
> 
> public interface Producer {
>   void send(@Header(value="foo") String foo, Foo foo);
> }
> 
> If camel injects header here, how can I check it using filter in my route
> configuration with spring ?
> 
> Thanks in advance.
> 
> -SK