我是一个尝试在java客户端实现Headers交换的新手.我知道这是"x-match"绑定参数的用途.当"x-match"参数设置为"any"时,只需一个匹配的标头值就足够了.或者,将"x-match"设置为"all",强制所有值必须匹配.但是任何人都可以为我提供一个骨架代码以便更好地理
hve*_*iga 24
要使用标头交换,您只需将交换声明为标头类型:
channel.exchangeDeclare("myExchange", "headers", true);
Run Code Online (Sandbox Code Playgroud)
然后,您需要在消费者使用它们之前声明一个队列,该队列将成为消息的最终目标:
channel.queueDeclare("myQueue", true, false, false, null);
Run Code Online (Sandbox Code Playgroud)
现在我们需要将交换绑定到队列来声明绑定.在此声明中,您可以设置将邮件从交换机路由到队列所需的标头.一个例子可能是:
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);
...
Run Code Online (Sandbox Code Playgroud)
这将使用headerName#1和headerName#2创建绑定.我希望这有帮助!
| 归档时间: |
|
| 查看次数: |
7829 次 |
| 最近记录: |