迷途书童

敏感、勤学、多思
随笔 - 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 迷途书童 阅读(2953) 评论(0)  编辑  收藏 所属分类: java应用SOA


只有注册用户登录后才能发表评论。


网站导航: