org.springframework.amqp.AmqpException: No method found for class [B
程序员文章站
2022-07-15 11:21:51
...
版本:spring-rabbit-1.7.1.RELEASE.jar
错误描述:
调用rabbitTemplate.convertAndSend(exchange, routingKey, object);
方法时,第三个参数Object直接传入JavaBean对象报错。
错误日志:
org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:876) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:786) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:706) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:96) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:187) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_241]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_241]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_241]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_241]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) ~[spring-aop-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]
at org.springframework.retry.interceptor.RetryOperationsInterceptor$1.doWithRetry(RetryOperationsInterceptor.java:91) ~[spring-retry-1.2.0.RELEASE.jar!/:?]
at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:286) [spring-retry-1.2.0.RELEASE.jar!/:?]
at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:179) [spring-retry-1.2.0.RELEASE.jar!/:?]
at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:115) [spring-retry-1.2.0.RELEASE.jar!/:?]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) [spring-aop-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]
at com.sun.proxy.$Proxy204.invokeListener(Unknown Source) [?:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1274) [spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:687) [spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1217) [spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:1187) [spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:96) [spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1414) [spring-rabbit-1.7.1.RELEASE.jar!/:?]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]
Caused by: org.springframework.amqp.AmqpException: No method found for class [B
at org.springframework.amqp.rabbit.listener.adapter.DelegatingInvocableHandler.getHandlerForPayload(DelegatingInvocableHandler.java:127) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.adapter.DelegatingInvocableHandler.getMethodNameFor(DelegatingInvocableHandler.java:224) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.getMethodAsString(HandlerAdapter.java:61) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:140) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:106) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:783) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
... 24 more
2021-04-19 15:25:35,102:WARN org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler SimpleAsyncTaskExecutor-1 (ConditionalRejectingErrorHandler.java:73) - Execution of Rabbit message listener failed.
org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Retry Policy Exhausted
at org.springframework.amqp.rabbit.retry.RejectAndDontRequeueRecoverer.recover(RejectAndDontRequeueRecoverer.java:45) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.config.StatelessRetryOperationsInterceptorFactoryBean$1.recover(StatelessRetryOperationsInterceptorFactoryBean.java:66) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.config.StatelessRetryOperationsInterceptorFactoryBean$1.recover(StatelessRetryOperationsInterceptorFactoryBean.java:59) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.retry.interceptor.RetryOperationsInterceptor$ItemRecovererCallback.recover(RetryOperationsInterceptor.java:141) ~[spring-retry-1.2.0.RELEASE.jar!/:?]
at org.springframework.retry.support.RetryTemplate.handleRetryExhausted(RetryTemplate.java:512) ~[spring-retry-1.2.0.RELEASE.jar!/:?]
at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:350) ~[spring-retry-1.2.0.RELEASE.jar!/:?]
at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:179) ~[spring-retry-1.2.0.RELEASE.jar!/:?]
at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:115) ~[spring-retry-1.2.0.RELEASE.jar!/:?]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]
at com.sun.proxy.$Proxy204.invokeListener(Unknown Source) ~[?:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1274) ~[spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:687) [spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1217) [spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:1187) [spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:96) [spring-rabbit-1.7.1.RELEASE.jar!/:?]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1414) [spring-rabbit-1.7.1.RELEASE.jar!/:?]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]
Caused by: org.springframework.amqp.AmqpRejectAndDontRequeueException: org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception
... 18 more
报错原因:
处理方法:
JavaBean消息对象手动转字符串传入,如使用fastJson转JSON字符串,rabbitTemplate.convertAndSend(exchange, routingKey, JSONObject.toJSONString(object));
如果遇到自动ack失败循环打印以上日志异常信息的情况可以限制rabbitmq ack失败重试次数,可参考如下配置
spring:
rabbitmq:
publisher-confirms: true
host: 192.168.1.111
port: 5672
username: guest
password: 111111
listener:
retry:
enabled: true
max-attempts: 3
max-interval: 10000 # 重试最大间隔时间
initial-interval: 1000 # 重试初始间隔时间
multiplier: 2 # 间隔时间乘子,间隔时间*乘子=下一次的间隔时间,最大不能超过设置的最大间隔时间
acknowledge-mode: auto # 自动ack
上一篇: 提权 --Mysql提权方式总结
下一篇: springboot项目需要的依赖
推荐阅读
-
Caused by: org.springframework.amqp.AmqpException: No method found for class [B
-
解决org.springframework.amqp.AmqpException: No method found for class [B 问题
-
org.springframework.amqp.AmqpException: No method found for class [B
-
解决rabbitmq无限循环异常问题亲测 Caused by: org.springframework.amqp.AmqpException: No method found for class [B
-
Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/blog/about/ Raised by: b