---
title: "rabbitmq-exchangeBind"
author: "蝶盟紫"
date: "2015-12-01T09:36:13Z"
tags: []
categories: ["企业架构"]
slug: "rabbitmq-exchangebind"
draft: false
lastmod: "2015-12-01T09:36:13Z"
id: 2260686
url: "https://joandora.iteye.com/blog/2260686"
---

queue可以与exchange绑定

 

exchange之间也可以互相绑定，但是当queue与互相绑定的exchange都存在绑定关系时，不会重复接收消息。

    /* pre (eN --&gt; qN) for N in \[0..2]  
     * add binding (e0 --&gt; q1)  
     * test (e0 --&gt; {q0, q1})  
     * add binding (e1 --&gt; e0)  
     * resulting in: (e1 --&gt; {q1, e0 --&gt; {q0, q1}})  
     * test (e1 --&gt; {q0, q1})  
     \*/  
    public void testDuplicateQueueDestinations() throws IOException,  
            ShutdownSignalException, InterruptedException {  
        channel.queueBind("q1", "e0", "");  
        publishWithMarker("e0", "");  
        consumeNoDuplicates(consumers\[0]);  
        consumeNoDuplicates(consumers\[1]);

        channel.exchangeBind("e0", "e1", "");

        publishWithMarker("e1", "");  
        consumeNoDuplicates(consumers\[0]);  
        consumeNoDuplicates(consumers\[1]);

        channel.exchangeUnbind("e0", "e1", "");  
    }