5.6.2. Declaring an XML Exchange, Declaring and Binding a Queue
Now we will declare an XML exchange named xml, a queue named message_queue, and a binding that routes messages based on an XQuery.
An XML Exchange differs from a direct exchange in two significant ways. The first is that there is no predeclared XML exchange, because it is not an exchange type defined in the AMQP specification. Therefore, you have to declare an XML exchange, whose type is xml:
session.exchangeDeclare(arg::exchange="xml", arg::type="xml");
The second difference is that an XML Exchange uses an XQuery to determine whether to route the message, based on the XML content of the message or message properties, as shown in the following code:
FieldTable binding;
binding.setString("xquery", "declare variable $control external;"
"./message/id mod 2 = 1 or $control = 'end'");
session.exchangeBind(arg::exchange="xml", arg::queue="message_queue", arg::bindingKey="query_name", arg::arguments=binding);
Note that this query has an external variable. Each application message header is bound to an external variable with the same name and value as the header before the routing query is invoked.