2016-12-15 222 views
0

出于某种原因RabbitListener正显示出实际的字符串,而不是ASCII表示RabbitListener返回字符串作为ASCII而不是字符串

兔MQ消息

交易所原始CDR

路由关键英国

Redelivered
priority:0

delivery_mode:2

头:

FILE_NAME:/Users/shahbour/IdeaProjects/micro-services/file-sftp-service/ftp-inbound/LONSBC01.20161214142000.10120CB.ACT

content_encoding:UTF-8

CONTENT_TYPE:文本/无格式

思网络,Inc.00000000FF 600000520000000000000128V04.02.05R000 0000000000000000000000000000ACT2016121414100000000000000000

,但我得到的是

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

下面是我使用的代码,每一件事情是春天开机默认

@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(); 
    } 

即使在警告有人宣称它不能转换如果MessageConverter型的一个bean在应用程序上下文声明

+0

请显示您的监听器容器工厂bean;还打开DEBUG日志记录,如果你不能从日志中找出它,请将日志发布到某个地方,以便我们可以看一看。 –

+0

@GaryRussell应该在上面的效果中声明'Jackson2JsonMessageConverter'结果还是bug? – Shahbour

+0

是的;看到我的答案。 –

回答

0

春天开机时会自动配置监听器容器适配器的消息变换。

该转换器预计的内容类型为application/json

如果您有一些消息是text/plain,有些消息是application/json,则应该配置一个ContentTypeDelegatingMessageConverter以及一个SimpleMessageConverter和JSON转换器。

+0

感谢您的解释 – Shahbour

相关问题