迷途書童

          敏感、勤學、多思
          隨筆 - 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

          主站蜘蛛池模板: 兴化市| 饶阳县| 叙永县| 遂川县| 遂宁市| 鄄城县| 谢通门县| 彭阳县| 建宁县| 靖西县| 元阳县| 玛曲县| 道真| 漾濞| 贡觉县| 兴义市| 南阳市| 睢宁县| 股票| 咸阳市| 郴州市| 林甸县| 台中县| 扶绥县| 崇明县| 陇南市| 新宁县| 格尔木市| 乃东县| 海盐县| 大邑县| 广灵县| 嘉祥县| 宜兰县| 崇阳县| 苍梧县| 皋兰县| 德昌县| 弥勒县| 东兴市| 漳平市|