cxf+jms
2015-11-09 00:12
253 查看
因为CXF(v2.2.3)原生提供的例子不友好,文档也不完整,摸索了几个小时,才发现问题,贴出来共飨。
服务端配置:
客户端配置:
服务端App:
public class ServerApp {
public static void main(String[] args) {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"server-applicationContext.xml");
}
}
客户端App:
public class ClientApp {
/**
* @param args
*/
public static void main(String[] args) {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"client-applicationContext.xml");
CustomerService hello = (CustomerService) applicationContext
.getBean("CustomerService");
System.out.println(hello.getOrder(null).getName());
}
}
Broker:
public final class EmbeddedBroker {
private EmbeddedBroker() {
}
public static void main(String[] args) throws Exception {
BrokerService broker = new BrokerService();
broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
broker.addConnector("tcp://localhost:61616");
broker.start();
System.out.println("JMS broker ready ");
Thread.sleep(125 * 60 * 1000);
System.out.println("JMS broker exiting");
broker.stop();
System.exit(0);
}
}
服务端配置:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:endpoint xmlns:customer="http://customerservice.service.test/" id="CustomerService" address="jms://localhost:61616" serviceName="customer:CustomerServiceService" endpointName="customer:CustomerServiceEndpoint" implementor="test.service.impl.CustomerServiceImpl"> <bean class="org.apache.cxf.transport.jms.jmsconfigfeature" p:jmsConfig-ref="jmsConfig" /> </bean class="org.apache.cxf.transport.jms.jmsconfigfeature" <bean id="jmsconfig" class="org.apache.cxf.transport.jms.JMSConfiguration" p:connectionFactory-ref="jmsConnectionFactory" p:targetDestination="test.cxf.jmstransport.queue" /> <bean id="jmsconnectionfactory" class="org.springframework.jms.connection.SingleConnectionFactory"> <bean class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerurl" value="tcp://localhost:61616" /> </property name="brokerurl" </property name="targetconnectionfactory"></bean id="jmsconnectionfactory" </bean id="jmsconfig" </import resource="classpath:meta-inf></import resource="classpath:meta-inf></import resource="classpath:meta-inf>
客户端配置:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:client id="customerservice" xmlns:customer="http://customerservice.service.test/" serviceName="customer:CustomerServiceService" endpointName="customer:CustomerServiceEndpoint" address="jms://localhost:61616" serviceClass="test.service.CustomerService"> <bean xmlns="http: www.springframework.org="" schema="" beans" class="org.apache.cxf.transport.jms.JMSConfigFeature" p:jmsConfig-ref="jmsConfig" /> </bean xmlns="http:> <bean id="jmsconfig" class="org.apache.cxf.transport.jms.JMSConfiguration" p:connectionFactory-ref="jmsConnectionFactory" p:targetDestination="test.cxf.jmstransport.queue" /> <bean id="jmsconnectionfactory" class="org.springframework.jms.connection.SingleConnectionFactory"> <bean class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerurl" value="tcp://localhost:61616" /> </property name="brokerurl" </property name="targetconnectionfactory"></bean id="jmsconnectionfactory" </bean id="jmsconfig" </jaxws:client id="customerservice" </import resource="classpath:meta-inf></import resource="classpath:meta-inf></import resource="classpath:meta-inf>
服务端App:
public class ServerApp {
public static void main(String[] args) {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"server-applicationContext.xml");
}
}
客户端App:
public class ClientApp {
/**
* @param args
*/
public static void main(String[] args) {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"client-applicationContext.xml");
CustomerService hello = (CustomerService) applicationContext
.getBean("CustomerService");
System.out.println(hello.getOrder(null).getName());
}
}
Broker:
public final class EmbeddedBroker {
private EmbeddedBroker() {
}
public static void main(String[] args) throws Exception {
BrokerService broker = new BrokerService();
broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
broker.addConnector("tcp://localhost:61616");
broker.start();
System.out.println("JMS broker ready ");
Thread.sleep(125 * 60 * 1000);
System.out.println("JMS broker exiting");
broker.stop();
System.exit(0);
}
}
相关文章推荐
- Map集合的遍历
- 写给初学者css优先级问题
- Hibernate无法自动创建数据库表
- 洛神赋
- fwrite和fread
- hdu 2030 统计汉字个数
- hibernate 中文查询时不执行
- 关于css3选择器的浏览器兼容性
- 直接选择排序
- jvm 对象查询语言(OQL)简介
- 凸优化
- 【JavaScript知识点七】 javascript 字符串函数
- Activity与WindowManagerService服务的连接过程分析
- jvm 对象查询语言(OQL)简介
- hibernate使用原生SQL查询返回结果集的处理
- Mac 效率工具
- Method Swizzling
- hiho 9 状态压缩二
- LintCode- 链表倒数第n个节点
- 解决 spring mvc 返回 json 时 在 ie 下提示下载问题