您的位置:首页 > 其它

cxf+jms

2015-11-09 00:12 253 查看
因为CXF(v2.2.3)原生提供的例子不友好,文档也不完整,摸索了几个小时,才发现问题,贴出来共飨。

服务端配置:

     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);

     }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: