2017-03-29 2 views
1

스프링 통합 JMS 메시지 기반 채널 어댑터를 사용하여 IBM MQ에서 메시지를 보내거나 읽도록 코드를 작성했지만 JMS 텍스트 응답 메시지를 구문 분석 할 수 없습니다. 아래는 내 통합입니다. XML스프링 통합 IBM MQ JMS 클라이언트

<?xml version="1.0" encoding="UTF-8"?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:int="http://www.springframework.org/schema/integration" 
     xmlns:int-jms="http://www.springframework.org/schema/integration/jms" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd 
      http://www.springframework.org/schema/integration 
      http://www.springframework.org/schema/integration/spring-integration.xsd 
      http://www.springframework.org/schema/integration/jms 
      http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd"> 

     <context:annotation-config /> 
     <context:component-scan base-package="com.*****" /> 

     <!-- Factory Defintions --> 
     <bean id="connectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory"> 
      <property name="transportType" value="1" /> 
      <property name="queueManager" value="****" /> 
      <property name="hostName" value="******" /> 
      <property name="port" value="****" /> 
      <property name="channel" value="******" /> 
     </bean> 

     <!-- Queue Definition --> 
     <bean id="inQueue" class="com.ibm.mq.jms.MQQueue" depends-on="connectionFactory"> 
      <constructor-arg index="0" value="****" /> 
      <constructor-arg index="1" value="*****" /> 
     </bean> 

     <bean id="outQueue" class="com.ibm.mq.jms.MQQueue" depends-on="connectionFactory"> 
      <constructor-arg index="0" value="*****" /> 
      <constructor-arg index="1" value="******" /> 
     </bean> 

     <bean id="messageListener" class="com.***.MessageListener"/> 
     <bean id="messagePublisher" class="com.*****.MessagePublisher"/> 

     <!-- OUTBOUND settings --> 

     <int:channel id="senderChannel" /> 

     <int-jms:outbound-channel-adapter id="jmsOut" destination="outQueue" channel="senderChannel"/> 

     <!-- <int:service-activator output-channel="senderChannel" ref="messagePublisher" method="processMessage" /> --> 

     <!-- INBOUND settings --> 

     <int:channel id="recieverChannel" />  

     <int-jms:message-driven-channel-adapter id="jmsIn" destination="inQueue" channel="recieverChannel" extract-payload="false" /> 

     <int:service-activator input-channel="recieverChannel" ref="messageListener" method="processMessage" /> 

    </beans> 

과정은 외부 서버에 MQ를 통해 메시지를 보낼 계획하고는 ACK와 함께 (또는 응답하지 않을 수 있습니다) 할 수 있습니다.

게시자 코드 : 내 청취자의 현재

import org.springframework.beans.factory.annotation.Autowired; 
    import org.springframework.integration.support.MessageBuilder; 
    import org.springframework.messaging.MessageChannel; 

    public class MessagePublisher { 

     @Autowired 
     private MessageChannel senderChannel; 

     public void processMessage(String message) { 
      System.out.println("MessagePublisher::::::Sent message: " + message); 

      senderChannel.send(MessageBuilder.withPayload(message).build()); 
     } 
    } 

내가으로 ACK를 인쇄하려고 :

import javax.jms.JMSException; 
    import javax.jms.Message; 
    import javax.jms.TextMessage; 

    public class MessageListener { 

     public void processMessage(Message message) { 

      if (message instanceof TextMessage) { 
       TextMessage txtmsg = (TextMessage) message; 

       try { 

        System.out.println("MessageListener::::::Received message: " 
          + txtmsg.getText()); 
       } catch (JMSException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
      } 
     } 
내가 몸 메시지를 다시받을 때 문제가

가로 인코딩 된 문자열을 포함

MessageListener ::::::받은 메시지 : [여기에 인코딩 된 특수 문자를 인쇄하십시오]

전체 응답 텍스트를 적절한 형식으로 어떻게 파싱 할 수 있습니까? 나는 응답 객체의 인스턴스가 JMS 텍스트 메시지 인 것처럼 보였지만, 콘솔에 출력되었을 때 나는 단지 인코딩 된 문자열 메시지만을 보았다.

+0

인코딩 알고리즘을 알지 못하므로 void를 구문 분석하는 데 도움이되지 않습니다. 해당 메시지의 내용에 대한 자세한 정보를 제공해주십시오. –

+0

메시지는 단순히 외부 JMS 서버로 전송 된 "테스트 메시지"입니다. 받은 ack은 본문 텍스트와 함께 JMS 헤더가 있습니다. 헤더를 잘 읽을 수 있지만 본문 텍스트가 암호화되어 있고 모든 특수 문자이므로 여기에 붙여 넣을 수 없습니다 (바이트 메시지처럼 보입니다.)) 그러나 응답을 보아서 그것의 특별한 IBm 인코딩 만인지 나는 확신 할 수 없다. –

+0

그래서, "외부 서버"에 그들이 당신에게 보내는 것을 물어보십시오! 이 문제는 도구 사용과 관련이 없으므로 여기에서 어떤 도움을 원하십니까? 이것은 단지 비즈니스 프로세스와 데이터 형식입니다. –

답변

0

확인.

byte[] by = ((TextMessage) msg).getText().getBytes("ISO-8859-1"); 
String text = new String(by,"UTF-8"); 

더 많은 정보는 여기에 있습니다 : : Encoding a JMS TextMessagehere

이 시도 : 나는 당신의 문제는 보낸 사람과받는 사람에 대한 다른 character encoding, 정말 생각합니다.