您好我使用Spring boot 1.3.5和初学者RabbitMQ。在这个项目中,我有一个RabbitMQ消费者,它消耗来自特定队列的消息。但是在运行应用程序时它继续打印在控制台中的消息下方。而在谷歌浏览我读取设置heartBeat将解决问题,但没有运气对我来说,
14:08:14.892 [SimpleAsyncTaskExecutor-1] DEBUG o.s.a.r.l.BlockingQueueConsumer - Retrieving delivery for Consumer: tags=[{amq.ctag-rDkzcToXLMWqF4fFUIHS0A=notificationQueue}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,3), conn: Proxy@47914ea3 Shared Rabbit Connection: SimpleConnection@1096fe75 [delegate=amqp://guest@127.0.0.1:5672/], acknowledgeMode=AUTO local queue size=0
14:08:14.913 [SimpleAsyncTaskExecutor-3] DEBUG o.s.a.r.l.BlockingQueueConsumer - Retrieving delivery for Consumer: tags=[{amq.ctag-jxyjMKfw6heu77XVdYh3tw=notificationQueue}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,2), conn: Proxy@47914ea3 Shared Rabbit Connection: SimpleConnection@1096fe75 [delegate=amqp://guest@127.0.0.1:5672/], acknowledgeMode=AUTO local queue size=0
14:08:14.917 [SimpleAsyncTaskExecutor-2] DEBUG o.s.a.r.l.BlockingQueueConsumer - Retrieving delivery for Consumer: tags=[{amq.ctag-AcbX0R5eM-ukqWN0a_nrwA=notificationQueue}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1), conn: Proxy@47914ea3 Shared Rabbit Connection: SimpleConnection@1096fe75 [delegate=amqp://guest@127.0.0.1:5672/], acknowledgeMode=AUTO local queue size=0
14:08:15.893 [SimpleAsyncTaskExecutor-1] DEBUG o.s.a.r.l.BlockingQueueConsumer - Retrieving delivery for Consumer: tags=[{amq.ctag-rDkzcToXLMWqF4fFUIHS0A=notificationQueue}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,3), conn: Proxy@47914ea3 Shared Rabbit Connection: SimpleConnection@1096fe75 [delegate=amqp://guest@127.0.0.1:5672/], acknowledgeMode=AUTO local queue size=0
它永远结束。亲自找到以下消费者代码:
RabbitMqConfiguration.java
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableRabbit
public class RabbitMqConfiguration{
@Autowired
private CachingConnectionFactory cachingConnectionFactory;
@Value("${concurrent.consumers}")
public int concurrent_consumers;
@Value("${max.concurrent.consumers}")
public int max_concurrent_consumers;
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(cachingConnectionFactory);
factory.setConcurrentConsumers(concurrent_consumers);
factory.setMaxConcurrentConsumers(max_concurrent_consumers);
factory.setMessageConverter(jsonMessageConverter());
return factory;
}
@Bean
public MessageConverter jsonMessageConverter()
{
final Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();
return converter;
}
}
NotificationConsumer.java
@Component
public class NotificationConsumer {
private static final Logger logger = LoggerFactory.getLogger(NotificationConsumer.class);
@Value("${notification.queue}")
public String notificationQueue;
@RabbitListener(id="notification",containerFactory="rabbitListenerContainerFactory",queues = "#{notificationQueue}")
public void handleNotificationMessage(Transaction transaction)
{
System.out.println("Entered handleNotificationMessage::"+transaction.getId());
System.out.println("Exit handleNotificationMessage::"+transaction.getData());
logger.info("Entered handleNotificationMessage::", transaction.getId());
logger.info("Exit handleNotificationMessage::", transaction.getData());
}
@Bean
public Queue notificationQueue() {
return new Queue(notificationQueue, true, false, false);
}
}
application.yml
spring:
rabbitmq:
addresses: 127.0.0.1:5672
adminAddresses: http://127.0.0.1:15672
username: guest
password: guest
requested-heartbeat: 60
spring.rabbit.exchange: notification-exchange
notification.queue: notificationQueue
concurrent.consumers: 3
max.concurrent.consumers: 10
消息将由另一个应用程序生成,此应用程序将仅使用该消息。
应该感谢你的帮助。
根据Gary的说法,将记录器级别从DEBUG转移到INFO解决了我的问题。
logging:
level:
ROOT: INFO
现在我得到以下异常:
15:21:24.925 [SimpleAsyncTaskExecutor-2] WARN o.s.a.r.l.ConditionalRejectingErrorHandler - 致命消息转换错误;消息被拒绝; 它将被删除或路由到死信交换,如果这样配置:(正文:'{“id”:“5784eed4f5a64b4d8663e706”,“clientIdentifier”:“313131313131”, “data”:“按vad采样数据”,“currentAction”:{“state”:{“status”:“PENDING”,“errorCode”:“404”},“data”:“示例数据”}, “hasError”:false,“errorMessage”:“”}'MessageProperties [headers = {__ TypeId __ = com.global.produce.model.Transaction}, timestamp = null,messageId = null,userId = null,appId = null,clusterId = null,type = null,correlationId = null,replyTo = null,contentType = application / json, contentEncoding = UTF-8,contentLength = 0,deliveryMode = PERSISTENT,expiration = null,priority = 0,redelivered = false,receivedExchange =, receivedRoutingKey = notificationQueue,deliveryTag = 1,messageCount = 0])
有人对此错误有任何疑问吗?
答案 0 :(得分:4)
那只是DEBUG
日志;将日志设置更改为INFO或WARN或ERROR。