我的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");
例外情况:
无法使用不同类型,持久性,内部或自动删除值,类ID = 40,方法ID = 10的虚拟主机'/'重新声明交换'EX_TEST'
如何解决呢?
谢谢:D
最佳答案
方法中的参数
mModel.exchangeDeclare(EXCHANGE_NAME, MyExchangeType, true);
和
channel.exchangeDeclare(EXCHANGE_NAME, "topic");
应该是相同的。