请问一下,同样的代码,启动时消费者没有连接上MQ服务器如何解决
我用的配置文件是yml形式,生产者那边配置没问题,可以正常连接服务器并发送消息。
消费者这边一样的,并且可以正常启动SpringBootApplication,但是在控制台中rabbitConnectionFactory已经注册了,之后却没有连接服务器的操作,同时控制台输出也为空,没有进入Receiver类。以下是控制台输出,Receiver类和yml配置文件,请问一下是哪里没有配置正确。
application.yml #rabbitmq基础配置 spring: rabbitmq: addresses: 127.0.0.1:5672 username: guest password: guest virtual-host: / connection-timeout: 15000 #rabbitmq消费者配置 listener: simple: concurrency: 5 max-concurrency: 10 acknowledge-mode: manual prefetch: 1 http: encoding: UTF-8 jackson: date-format: yyyy-MM-dd HH:mm:ss time-zone: GMT+8 default-property-inclusion: non_null server: servlet: context-path: / port: 8002
@Component public class OrderReceiver { //Rabbit以注解的形式进行监听 @RabbitListener( bindings = @QueueBinding( value = @Queue(value = "order-queue", durable = "true"), exchange = @Exchange(value = "order-exchange" , type = "topic"), key = "order.#" ) ) @RabbitHandler public void onOrderMsg(@Payload Order order , @Headers Map<String,Object> headers, Channel channel) throws IOException { //消费者操作 System.err.println("消费者活动"); System.out.println("订单ID: " + order.getId()); Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG); //手工模式,响应ACK channel.basicAck(deliveryTag, false); }