Spring Integration序列化MessageHeader对象

时间:2015-02-24 14:47:50

标签: spring spring-integration spring-amqp

我有一些服务,一个用Grails 2.4.2(Spring 4.0.5)实现,一些用Spring Web(Spring 4.0.5)实现,另一个用Spring Boot 1.2.1(Spring 4.1.4)实现。 />
服务通过RabbitMQ与弹簧集成进行通信。

Grails和Spring Web服务之间的通信很好,但是无法与Spring Boot服务进行通信。因为Spring Boot使用较新的Spring版本,而MessageHeader类的串行版本也发生了变化。

我该怎么做才能避免这个问题?

这里有例外:

Caused by: org.springframework.messaging.MessagingException: Failure occured in AMQP listener while attempting to convert and dispatch Message.; nested exception is org.springframework.amqp.support.converter.MessageConversionException: failed to convert serialized
 Message content
        at org.springframework.integration.amqp.channel.AbstractSubscribableAmqpChannel$DispatchingMessageListener.onMessage(AbstractSubscribableAmqpChannel.java:201) ~[spring-integration-amqp-4.0.2.RELEASE.jar:na]
        at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:693) ~[spring-rabbit-1.3.4.RELEASE.jar:na]
        ... 10 common frames omitted
Caused by: org.springframework.amqp.support.converter.MessageConversionException: failed to convert serialized Message content
        at org.springframework.amqp.support.converter.SimpleMessageConverter.fromMessage(SimpleMessageConverter.java:112) ~[spring-amqp-1.3.4.RELEASE.jar:na]
        at org.springframework.integration.amqp.channel.AbstractSubscribableAmqpChannel$DispatchingMessageListener.onMessage(AbstractSubscribableAmqpChannel.java:176) ~[spring-integration-amqp-4.0.2.RELEASE.jar:na]
        ... 11 common frames omitted
Caused by: java.lang.IllegalArgumentException: Could not deserialize object
        at org.springframework.amqp.utils.SerializationUtils.deserialize(SerializationUtils.java:79) ~[spring-amqp-1.3.4.RELEASE.jar:na]
        at org.springframework.amqp.support.converter.SimpleMessageConverter.fromMessage(SimpleMessageConverter.java:107) ~[spring-amqp-1.3.4.RELEASE.jar:na]
        ... 12 common frames omitted
Caused by: java.io.InvalidClassException: org.springframework.messaging.MessageHeaders; local class incompatible: stream classdesc serialVersionUID = -4615750558355702881, local class serialVersionUID = 7035068984263400920
        at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:617) ~[na:1.7.0_51]
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622) ~[na:1.7.0_51]
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517) ~[na:1.7.0_51]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771) ~[na:1.7.0_51]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350) ~[na:1.7.0_51]
>       at org.springframework.amqp.utils.SerializationUtils.deserialize(SerializationUtils.java:76) ~[spring-amqp-1.3.4.RELEASE.jar:na]

1 个答案:

答案 0 :(得分:1)

不要序列化整个Message<?>;使用AMQP适配器&#39;能够将Message标题映射到amqp标题,反之亦然。

我不确定它在grails方面是如何工作的,但你也需要在那里进行映射。