1. 程式人生 > >IBM MQ 集成CXF 發送JMS 消息

IBM MQ 集成CXF 發送JMS 消息

tty eply atomic instance prop ans rop cep 連接

1.修改wsdl 協議類型為 jms

替換

<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<soap:binding style="document" transport="http://cxf.apache.org/transports/jms"/>

2.根據wsdl生成服務端代碼,前提安裝cxf,請參看 http://www.cnblogs.com/yun965861480/p/7400552.html

wsdl2java -server -impl -encoding UTF8 -d E:\work\waikuai\pom\cxf\src\main\java cxf\EsbJmsServer.wsdl

3.配置服務端

<?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:cxf="http://cxf.apache.org/core"
    xmlns:soap="http://cxf.apache.org/bindings/soap" xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:jms
="http://cxf.apache.org/transports/jms" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://
cxf.apache.org/bindings/soap http://cxf.apache.org/schema/bindings/soap.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/transports/jms http://cxf.apache.org/schemas/configuration/jms.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <jaxws:endpoint id="esbJmsServer" implementor="com.midea.service.fxms.abstraction.atomic.technology_esbjmsserver.v1.EsbJmsServerPortImpl" address="jms://"> <jaxws:properties> <entry key="org.apache.cxf.message.Message.ENCODING" value="UTF-8" /> </jaxws:properties> <jaxws:features> <bean class="org.apache.cxf.feature.LoggingFeature" /> <bean class="org.apache.cxf.transport.jms.JMSConfigFeature"> <property name="jmsConfig"> <ref bean="esbJmsServerJmsConfig" /> </property> </bean> </jaxws:features> <jaxws:inInterceptors> <bean class="com.srcb.esb.interceptor.MediatorInterceptor"></bean> </jaxws:inInterceptors> </jaxws:endpoint> <bean id="esbJmsServerJmsConfig" class="org.apache.cxf.transport.jms.JMSConfiguration" p:connectionFactory-ref="jmsConnectionFactory" p:targetDestination="LOCALQ.P.FXMS.REQ" /> <bean id="jmsConfig" class="org.apache.cxf.transport.jms.JMSConfiguration" p:connectionFactory-ref="jmsConnectionFactory" p:targetDestination="LOCALQ.P.ESBPRO.REQ" /> <bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"> <property name="targetConnectionFactory"> <bean class="com.ibm.mq.jms.MQConnectionFactory"> <property name="channel" value="SYSTEM.DEF.SVRCONN"></property> <!-- MQ網關集群,多個以逗號隔開 --> <property name="connectionNameList" value="10.16.24.180(11101),10.16.24.181(12101)"></property> <property name="CCSID" value="1381"></property> <property name="transportType" value="1"></property> </bean> </property> </bean> </beans>

4.生成客戶端代碼

wsdl2java -client -impl -encoding UTF8 -d E:\work\waikuai\pom\cxf\cxf_jms_client\src\main\java cxf\EsbJmsServer.wsdl

5.配置客戶端

<?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:cxf="http://cxf.apache.org/core"
    xmlns:soap="http://cxf.apache.org/bindings/soap" xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:jms="http://cxf.apache.org/transports/jms" xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
                        http://cxf.apache.org/bindings/soap http://cxf.apache.org/schema/bindings/soap.xsd
                        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
                        http://cxf.apache.org/transports/jms http://cxf.apache.org/schemas/configuration/jms.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />


<!-- utf-8 配置,和 日誌配置 -->
    <cxf:bus>
        <cxf:properties>
             <entry key="org.apache.cxf.message.Message.ENCODING" value="UTF-8" />
        </cxf:properties>
        <cxf:features>
            <cxf:logging/>
        </cxf:features>
    </cxf:bus>
    
    <jaxws:client id="esbJmsServerClient"
        xmlns:s="http://fxms.service.midea.com/abstraction/atomic/technology.EsbJmsServer/v1"
        serviceClass="com.midea.service.fxms.abstraction.atomic.technology_esbjmsserver.v1.EsbJmsServerPortType"
        serviceName="s:EsbJmsServer" endpointName="s:EsbJmsServerPort"
        wsdlLocation="classpath:cxf/EsbJmsServer.wsdl" address="jms://">
        <jaxws:properties>
            <!-- 修改默認的SOAP編碼 -->
            <entry key="org.apache.cxf.message.Message.ENCODING" value="UTF-8" />
        </jaxws:properties>
        <jaxws:features>
            <!-- 增加日誌特征 -->
            <bean class="org.apache.cxf.feature.LoggingFeature" />
            <!-- 註入JMS配置對象 -->
            <bean class="org.apache.cxf.transport.jms.JMSConfigFeature">
                <property name="jmsConfig">
                    <ref bean="ftmsJmsConfiguration" />
                </property>
            </bean>
        </jaxws:features>
    </jaxws:client>
    

    <bean id="ftmsJmsConfiguration" class="org.apache.cxf.transport.jms.JMSConfiguration"
        p:connectionFactory-ref="jmsConnectionFactory" p:targetDestination="LOCALQ.C.FTMS.REQ"
        p:replyDestination="LOCALQ.FTMS.RSP">
        <!-- 超時時間(ms) -->
        <property name="receiveTimeout" value="80000"></property>
        <!-- 消息持久性:1表示非持久;2表示持久;默認為2 -->
        <property name="deliveryMode" value="1"></property>
        <property name="explicitQosEnabled" value="true"></property>
    </bean>
    

    <bean id="jmsConnectionFactory"
        class="org.springframework.jms.connection.SingleConnectionFactory">
        <property name="targetConnectionFactory">
            <bean class="com.ibm.mq.jms.MQConnectionFactory">
                <property name="channel" value="SYSTEM.DEF.SVRCONN"></property>
                <!-- 16777216:不同隊列管理器名;67108864:相同隊列管理器名 -->
                <property name="clientReconnectOptions" value="16777216"></property>
                <!-- 隊列管理器IP及PORT列表,優先連接第1個地址 -->
                <property name="connectionNameList" value="10.16.24.180(11001),10.16.24.181(12001)"></property>
<!--                 <property name="connectionNameList" value="10.16.12.98(11001),10.16.12.99(12001)"></property> -->
                <!-- <property name="connectionNameList" value="10.16.13.122(11001)"></property> -->
<!--                 <property name="connectionNameList" value="10.16.10.72(11001)"></property> -->
<!--                 <property name="connectionNameList" value="127.0.0.1(11001)"></property> -->
                <property name="CCSID" value="1381"></property>
                <property name="transportType" value="1"></property>
            </bean>
        </property>
    </bean>
</beans>

IBM MQ 集成CXF 發送JMS 消息