迷途書童

          敏感、勤學、多思
          隨筆 - 77, 文章 - 4, 評論 - 86, 引用 - 0
          數據加載中……

          CXF使用JMS作為傳輸協議的配置


          因為CXF(v2.2.3)原生提供的例子不友好,文檔也不完整,摸索了幾個小時,才發現問題,貼出來共饗。
          服務端配置:
          <beans xmlns="http://www.springframework.org/schema/beans"
              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"
          >

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

              
          <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">
                  
          <jaxws:features>
                      
          <bean class="org.apache.cxf.transport.jms.JMSConfigFeature"
                          p:jmsConfig-ref
          ="jmsConfig" />
                  
          </jaxws:features>
              
          </jaxws:endpoint>

              
          <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">
                  
          <property name="targetConnectionFactory">
                      
          <bean
                          
          class="org.apache.activemq.ActiveMQConnectionFactory">
                          
          <property name="brokerURL"
                              value
          ="tcp://localhost:61616" />
                      
          </bean>
                  
          </property>
              
          </bean>

          </beans>
          客戶端配置:
          <beans xmlns="http://www.springframework.org/schema/beans"
              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"
          >

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

              
          <jaxws:client id="CustomerService"
                  xmlns:customer
          ="http://customerservice.service.test/"
                  serviceName
          ="customer:CustomerServiceService"
                  endpointName
          ="customer:CustomerServiceEndpoint"
                  address
          ="jms://localhost:61616"
                  serviceClass
          ="test.service.CustomerService">
                  
          <jaxws:features>
                      
          <bean xmlns="http://www.springframework.org/schema/beans"
                          class
          ="org.apache.cxf.transport.jms.JMSConfigFeature"
                          p:jmsConfig-ref
          ="jmsConfig" />
                  
          </jaxws:features>
              
          </jaxws:client>

              
          <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">
                  
          <property name="targetConnectionFactory">
                      
          <bean
                          
          class="org.apache.activemq.ActiveMQConnectionFactory">
                          
          <property name="brokerURL"
                              value
          ="tcp://localhost:61616" />
                      
          </bean>
                  
          </property>
              
          </bean>

          </beans>
          服務端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);
              }
          }

          posted on 2009-08-30 21:50 迷途書童 閱讀(2974) 評論(0)  編輯  收藏 所屬分類: java應用SOA

          主站蜘蛛池模板: 饶阳县| 东明县| 濉溪县| 大方县| 红河县| 丹江口市| 鄂伦春自治旗| 洛南县| 阿鲁科尔沁旗| 孟连| 涡阳县| 南澳县| 邛崃市| 丰原市| 虎林市| 章丘市| 神农架林区| 思南县| 武陟县| 岱山县| 海门市| 酉阳| 灵寿县| 南投市| 三台县| 丹东市| 富平县| 双峰县| 铁力市| 吉隆县| 肇州县| 久治县| 定陶县| 乡城县| 松原市| 微山县| 阿拉善盟| 绥宁县| 安顺市| 祁连县| 桃园市|