【发布时间】:2016-12-15 15:26:18
【问题描述】:
由于某种原因,RabbitListener 显示的是 ASCII 表示而不是实际的字符串
兔子 MQ 消息
交换 raw-cdr
英国路由密钥
重新发送
优先级:0delivery_mode: 2
标题:
文件名:/Users/shahbour/IdeaProjects/micro-services/file-sftp-service/ftp-inbound/LONSBC01.20161214142000.10120CB.ACT
content_encoding: UTF-8
content_type:文本/纯文本
Sonus Networks, Inc.00000000FF600000520000000000000128V04.02.05R000 00000000000000000000000000000ACT2016121414100000000000000000
但我得到的是
83,111,110,117,115,32,78,101,116,119,111,114,107,115,44,32,73,110,99,46,48,48,48,48,48,48,48,48,70,70,54,48,48,48,48,48 ,53,50,48,48,48,48,48,48,48,48,48,48,48,48,48,49,50,56,86,48,52,46,48,50,46 ,48,53,82,48,48,48,32,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48 ,48,48,48,48,48,48,48,48,48,48,65,67,84,50,48,49,54,49,50,49,52,49,52,49,48 ,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48
下面是我使用的代码,一切都是spring boot默认的
@RabbitListener(queues = {"fr-cdr.panel","uk-cdr.panel"})
public void messageHandler(Message<String> rawCdr, @Header String file_name) throws InterruptedException {
log.info(rawCdr);
}
生产者来自另一个程序,如下所示
@Bean
@ServiceActivator(inputChannel = "linesChannel")
public AmqpOutboundEndpoint amqpOutbound(AmqpTemplate amqpTemplate) {
AmqpOutboundEndpoint outbound = new AmqpOutboundEndpoint(amqpTemplate);
outbound.setExchangeName(exchangeName);
outbound.setRoutingKey(routingKey);
return outbound;
}
启用调试模式后问题显示
2016-12-16 07:46:03.714 DEBUG 81519 --- [cTaskExecutor-1] o.s.a.r.listener.BlockingQueueConsumer : Received message: (Body:'Sonus Networks, Inc.00000000FF600000520000000000000128V04.02.05R000 0000000000000000000000000000ACT2016121414100000000000000000' MessageProperties [headers={file_name=/Users/shahbour/IdeaProjects/micro-services/file-sftp-service/ftp-inbound/LONSBC01.20161214142000.10120CB.ACT}, timestamp=null, messageId=null, userId=null, receivedUserId=null, appId=null, clusterId=null, type=null, correlationId=null, correlationIdString=null, replyTo=null, contentType=text/plain, contentEncoding=UTF-8, contentLength=0, deliveryMode=null, receivedDeliveryMode=PERSISTENT, expiration=null, priority=0, redelivered=true, receivedExchange=raw-cdr, receivedRoutingKey=uk, receivedDelay=null, deliveryTag=1, messageCount=0, consumerTag=amq.ctag-15IUBH6oN_hheTvluP4YfQ, consumerQueue=uk-cdr.panel])
2016-12-16 07:46:03.717 WARN 81519 --- [cTaskExecutor-1] o.s.a.s.c.Jackson2JsonMessageConverter : Could not convert incoming message with content-type [text/plain]
2016-12-16 07:46:03.724 DEBUG 81519 --- [cTaskExecutor-1] .a.r.l.a.MessagingMessageListenerAdapter : Processing [GenericMessage [payload=byte[127], headers={amqp_receivedDeliveryMode=PERSISTENT, amqp_receivedRoutingKey=uk, amqp_contentEncoding=UTF-8, amqp_receivedExchange=raw-cdr, amqp_deliveryTag=1, file_name=/Users/shahbour/IdeaProjects/micro-services/file-sftp-service/ftp-inbound/LONSBC01.20161214142000.10120CB.ACT, amqp_consumerQueue=uk-cdr.panel, amqp_redelivered=true, id=c645580a-6f8d-6649-1426-14d06fbc1ddf, amqp_consumerTag=amq.ctag-15IUBH6oN_hheTvluP4YfQ, contentType=text/plain, timestamp=1481867163721}]]
在注释掉下面的 Jackson2JsonMessageConverter 之后,一切都运行良好。
@Bean
public MessageConverter jackson2json() {
return new Jackson2JsonMessageConverter();
}
即使在警告中声明它无法转换
【问题讨论】:
-
请显示您的侦听器容器工厂bean;还要开启 DEBUG 日志,如果你不能从日志中弄清楚,把日志贴在某个地方让我们看看。
-
@GaryRussell 应该声明
Jackson2JsonMessageConverter会导致上述效果还是一个错误? -
是的;看我的回答。
标签: spring-integration spring-amqp