You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by ilango_g <il...@yahoo.com> on 2008/10/13 23:36:01 UTC

Header-based routing

Hi
I need to write a Listener listening in on an "source/inbound" queue. This
listener will read the contents of the header and based on the content of a
specific header property, the Listener will pick up that message and route
it a certain destination queue that matches the information  in the header. 
Is there a sample available?

thanks
ilango
-- 
View this message in context: http://www.nabble.com/Header-based-routing-tp19963392p19963392.html
Sent from the Qpid Developers mailing list archive at Nabble.com.


Re: Header-based routing

Posted by Carl Trieloff <cc...@redhat.com>.
For M3:

 From client/message.h

    /** Get a modifyable reference to the message headers. */
    framing::FieldTable& getHeaders();

so for a message

int foo = msg.getHeaders().getInt("myPropThatIsInt");

if you are on trunk, getInt() / getString() is now getAsInt() / 
getAsString()

Two headers you care about are

qpid/client/message.h
qpid/framing/FieldTable.h

regards
Carl.




ilango_g wrote:
> I am sorry if I was not specific. Yes, I am asking how to get the application
> headers from a message. Thanks again
>
> ilango
>
> Carl Trieloff wrote:
>   
>> ok, are you asking how to get the application headers from a message?
>>
>> what part do you need help with?
>>
>> Carl.
>>
>>
>> ilango_g wrote:
>>     
>>> That does not seem to help. Any suggestions for me?
>>>
>>> Carl Trieloff wrote:
>>>   
>>>       
>>>> ilango_g wrote:
>>>>     
>>>>         
>>>>> Hi
>>>>> I need to write a Listener listening in on an "source/inbound" queue.
>>>>> This
>>>>> listener will read the contents of the header and based on the content
>>>>> of
>>>>> a
>>>>> specific header property, the Listener will pick up that message and
>>>>> route
>>>>> it a certain destination queue that matches the information  in the
>>>>> header. 
>>>>> Is there a sample available?
>>>>>
>>>>> thanks
>>>>> ilango
>>>>>   
>>>>>       
>>>>>           
>>>> I don't see a canned example, but basically you would use the "match" 
>>>> exchange so bind your
>>>> queues to the "amq.match" exchange.
>>>>
>>>> Then when you publish the messages you place the header to match based 
>>>> on the binding in the
>>>> message application headers.
>>>>
>>>> Here are some code snippets to publish to a headers exchange...
>>>>
>>>> --- examples of bind  & msg below...
>>>>
>>>>         std::string myQueue=session.getId().str();
>>>>         session.queueDeclare(arg::queue=myQueue, arg::exclusive=true,
>>>> arg::autoDelete=true);
>>>>
>>>>         session.exchangeBind(arg::exchange="amq.match",
>>>> arg::queue=myQueue, arg::arguments=bind);
>>>>
>>>> .... then where you publish the message
>>>>
>>>>        session.messageTransfer(arg::content=message,
>>>> arg::destination="amq.match", arg::arguments=msg);
>>>>
>>>>
>>>>
>>>>
>>>> match all example
>>>>
>>>>     FieldTable bind, msg;
>>>>     bind.setString("x-match", "all");
>>>>     bind.setString("foo", "FOO");
>>>>     bind.setInt("n", 42);
>>>>
>>>> then on message
>>>>     msg.setString("foo", "FOO");
>>>>     msg.setInt("n", 42);
>>>>
>>>>
>>>> match any exmaple
>>>>
>>>>     FieldTable bind, msg;
>>>>     bind.setString("x-match", "any");
>>>>     bind.setString("foo", "FOO");
>>>>     bind.setInt("n", 42);
>>>>
>>>> then on message
>>>>     msg.setString("foo", "FOO");
>>>>
>>>>
>>>> easiest would be to take the pub/sub example and update it  to use the 
>>>> "amq.match" exchange as above &  the update the bindings and message 
>>>> transfer
>>>> with header args
>>>>
>>>> shout if that does not help.
>>>> Carl.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>     
>>>>         
>>>   
>>>       
>>
>>     
>
>   


Re: Header-based routing

Posted by ilango_g <il...@yahoo.com>.
I am sorry if I was not specific. Yes, I am asking how to get the application
headers from a message. Thanks again

ilango

