在某些情况下,我使用了一些例外情况来拒绝该消息,但是在控制台中却显示了例外情况,乍一看似乎并不正确。
如何从控制台/文件登录中隐藏该特定异常
我正在使用spring-boot和默认记录器!
public static class UndispatchException extends AmqpRejectAndDontRequeueException{ public UndispatchException() { super("Dispatch still looking for a driver"); } }
这里是列表器
@RabbitListener(queues = TEST_QUEUE) public void handle(Dispatch in) { if(in.isRequeue()){ log.debug("will reject the message"); throw new UndispatchException(); } log.debug("won't reject the message"); }
这是我要隐藏的日志!在某些情况下必须重新排队该消息!
2018-05-15 18:41:11.494 WARN 2709 --- [cTaskExecutor-1] s.a.r.l.ConditionalRejectingErrorHandler : Execution of Rabbit message listener failed. org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener method 'public void com.amqp.handleException.demo.DemoApplication.handle(com.amqp.handleException.demo.DemoApplication$Dispatch)' threw exception at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:140) ~[spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:106) ~[spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:856) ~[spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:779) ~[spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:105) [spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:208) ~[spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1349) [spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:760) ~[spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1292) [spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:1262) [spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1800(SimpleMessageListenerContainer.java:105) [spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1518) [spring-rabbit-1.7.7.RELEASE.jar:na] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111] Caused by: com.amqp.handleException.demo.DemoApplication$UndispatchException: Dispatch still looking for a driver at com.amqp.handleException.demo.DemoApplication.handle(DemoApplication.java:47) ~[classes/:na] at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source) ~[na:na] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111] at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:180) ~[spring-messaging-4.3.15.RELEASE.jar:4.3.15.RELEASE] at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:112) ~[spring-messaging-4.3.15.RELEASE.jar:4.3.15.RELEASE] at org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:49) ~[spring-rabbit-1.7.7.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:126) ~[spring-rabbit-1.7.7.RELEASE.jar:na] ... 12 common frames omitted
在您的日志记录配置中,为
org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler
到ERROR(该消息记录在WARN级别)。
使用Spring Boot,您只需添加…
logging.level.org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler=ERROR
…到您的application.properties(或.yml)文件中。
编辑
如果您希望执行其他操作(例如记录某些异常),则可以制作的副本ConditionalRejectingErrorHandler并更改handleError()方法。该代码是在这里。
ConditionalRejectingErrorHandler
handleError()
然后,您可以使用自定义错误处理程序配置侦听器容器(或侦听器容器工厂)。