RabbitMq 之queueBind和exchangeBind方法详解

queueBind 方法详解

将队列和交换器绑定 方法如下 ,可以与前两节中的方法定义进行类比。

Queue.BindOk queueBind(String queue , String exchange , String routingKey) throws IOException ; 
Queue.BindOk queueBind(String queue , String exchange , String routingKey, Map arguments) throws IOException; 
void queueBindNoWait(String queue , String exchange , String routingKey, Map arguments) throws IOException; 

方法中涉及的参数详解:
~ queue: 队列名称:
~exchange: 交换器的名称:
~routingKey: 用来绑定队列和交换器的路由键;
~argument: 定义绑定的一些参数。 不仅可以将队列和交换器绑定起来,也可以将已经被绑定的队列和交换器进行解绑。具体 方法可以参考如下(具体的参数解释可以参考前面的内容,这里不再赘述):

Queue.UnbindOk queueUnbind (String queue , String exchange , String routingKey) throws IOException; 
Queue.UnbindOk queueUnbind (String queue , String exchange , String routingKey, Map arguments) throws IOException; 

exchangeBind 方法详解

我们不仅可以将交换器与队列绑定,也可以将交换器与交换器绑定,后者和前者的用法如 出一辙,相应的方法如下:

Exchange.BindOk exchangeBind(String destination , String source , String routingKey) throws IOException; 
Exchange.BindOk exchangeBind(String destination, String source , String routingKey, Map arguments) throws IOException;
void exchangeBindNoWait(String destination, String sour ce , String routingKey, Map arguments) throws IOException;

绑定之后 消息 source 换器转发到 destination 交换器,某种程度上来 destination 交换器可以看作个队列 。示例如下:

channel.exchangeDeclare( " source " , "direct " , false , true , null) ; 
channel.exchangeDeclare( "destination " , " fanout " , false , true , null); 
channel.exchangeBind( " destination " , " source " , " exKey"); 
channel.queueDeclare( "queue " , false , false , true , null); 
channel.queueBind( " queue " , dest nation "" ) ; 
channel.basicPublish( " source " , " exKey " , nu l l , " exToExDemo ". getBytes ()) ; 
交换器与交换器绑定
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容