To use header exchanges, you just need to declare your exchange as a header type:
channel.exchangeDeclare("myExchange", "headers", true);
Then you need to declare a queue that will become the final destination of the messages before the consumer consumes them:
channel.queueDeclare("myQueue", true, false, false, null);
Now we need to bind the exchange to the queue, declaring the binding. This ad indicates which headers you want to route messages from your exchange to the queue. An example would be:
Map<String, Object> bindingArgs = new HashMap<String, Object>(); bindingArgs.put("x-match", "any"); //any or all bindingArgs.put("headerName#1", "headerValue#1"); bindingArgs.put("headerName#2", "headerValue#2"); ... channel.queueBind("myQueue", "myExchange", "", bindingArgs); ...
This will create a binding using headerName # 1 and headerName # 2. Hope this helps!
hveiga
source share