我低于异常
Caused by: java.lang.NoSuchMethodException: com.stockopedia.symfony.Foundation.importExchange([B)
at java.lang.Class.getMethod(Class.java:1665)
at org.springframework.util.MethodInvoker.prepare(MethodInvoker.java:178)
at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.invokeListenerMethod(MessageListenerAdapter.java:466)
... 12 more
这就是我发送消息的方式
MessageProperties props = MessagePropertiesBuilder.newInstance()
.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)
.setReplyTo(this.replyQueue)
.setCorrelationId(itemStr.getBytes())
.setHeader("replyTimeout", this.replyTimeout).build();
Message message = MessageBuilder
.withBody(item.toString().getBytes()).andProperties(props)
.build();
这是我的侦听器容器配置
<rabbit:listener-container
connection-factory="rabbitConnectionFactory" concurrency="${import.exchanges.listener.concurrency}"
requeue-rejected="false" prefetch="1" >
<rabbit:listener queues="${import.exchanges.shares.queue}"
ref="foundation" method="importExchange" />
</rabbit:listener-container>
这是我的pojo,
public class Foundation {
public Message importExchange(Message exchange) {
System.out.println("Command:" + exchange.getBody());
Message message = MessageBuilder
.withBody(exchange.getBody().toString().getBytes()).setCorrelationId(exchange.getMessageProperties().getCorrelationId() .toString().getBytes()).build();
return message;
}
}
我不想实现任何接口,因为我在同一个 pojo 中有许多这样的方法,我想将它们用作侦听器。
我看过MessageListenerAdapter的实现代码,https://github.com/spring-projects/spring-amqp/blob/master/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessageListenerAdapter .java和文档 http://docs.spring.io/spring-amqp/docs/1.2.1.RELEASE/api/org/springframework/amqp/rabbit/listener/adapter/MessageListenerAdapter.html
这里给出了这个例子,它接受 Message 参数
public interface RawMessageDelegate {
void handleMessage(Message message);
}
我的 pojo 是相似的,为什么我得到这个异常?我尝试删除 setContentType 但仍然遇到相同的异常?