2

我的 RabbitMQ 上有一个主题交换。发送消息时出错。

EXCHANGE_NAME = "EX_TEST";

接收部分:

ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setHost(mServer);
mConnection = connectionFactory.newConnection();
mModel = mConnection.createChannel();
mModel.exchangeDeclare(EXCHANGE_NAME, MyExchangeType, true);
mQueue = mModel.queueDeclare().getQueue();
MySubscription = new QueueingConsumer(mModel);
mModel.queueBind(mQueue, EXCHANGE_NAME, routingKey);
mModel.basicConsume(mQueue, true, MySubscription);

发送部分:

ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, "topic");

在线错误:channel.exchangeDeclare(EXCHANGE_NAME, "topic"); 异常:无法在 vhost '/' 中使用不同类型、持久、内部或自动删除值重新声明交换 'EX_TEST',class-id=40,method-id=10

如何解决这个问题?谢谢你 :D

4

1 回答 1

1

方法参数

mModel.exchangeDeclare(EXCHANGE_NAME, MyExchangeType, true);

channel.exchangeDeclare(EXCHANGE_NAME, "topic");

应该是相同的。

于 2013-11-01T10:23:41.780 回答