0.POM依赖

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yun.base</groupId>
<artifactId>cxf</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>cxf_jms_server</artifactId> <properties>
<cxf.version>3.1.12</cxf.version>
<spring.version>4.2.5.RELEASE</spring.version>
<slf4j.version>1.7.7</slf4j.version>
<logback.version>1.1.2</logback.version>
<websphereMq.version>5.3.07</websphereMq.version>
<!-- 本地jar目录 -->
<wmq.jars>E:/installFile/ibmmq</wmq.jars>
</properties>
<dependencies>
<!-- springmvc start -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- springmvc end --> <!-- logback -->
<dependency>
<!--主要介绍的是这个jar包,这个包是负责logback随着项目启动的jar包-->
<groupId>org.logback-extensions</groupId>
<artifactId>logback-ext-spring</artifactId>
<version>0.1.4</version>
</dependency>
<!-- slf4j start -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<!-- slf4j end --> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.12</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-jms</artifactId>
<version>3.1.12</version>
</dependency>
<dependency>
<groupId>org.apache.cxf.xjc-utils</groupId>
<artifactId>cxf-xjc-runtime</artifactId>
<version>3.0.5</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency> <!--Websphere MQ dependencies--> <dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mqjms</artifactId>
<version>${websphereMq.version}</version>
<scope>system</scope>
<systemPath>${wmq.jars}/com.ibm.mqjms.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mq.headers</artifactId>
<version>${websphereMq.version}</version>
<scope>system</scope>
<systemPath>${wmq.jars}/com.ibm.mq.headers.jar</systemPath>
</dependency> <dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mq.jmqi</artifactId>
<version>${websphereMq.version}</version>
<scope>system</scope>
<systemPath>${wmq.jars}/com.ibm.mq.jmqi.jar</systemPath>
</dependency> <dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.dhbcore</artifactId>
<version>${websphereMq.version}</version>
<scope>system</scope>
<systemPath>${wmq.jars}/dhbcore.jar</systemPath>
</dependency> <!--Spring--> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
<version>1.1.1</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency> <!--Javax Servlet API--> <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency> </dependencies> </project>

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\cxf_jms_server\src\main\java cxf\EsbJmsServer.wsdl

3.服务端服务转发拦截器

package com.srcb.esb.interceptor;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.util.List;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;
import org.apache.cxf.Bus;
import org.apache.cxf.binding.Binding;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.SoapVersion;
import org.apache.cxf.binding.soap.SoapVersionFactory;
import org.apache.cxf.bus.CXFBusFactory;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.endpoint.ServerRegistry;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.InterceptorChain;
import org.apache.cxf.interceptor.StaxInInterceptor;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.service.Service;
import org.apache.cxf.staxutils.DepthXMLStreamReader;
import org.apache.cxf.staxutils.StaxUtils; public class MediatorInterceptor extends
AbstractPhaseInterceptor<SoapMessage> { public MediatorInterceptor() {
super(Phase.POST_STREAM);
addBefore(StaxInInterceptor.class.getName());
} public void handleMessage(SoapMessage message) throws Fault { /* =======================解析报文的命名空间================================= */
String schemaNamespace = "";
try {
// create a buffered stream so that we get back the original stream
// after scaning
InputStream is = message.getContent(InputStream.class);
BufferedInputStream pis = new BufferedInputStream(is);
pis.mark(pis.available());
message.setContent(InputStream.class, pis); String encoding = (String) message.get(Message.ENCODING);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(pis, encoding);
DepthXMLStreamReader xmlReader = new DepthXMLStreamReader(reader);
if (xmlReader.nextTag() == XMLStreamConstants.START_ELEMENT) {
String ns = xmlReader.getNamespaceURI();
SoapVersion soapVersion = SoapVersionFactory.getInstance().getSoapVersion(ns);
StaxUtils.toNextTag(xmlReader, soapVersion.getBody());
xmlReader.nextTag();
}
schemaNamespace = xmlReader.getName().getNamespaceURI();
pis.reset();
} catch (Exception e) {
e.printStackTrace();
} /* =======================根据Namespace选取对应的Endpoint================================== */
Bus bus = CXFBusFactory.getDefaultBus();
ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class);
List<Server> servers = serverRegistry.getServers(); Endpoint ep = null;
for (Server server : servers) {
ep = server.getEndpoint();
if (schemaNamespace.startsWith(ep.getEndpointInfo().getName().getNamespaceURI())) {
break;
} else {
ep = null;
}
}
if (ep == null) {
return;
} /* =======================设置新Endpoint================================== */
Exchange ex = message.getExchange();
ex.put(Endpoint.class, ep);
ex.put(Binding.class, ep.getBinding());
ex.put(Service.class, ep.getService()); // set for PE's OperationId(see ServiceDispatcher.java)
ex.put(javax.xml.ws.Endpoint.WSDL_SERVICE, ep.getService().getName()); InterceptorChain chain = message.getInterceptorChain();
chain.add(ep.getInInterceptors());
chain.add(ep.getBinding().getInInterceptors());
chain.add(ep.getService().getInInterceptors());
chain.setFaultObserver(ep.getOutFaultObserver());
}
}

4.配置服务端

