出於某種原因RabbitListener正顯示出實際的字符串,而不是ASCII表示RabbitListener返回字符串作爲ASCII而不是字符串
兔MQ消息
交易所原始CDR
路由關鍵英國
Redelivered
priority:0delivery_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在應用程序上下文聲明
請顯示您的監聽器容器工廠bean;還打開DEBUG日誌記錄,如果你不能從日誌中找出它,請將日誌發佈到某個地方,以便我們可以看一看。 –
@GaryRussell應該在上面的效果中聲明'Jackson2JsonMessageConverter'結果還是bug? – Shahbour
是的;看到我的答案。 –