RabbitMQ,主题交换

时间:2013-11-01 08:12:26

标签: java android rabbitmq rabbitmq-exchange

我的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

1 个答案:

答案 0 :(得分:1)

中的方法参数
mModel.exchangeDeclare(EXCHANGE_NAME, MyExchangeType, true);

channel.exchangeDeclare(EXCHANGE_NAME, "topic");

应该完全相同。