chenghm123 opened a new issue #359:
URL: https://github.com/apache/rocketmq-spring/issues/359
```java
public class DefaultRocketMQListenerContainer implements InitializingBean,
RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware {
// ……
private Object doConvertMessage(MessageExt messageExt) {
if (Objects.equals(messageType, MessageExt.class) ||
Objects.equals(messageType, org.apache.rocketmq.common.message.Message.class)) {
return messageExt;
} else {
String str = new String(messageExt.getBody(),
Charset.forName(charset));
if (Objects.equals(messageType, String.class)) {
return str;
} else {
// If msgType not string, use objectMapper change it.
try {
if (messageType instanceof Class) {
//if the messageType has not Generic Parameter
return
this.getMessageConverter().fromMessage(MessageBuilder.withPayload(str).build(),
(Class<?>) messageType);
} else {
//if the messageType has Generic Parameter, then use
SmartMessageConverter#fromMessage with third parameter "conversionHint".
//we have validate the MessageConverter is
SmartMessageConverter in this#getMethodParameter.
return ((SmartMessageConverter)
this.getMessageConverter()).fromMessage(MessageBuilder.withPayload(str).build(),
(Class<?>) ((ParameterizedType) messageType).getRawType(), methodParameter);
}
} catch (Exception e) {
log.info("convert failed. str:{}, msgType:{}", str,
messageType);
throw new RuntimeException("cannot convert message to "
+ messageType, e);
}
}
}
}
// ……
}
```
这个直接就`new
String()`了,后面`MessageConverter`发挥不出更大的作用,万一序列化用的是`hession`或者`kryo`就会失败。
顺便是否可以扩展一下不通的消费实例,不同的`RocketMQTemplate`设置不同的`MessageConverter`,来兼容很多公司的一些现状。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]