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 ()) ; 
交换器与交换器绑定

你可能感兴趣的:(RabbitMq 之queueBind和exchangeBind方法详解)