zoukankan      html  css  js  c++  java
  • [每日一学]apache camel|IBMWebsphere MQ header issue|MQRFH2 |MQSTR

     最近工作中,遇到一个很奇怪的问题:

    现象:在camel开发中,通过 IBM Websphere MQ 给assasin 发送xml的message时,会多出<mcd>等这样的header出来

    经查:


    Being that Camel is using the JMS API to write a message to an MQ queue, MQ will use the RHQ2 header to store information about the message, etc. However, the reading app is a non-JMS app, which cannot read the RFH2 header. We would like to strip the header by utilizing the targetClient=MQ in our put call, but this isn't working. We tried targetClient=1 as well

    原因是MQ自动加上这些header信息,而client端又无法识别,所以无法读取,出现异常。

    解决方案:

    在返回给client时,queue加上targetClient=1 ,告诉MQ驱动,不要发送header信息。


    <route id="qname">
    <from uri="amq:queue:qname" />
    <transacted ref="requiredJta" />
    <to uri="log:com.wellsfargo.1txc?showHeaders=true&amp;showBody=false&amp;multiline=false&amp;level=INFO"/>
    <setHeader headerName="CamelJmsDestinationName"><constant>queue:///qname?targetClient=1</constant></setHeader>
    <to uri="wmq:queue:qname" />
    </route>

    另一种方案:

    用这个类配置在jmsConfiguartion类里:

    https://jira.spring.io/secure/attachment/12688/IBMWebSphereMqDestinationResolver.java

    example code :

    ==============================================================================

    package org.springframework.jms.support.destination;
    
    import javax.jms.Destination;
    import javax.jms.JMSException;
    import javax.jms.Session;
    
    import com.ibm.mq.jms.JMSC;
    import com.ibm.mq.jms.MQDestination;
    
    
    /**
     * 
     * Dynamic destination resolver which can set some IBM WebSphere MQ
     * specific properties.
     * 
     * @author <a href="mailto:david@davidkarlsen.com">David J. M. Karlsen</a>
     * @see com.ibm.mq.jms.JMSC
     * @see DestinationResolver
     * @see DynamicDestinationResolver
     *
     */
    public class IBMWebSphereMqDestinationResolver 
        extends DynamicDestinationResolver
        implements DestinationResolver
    {
        private int ccsid = 819;
        private int encoding = JMSC.MQJMS_ENCODING_NATIVE;
        private int failIfQuiesce = JMSC.MQJMS_FIQ_YES;
        private int targetClient = JMSC.MQJMS_CLIENT_JMS_COMPLIANT;
       
        /**
         * @param ccsid
         * Character set for automatic conversion of message payload.
         * <p>
         * Defaults to com.ibm.mq.jms.JMSC.MQJMS_FIQ_YES
         */
        public void setCcsid( int ccsid )
        {
            this.ccsid = ccsid;
        }
        /**
         * @param encoding
         * Encoding for message payload.
         * <p>
         * Defaults to com.ibm.mq.jms.JMSC.MQJMS_ENCODING_NATIVE
         */
        public void setEncoding( int encoding )
        {
            this.encoding = encoding;
        }
        /**
         * @param failIfQuiesce
         * 
         * Control graceful exits when queue manager is quesing.
         * <p>
         * Defaults to com.ibm.mq.jms.JMSC.MQJMS_FIQ_YES
         */
        public void setFailIfQuiesce( int failIfQuiesce )
        {
            this.failIfQuiesce = failIfQuiesce;
        }
        /**
         * @param targetClient
         * Control target client type (JMS compliant or not).
         * <p>
         * Defaults to com.ibm.mq.jms.JMSC.MQJMS_CLIENT_JMS_COMPLIANT
         */
        public void setTargetClient( int targetClient )
        {
            this.targetClient = targetClient;
        }
        protected int getCcsid()
        {
            return ccsid;
        }
        protected int getEncoding()
        {
            return encoding;
        }
        protected int getFailIfQuiesce()
        {
            return failIfQuiesce;
        }
        protected int getTargetClient()
        {
            return targetClient;
        }
        
        /**
         * {@inheritDoc}
         * @see DestinationResolver#resolveDestinationName(Session, String, boolean)
         */
        public Destination resolveDestinationName( Session session, 
                                                   String destinationName, 
                                                   boolean isPubSubDomain ) 
            throws JMSException
        {
    
            Destination destination = super.resolveDestinationName( session, destinationName, isPubSubDomain );
            if ( destination instanceof MQDestination )
            {
                MQDestination mqDestination = (MQDestination) destination;
                mqDestination.setCCSID( getCcsid() );
                mqDestination.setEncoding( getEncoding() );
                mqDestination.setFailIfQuiesce( getFailIfQuiesce() );
                mqDestination.setTargetClient( getTargetClient() );
            }
            
            return destination;
        }
    
    }
    ===============================================================================================================

    其中代码:private int targetClient = JMSC.MQJMS_CLIENT_JMS_COMPLIANT;

    要改成:   private int targetClient = JMSC.MQJMS_CLIENT_NONJMS_MQ;

    本人精通java高并发,DDD,微服务等技术实践,专注java,rust技术栈。 本人姓名郭莹城,坐标深圳,前IBM架构师、咨询师、敏捷开发技术教练,前IBM区块链研究小组成员、十多年架构设计工作经验,《区块链核心技术与应用》作者之一, 现聚焦于:区块链创投与交易所资源对接和技术咨询。 工作微信&QQ:360369487,区块链创投与交易所资源对接,加我注明:博客园+对接,技术咨询和顾问,加我注明:博客园+顾问。想学习golang和rust的同学,也可以加我微信,备注:博客园+golang或博客园+rust,谢谢!
  • 相关阅读:
    HttpApplication处理对象与HttpModule处理模块
    HttpHandler与HttpModule的用处与区别
    ASP.NET管线与应用程序生命周期
    IIS架构与HTTP请求处理流程
    构造函数的选择与服务生命周期管理
    堆排序
    WebApi异常
    Java NIO内存映射---上G大文件处理(转)
    Spring+Mybatis+SpringMVC后台与前台分页展示实例(附工程)(转)
    redis入门(转)
  • 原文地址:https://www.cnblogs.com/gyc567/p/5343512.html
Copyright © 2011-2022 走看看