* properties H1 and H2 and the other queue receives messages with either one of those properties.
*/
public static void main(String[] args)
{
// Create connection
Connection con = new Connection();
con.connect("localhost", 5672, "test", "guest", "guest",false);
// Create session
Session session = con.createSession(0);
// declare and bind queues
session.queueDeclare("headers_queue_any", null, null);
session.queueDeclare("headers_queue_all", null, null);
// we need to declare the header: name, type, alternate exchange
session.exchangeDeclare("test.headers", "headers", "amq.direct", null);
// The matching algorithm is controlled by 'x-match' property
// 'x-match' can take one of two values,
// (i) 'all' implies that all the other pairs must match the headers
// property of a message for that message to be routed (i.e. an AND match)
// (ii) 'any' implies that the message should be routed if any of the
// fields in the headers property match one of the fields in the arguments table (i.e. an OR match)
Map<String, Object> arguments = new HashMap<String, Object>();
arguments.put("x-match", "any");
arguments.put("h1", "v1");
arguments.put("h2", "v2");
session.exchangeBind("headers_queue_any", "test.headers", "useless", arguments);
arguments = new HashMap<String, Object>();
arguments.put("x-match", "all");
arguments.put("h1", "v1");
arguments.put("h2", "v2");
session.exchangeBind("headers_queue_all", "test.headers", "useless", arguments);
// confirm completion
session.sync();
//cleanup
session.close();
con.close();
}