<?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="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>
<property name="connectionNameList" value="10.16.24.180(11101)"></property>
<property name="CCSID" value="1381"></property>
<property name="transportType" value="1"></property>
</bean>
</property>
</bean> <jaxws:endpoint id="esbJmsServer1"
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="esbJmsServerJmsConfig1" />
</property>
</bean>
</jaxws:features>
<jaxws:inInterceptors>
<bean class="com.srcb.esb.interceptor.MediatorInterceptor"></bean>
</jaxws:inInterceptors>
</jaxws:endpoint> <bean id="esbJmsServerJmsConfig1" class="org.apache.cxf.transport.jms.JMSConfiguration"
p:connectionFactory-ref="jmsConnectionFactory1" p:targetDestination="LOCALQ.P.FXMS.REQ"
/> <bean id="jmsConnectionFactory1"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="com.ibm.mq.jms.MQConnectionFactory">
<property name="channel" value="SYSTEM.DEF.SVRCONN"></property>
<property name="connectionNameList" value="10.16.24.181(12101)"></property>
<property name="CCSID" value="1381"></property>
<property name="transportType" value="1"></property>
</bean>
</property>
</bean> </beans>

5.生成客户端代码

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

6.配置客户端

<?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="CCSID" value="1381"></property>
<property name="transportType" value="1"></property>
</bean>
</property>
</bean>
</beans>

IBM MQ 集成CXF 发送JMS 消息的更多相关文章

  1. SpringBoot 对IBM MQ进行数据监听接收以及数据发送

    一.需求介绍 后端使用Spring Boot2.0框架,要实现IBM MQ的实时数据JMS监听接收处理,并形成回执通过MQ队列发送. 二.引入依赖jar包 <dependency> < ...

  2. IBM MQ消息中间件jms消息中RHF2消息头的处理

    公司的技术平台在和某券商对接IBM MQ消息中间件时,发送到MQ中的消息多出了消息头信息:RHF2,造成消息的接收处理不正常.在此记录此问题的处理方式. 在IBM MQ中提供了一个参数 targetC ...

  3. spring监听与IBM MQ JMS整合

    spring xml 的配置: 文件名:applicationContext-biz-mq.xml <?xml version="1.0" encoding="UT ...

  4. IBM Mq Spring JMS 的xml配置

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  5. IBM MQ + WebSphere + Spring JMS配置方法

    IBM MQ + WebSphere + Spring JMS配置方法  首先要在WAS里面配置IBM MQ作为JMS消息的提供者,在WAS管理控制台: Resources->JMS Provi ...

  6. Oozie 生成JMS消息并向 JMS Provider发送消息过程分析

    一,涉及到的工程 从官网下载源码,mvn 编译成 Eclipse工程文件:

  7. MQ系列5:RocketMQ消息的发送模式

    MQ系列1:消息中间件执行原理 MQ系列2:消息中间件的技术选型 MQ系列3:RocketMQ 架构分析 MQ系列4:NameServer 原理解析 在之前的篇章中,我们学习了RocketMQ的原理, ...

  8. MQ发送定时消息

    通过延时发送来发送定时消息. RocketMQ只支持固定精度时间的延时消息发送:1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h 若 ...

  9. IBM MQ 使用指南

    一.MQ基本操作 MQ中有几个很重要的组件:队列管理器(QueueManager).队列(Queue)和通道(Channel).其基本的操作方法如下:  1)创建队列管理器 crtmqm –q QMg ...

随机推荐

  1. yarn hadoop-2.3.0 installation cluster Centos 64bits

    Apache Hadoop -2.2.0 - How to Install a Three Nodes Cluster http://tonylixu.blogspot.ca/2014/02/apac ...

  2. Confluence 6 为边栏添加自定义内容

    你可以使用 wiki 标记和自定义内容来对边栏进行更进一步的自定义. 希望添加自定义内容到你的边栏中: 进入空间后,然后从边栏的底部选择 空间工具(Space tools) > 外观和感觉(Lo ...

  3. PHP设计模式注意点

    PHP命名空间 可以更好地组织代码,与Java中的包类似. Test1.php <?php namespace Test1;//命名空间Test1 function test(){ echo _ ...

  4. 【洛谷p1012】拼数

    (今天yuezhuren大课间放我们出来了……) (另外今天回了两趟初中部) 拼数[传送门] 洛谷算法标签: (然鹅这两个学的都不好,能过真的how strange) 开始的时候没读题啊,直接暴力so ...

  5. tcpcopy真实流量压测工具

    https://quentinxxz.iteye.com/blog/2249799 http://blog.chinaunix.net/uid-25057421-id-5576741.html htt ...

  6. ie8不支持currentTarget的解决办法

    一般绑定事件时,我们都会在事件回调方法里用event.currentTarget获取当前对象,但到ie8里就获取不到了. 解决方法如下: var eve = event || window.event ...

  7. 51nod-1181-两次筛法

    1181 质数中的质数(质数筛法)  题目来源: Sgu 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 如果一个质数,在质数列表中的编号也是质数,那么就 ...

  8. logmnr使用

    logminer 工具的使用 Oracle LogMiner 是Oracle公司从产品8i以后提供的一个实际非常有用的分析工具,使用该工具可以轻松获得Oracle 重作日志文件(归档日志文件)中的具体 ...

  9. Space Ant

    Space Ant The most exciting space discovery occurred at the end of the 20th century. In 1999, scient ...

  10. Django之自定义分页

    分页功能在每个网站都是必要的,对于分页来说,其实就是根据用户的输入计算出应该显示在页面上的数据在数据库表中的起始位置. 1. 每页显示的数据条数 2. 每页显示页号链接数 3. 上一页和下一页 4. ...