rabbitmq-InternalExchange

如果一个excahnge被定义成Internal,那么consumer是不能给它发消息的,会报错;

//
// Functional test demonstrating use of an internal exchange in an exchange to
// exchange routing scenario.  The routing topology is:
//
//            -------            -------
//          -/       \-        -/       \-
//         /           \      /           \           +-------------+
//         |    e0     +------|     e1    +-----------+    q1       |
//         \           /      \           /           +-------------+
//          -\       /-        -\       /-
//            -------            -------
//                              (internal)
//
// Where a non-internal exchange is bound to an internal exchange, which in
// turn is bound to a queue.  A client should be able to publish to e0, but
// not to e1, and publications to e0 should be delivered into q1.
//
public class InternalExchange extends BrokerTestCase
{
    private final String[] queues = new String[] { "q1" };
    private final String[] exchanges = new String[] { "e0", "e1" };

    protected void createResources() throws IOException
    {
        // The queues and exchange we create here are all auto-delete, so we
        // don't need to override releaseResources() with their deletions...
        for (String q : queues)
        {
            channel.queueDeclare(q, false, true, true, null);
        }

        // The second exchange, "e1", will be an 'internal' one.
        for ( String e : exchanges )
        {
            channel.exchangeDeclare(e, "direct",
                                    false, true,
                                    !e.equals("e0"),
                                    null);
        }

        channel.exchangeBind("e1", "e0", "");
        channel.queueBind("q1", "e1", "");
    }


    public void testTryPublishingToInternalExchange()
            throws IOException
    {
        byte[] testDataBody = "test-data".getBytes();

        // We should be able to publish to the non-internal exchange as usual
        // and see our message land in the queue...
        channel.basicPublish("e0", "", null, testDataBody);
        GetResponse r = channel.basicGet("q1", true);
        assertTrue(Arrays.equals(r.getBody(), testDataBody));

        // Publishing to the internal exchange will not be allowed...
        channel.basicPublish("e1", "", null, testDataBody);

        expectError(AMQP.ACCESS_REFUSED);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值