4.10.6. Subscribe to a Headers Exchange
- Changes
- Updated April 2013.
- Updated July 2013.
The following code creates a queue
match-q
, and subscribes it to the amq.match
exchange using a binding key that matches messages that have a header key header1
with a value of value1
:
AMQP 0-10
- Python
rxheaders = ssn.receiver("match-q;{create: always, node: {type: queue}, link:{x-bindings:[{key: 'binding-name', exchange: 'amq.match', queue: 'match-q', arguments:{'x-match': 'any', 'header1': 'value1'}}]}}")
AMQP 1.0
- C++
Receiver rxheaders = ssn.createReceiver("amq.match; {link: {name:match-q, filter:{value:{'x-match': 'any', 'header1': 'value1'}, name: headers, descriptor:'apache.org:legacy-amqp-headers-binding:map'}}}");
The
x-match
argument can take the values any
, which matches messages with any of the key value pairs in the binding, or all
, which matches messages that have all the key value pairs from the binding key in their header.
Note that you cannot match against multiple values for the same header. You can use multiple headers with different values, but only one value can be matched against a particular header.
AMQP 1.0 does not support link-scoped
x-binding
, and so a filter is used.
AMQP 0-10 uses a link-scoped
x-binding
. Note the x-bindings
argument key
. This argument creates a named handle for the binding, which is visible when running qpid-config exchanges -r
. Without a handle, a binding cannot be deleted by name. A null
key is valid, but in addition to not being able to be deleted by name, when a binding is created with a null
handle, any further attempt to create a binding with a null
handle on that exchange will be update the existing binding rather than create a new one.