그외의 클래스의 경우 null처리가 된다.
SimpleMessageConverter 클래스 참고
/**
* Creates an AMQP Message from the provided Object.
*/
@Override
protected Message createMessage(Object object, MessageProperties messageProperties) throws MessageConversionException {
byte[] bytes = null;
if (object instanceof byte[]) {
bytes = (byte[]) object;
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_BYTES);
}
else if (object instanceof String) {
try {
bytes = ((String) object).getBytes(this.defaultCharset);
}
catch (UnsupportedEncodingException e) {
throw new MessageConversionException(
"failed to convert to Message content", e);
}
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);
messageProperties.setContentEncoding(this.defaultCharset);
}
else if (object instanceof Serializable) {
try {
bytes = SerializationUtils.serialize(object);
} catch (IllegalArgumentException e) {
throw new MessageConversionException(
"failed to convert to serialized Message content", e);
}
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_SERIALIZED_OBJECT);
}
if (bytes != null) {
messageProperties.setContentLength(bytes.length);
}
return new Message(bytes, messageProperties);
}
하지만 MessageConverter를 이용한다면 확장이 가능하다
http://docs.spring.io/spring-amqp/reference/html/amqp.html 의
3.6 Message Converters 를 참고
나의 경우 Jackson2JsonMessageConverter를 이용하였다.
============================================================
rabbitTemplate.setMessageConverter(Jackson2JsonMessageConverter());
@Bean
public Jackson2JsonMessageConverter Jackson2JsonMessageConverter(){
return new Jackson2JsonMessageConverter();
}
==============================================================
댓글 없음:
댓글 쓰기