Carl Trieloff wrote:
> 
> 
> ok, are you asking how to get the application headers from a message?
> 
> what part do you need help with?
> 
> Carl.
> 
> 
> ilango_g wrote:
>> That does not seem to help. Any suggestions for me?
>>
>> Carl Trieloff wrote:
>>   
>>> ilango_g wrote:
>>>     
>>>> Hi
>>>> I need to write a Listener listening in on an "source/inbound" queue.
>>>> This
>>>> listener will read the contents of the header and based on the content
>>>> of
>>>> a
>>>> specific header property, the Listener will pick up that message and
>>>> route
>>>> it a certain destination queue that matches the information  in the
>>>> header. 
>>>> Is there a sample available?
>>>>
>>>> thanks
>>>> ilango
>>>>   
>>>>       
>>> I don't see a canned example, but basically you would use the "match" 
>>> exchange so bind your
>>> queues to the "amq.match" exchange.
>>>
>>> Then when you publish the messages you place the header to match based 
>>> on the binding in the
>>> message application headers.
>>>
>>> Here are some code snippets to publish to a headers exchange...
>>>
>>> --- examples of bind  & msg below...
>>>
>>>         std::string myQueue=session.getId().str();
>>>         session.queueDeclare(arg::queue=myQueue, arg::exclusive=true,
>>> arg::autoDelete=true);
>>>
>>>         session.exchangeBind(arg::exchange="amq.match",
>>> arg::queue=myQueue, arg::arguments=bind);
>>>
>>> .... then where you publish the message
>>>
>>>        session.messageTransfer(arg::content=message,
>>> arg::destination="amq.match", arg::arguments=msg);
>>>
>>>
>>>
>>>
>>> match all example
>>>
>>>     FieldTable bind, msg;
>>>     bind.setString("x-match", "all");
>>>     bind.setString("foo", "FOO");
>>>     bind.setInt("n", 42);
>>>
>>> then on message
>>>     msg.setString("foo", "FOO");
>>>     msg.setInt("n", 42);
>>>
>>>
>>> match any exmaple
>>>
>>>     FieldTable bind, msg;
>>>     bind.setString("x-match", "any");
>>>     bind.setString("foo", "FOO");
>>>     bind.setInt("n", 42);
>>>
>>> then on message
>>>     msg.setString("foo", "FOO");
>>>
>>>
>>> easiest would be to take the pub/sub example and update it  to use the 
>>> "amq.match" exchange as above &  the update the bindings and message 
>>> transfer
>>> with header args
>>>
>>> shout if that does not help.
>>> Carl.
>>>
>>>
>>>
>>>
>>>
>>>     
>>
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Header-based-routing-tp19963392p19978166.html
Sent from the Qpid Developers mailing list archive at Nabble.com.


Re: Header-based routing

Posted by Carl Trieloff <cc...@redhat.com>.
ok, are you asking how to get the application headers from a message?

what part do you need help with?

Carl.


ilango_g wrote:
> That does not seem to help. Any suggestions for me?
>
> Carl Trieloff wrote:
>   
>> ilango_g wrote:
>>     
>>> Hi
>>> I need to write a Listener listening in on an "source/inbound" queue.
>>> This
>>> listener will read the contents of the header and based on the content of
>>> a
>>> specific header property, the Listener will pick up that message and
>>> route
>>> it a certain destination queue that matches the information  in the
>>> header. 
>>> Is there a sample available?
>>>
>>> thanks
>>> ilango
>>>   
>>>       
>> I don't see a canned example, but basically you would use the "match" 
>> exchange so bind your
>> queues to the "amq.match" exchange.
>>
>> Then when you publish the messages you place the header to match based 
>> on the binding in the
>> message application headers.
>>
>> Here are some code snippets to publish to a headers exchange...
>>
>> --- examples of bind  & msg below...
>>
>>         std::string myQueue=session.getId().str();
>>         session.queueDeclare(arg::queue=myQueue, arg::exclusive=true,
>> arg::autoDelete=true);
>>
>>         session.exchangeBind(arg::exchange="amq.match",
>> arg::queue=myQueue, arg::arguments=bind);
>>
>> .... then where you publish the message
>>
>>        session.messageTransfer(arg::content=message,
>> arg::destination="amq.match", arg::arguments=msg);
>>
>>
>>
>>
>> match all example
>>
>>     FieldTable bind, msg;
>>     bind.setString("x-match", "all");
>>     bind.setString("foo", "FOO");
>>     bind.setInt("n", 42);
>>
>> then on message
>>     msg.setString("foo", "FOO");
>>     msg.setInt("n", 42);
>>
>>
>> match any exmaple
>>
>>     FieldTable bind, msg;
>>     bind.setString("x-match", "any");
>>     bind.setString("foo", "FOO");
>>     bind.setInt("n", 42);
>>
>> then on message
>>     msg.setString("foo", "FOO");
>>
>>
>> easiest would be to take the pub/sub example and update it  to use the 
>> "amq.match" exchange as above &  the update the bindings and message 
>> transfer
>> with header args
>>
>> shout if that does not help.
>> Carl.
>>
>>
>>
>>
>>
>>     
>
>   


