Spring boot rabbitmq绑定不适用于spring引导
使用spring boot 1.5.9版本,代码如下Spring boot rabbitmq绑定不适用于spring引导,spring-boot,rabbitmq,spring-rabbit,Spring Boot,Rabbitmq,Spring Rabbit,使用spring boot 1.5.9版本,代码如下 @Configuration @EnableRabbit public class RabbitmqConfig { @Autowired ConnectionFactory connectionFactory; @Bean//with or without this bean, neither works public AmqpAdmin amqpAdmin() { return new R
@Configuration
@EnableRabbit
public class RabbitmqConfig {
@Autowired
ConnectionFactory connectionFactory;
@Bean//with or without this bean, neither works
public AmqpAdmin amqpAdmin() {
return new RabbitAdmin(connectionFactory);
}
@Bean
public Queue bbbQueue() {
return new Queue("bbb");
}
@Bean
public TopicExchange requestExchange() {
return new TopicExchange("request");
}
@Bean
public Binding bbbBinding() {
return BindingBuilder.bind(bbbQueue())
.to(requestExchange())
.with("*");
}
}
connection = pika.BlockingConnection(pika.ConnectionParameters(host='10.189.134.47'))
channel = connection.channel()
channel.exchange_declare(exchange='request', exchange_type='topic', durable=True)
result = channel.queue_declare(queue='aaa', durable=True)
queue_name = result.method.queue
channel.queue_bind(exchange='aaa', routing_key='*',
queue=queue_name)
print(' [*] Waiting for logs. To exit press CTRL+C')
def callback(ch, method, properties, body):
print(" [x] %r" % body)
channel.basic_consume(callback, queue=queue_name, no_ack=True)
channel.start_consuming()
jar启动后,RabbitMQ managementUI15672交换页面中没有错误消息,也没有显示主题交换
但是,对于python代码,主题exchange显示,绑定可以在exchange详细信息页面上看到。python代码如下
@Configuration
@EnableRabbit
public class RabbitmqConfig {
@Autowired
ConnectionFactory connectionFactory;
@Bean//with or without this bean, neither works
public AmqpAdmin amqpAdmin() {
return new RabbitAdmin(connectionFactory);
}
@Bean
public Queue bbbQueue() {
return new Queue("bbb");
}
@Bean
public TopicExchange requestExchange() {
return new TopicExchange("request");
}
@Bean
public Binding bbbBinding() {
return BindingBuilder.bind(bbbQueue())
.to(requestExchange())
.with("*");
}
}
connection = pika.BlockingConnection(pika.ConnectionParameters(host='10.189.134.47'))
channel = connection.channel()
channel.exchange_declare(exchange='request', exchange_type='topic', durable=True)
result = channel.queue_declare(queue='aaa', durable=True)
queue_name = result.method.queue
channel.queue_bind(exchange='aaa', routing_key='*',
queue=queue_name)
print(' [*] Waiting for logs. To exit press CTRL+C')
def callback(ch, method, properties, body):
print(" [x] %r" % body)
channel.basic_consume(callback, queue=queue_name, no_ack=True)
channel.start_consuming()
我只是复制了你的代码,它工作得很好 注意,在连接打开之前,队列/绑定不会被声明,例如由从队列读取的侦听器容器或使用RabbitTemplate发送消息
容器必须具有autoStartup=true默认值。早上淋浴时猜到了相同的原因。很好。谢谢