Re: Header-based routing

Posted by ilango_g <il...@yahoo.com>.
That does not seem to help. Any suggestions for me?

Carl Trieloff wrote:
> 
> ilango_g wrote:
>> Hi
>> I need to write a Listener listening in on an "source/inbound" queue.
>> This
>> listener will read the contents of the header and based on the content of
>> a
>> specific header property, the Listener will pick up that message and
>> route
>> it a certain destination queue that matches the information  in the
>> header. 
>> Is there a sample available?
>>
>> thanks
>> ilango
>>   
> 
> 
> I don't see a canned example, but basically you would use the "match" 
> exchange so bind your
> queues to the "amq.match" exchange.
> 
> Then when you publish the messages you place the header to match based 
> on the binding in the
> message application headers.
> 
> Here are some code snippets to publish to a headers exchange...
> 
> --- examples of bind  & msg below...
> 
>         std::string myQueue=session.getId().str();
>         session.queueDeclare(arg::queue=myQueue, arg::exclusive=true,
> arg::autoDelete=true);
> 
>         session.exchangeBind(arg::exchange="amq.match",
> arg::queue=myQueue, arg::arguments=bind);
> 
> .... then where you publish the message
> 
>        session.messageTransfer(arg::content=message,
> arg::destination="amq.match", arg::arguments=msg);
> 
> 
> 
> 
> match all example
> 
>     FieldTable bind, msg;
>     bind.setString("x-match", "all");
>     bind.setString("foo", "FOO");
>     bind.setInt("n", 42);
> 
> then on message
>     msg.setString("foo", "FOO");
>     msg.setInt("n", 42);
> 
> 
> match any exmaple
> 
>     FieldTable bind, msg;
>     bind.setString("x-match", "any");
>     bind.setString("foo", "FOO");
>     bind.setInt("n", 42);
> 
> then on message
>     msg.setString("foo", "FOO");
> 
> 
> easiest would be to take the pub/sub example and update it  to use the 
> "amq.match" exchange as above &  the update the bindings and message 
> transfer
> with header args
> 
> shout if that does not help.
> Carl.
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Header-based-routing-tp19963392p19975762.html
Sent from the Qpid Developers mailing list archive at Nabble.com.


Re: Header-based routing

Posted by Carl Trieloff <cc...@redhat.com>.
ilango_g wrote:
> Hi
> I need to write a Listener listening in on an "source/inbound" queue. This
> listener will read the contents of the header and based on the content of a
> specific header property, the Listener will pick up that message and route
> it a certain destination queue that matches the information  in the header. 
> Is there a sample available?
>
> thanks
> ilango
>   


I don't see a canned example, but basically you would use the "match" 
exchange so bind your
queues to the "amq.match" exchange.

Then when you publish the messages you place the header to match based 
on the binding in the
message application headers.

Here are some code snippets to publish to a headers exchange...

--- examples of bind  & msg below...

        std::string myQueue=session.getId().str();
        session.queueDeclare(arg::queue=myQueue, arg::exclusive=true, arg::autoDelete=true);

        session.exchangeBind(arg::exchange="amq.match", arg::queue=myQueue, arg::arguments=bind);

.... then where you publish the message

       session.messageTransfer(arg::content=message, arg::destination="amq.match", arg::arguments=msg);




match all example

    FieldTable bind, msg;
    bind.setString("x-match", "all");
    bind.setString("foo", "FOO");
    bind.setInt("n", 42);

then on message
    msg.setString("foo", "FOO");
    msg.setInt("n", 42);


match any exmaple

    FieldTable bind, msg;
    bind.setString("x-match", "any");
    bind.setString("foo", "FOO");
    bind.setInt("n", 42);

then on message
    msg.setString("foo", "FOO");


easiest would be to take the pub/sub example and update it  to use the 
"amq.match" exchange as above &  the update the bindings and message 
transfer
with header args

shout if that does not help.
Carl.