如何在 Apache Camel 中使用 AMQP 而不是 JMS?
问候大家 我使用具有以下配置的 JMS 在客户端和客户端之间发送消息服务器,我需要用AMQP替换jms,我需要一些指导,所以请告知:
client-applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring-1.4.0.xsd
http://cxf.apache.org/transports/camel http://cxf.apache.org/transports/camel.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-camel.xml" />
<!-- Directly defined ConnectionFactory -->
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<!-- By defining a JmsComponent called jms you can use the JMS transport in routes
You may define several of these components if you have different JMS servers for
different services. They can be distinguished in the routes by their id
-->
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="useMessageIDAsCorrelationID" value="true" />
</bean>
<!-- Add the camel transport to CXF. So you can define endpoint in the form camel://direct:<EndpointName>
in cxf client and server endpoints. These endpoints are then available in camel
as direct:<EndpointName> -->
<bean class="org.apache.camel.component.cxf.transport.CamelTransportFactory">
<property name="bus" ref="cxf" />
<property name="camelContext" ref="camelContext" />
<property name="transportIds">
<list>
<value>http://cxf.apache.org/transports/camel</value>
</list>
</property>
</bean>
<!-- Define a cxf endpoint based on client stub generated from a wsdl.
It is important to provide serviceName and endpointName so the wsdl is not needed
at runtime. As far as I know the serviceName and endpointName do not have to have a special
convention but it is good practice to use the service namespace and Service Interface name in the names
-->
<client id="CustomerService" xmlns="http://cxf.apache.org/jaxws" xmlns:customer="http://customerservice.example.com/"
serviceName="customer:CustomerServiceService" endpointName="customer:CustomerServiceEndpoint"
address="camel://direct:CustomerService" serviceClass="com.example.customerservice.CustomerService">
<features>
<!-- Enables logging of SOAP messages. -->
<!-- <logging xmlns="http://cxf.apache.org/core" /> -->
</features>
</client>
<!-- This context defines a route for each endpoint. For client endpoints you route from
the cxf endpoint to the jms queue or topic. For servers you route from the jms queue or
topic to the cxf endpoint -->
<camelContext id="camelContext" xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="direct:CustomerService" />
<to uri="jms://queue:CustomerService" />
</route>
</camelContext>
</beans>
server-applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring-1.4.0.xsd
http://cxf.apache.org/transports/camel http://cxf.apache.org/transports/camel.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-camel.xml" />
<!-- Directly defined ConnectionFactory -->
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<!-- By defining a JmsComponent called jms you can use the JMS transport in routes
You may define several of these components if you have different JMS servers for
different services. They can be distinguished in the routes by their id
-->
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="useMessageIDAsCorrelationID" value="true" />
</bean>
<!-- Add the camel transport to CXF. So you can define endpoint in the form camel://direct:<EndpointName>
in cxf client and server endpoints. These endpoints are then available in camel
as direct:<EndpointName> -->
<bean class="org.apache.camel.component.cxf.transport.CamelTransportFactory">
<property name="bus" ref="cxf" />
<property name="camelContext" ref="camelContext" />
<property name="transportIds">
<list>
<value>http://cxf.apache.org/transports/camel</value>
</list>
</property>
</bean>
<!-- Define a cxf endpoint based on client stub generated from a wsdl.
It is important to provide serviceName and endpointName so the wsdl is not needed
at runtime. As far as I know the serviceName and endpointName do not have to have a special
convention but it is good practice to use the service namespace and Service Interface name in the names
-->
<endpoint
xmlns="http://cxf.apache.org/jaxws"
xmlns:customer="http://customerservice.example.com/"
id="CustomerService"
address="camel://direct:CustomerService"
serviceName="customer:CustomerServiceService"
endpointName="customer:CustomerServiceEndpoint"
implementor="com.example.customerservice.impl.CustomerServiceImpl">
<features>
<!-- Enables logging of SOAP messages. -->
<logging xmlns="http://cxf.apache.org/core" />
</features>
</endpoint>
<!-- This context defines a route for each endpoint. For client endpoints you route from
the cxf endpoint to the jms queue or topic. For servers you route from the jms queue or
topic to the cxf endpoint -->
<camelContext id="camelContext" trace="true" xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="jms://queue:CustomerService" />
<to uri="direct:CustomerService" />
</route>
</camelContext>
</beans>
greetings all
I am using the JMS with the following configuration to send messages between client & server, and i need to replace jms with AMQP, and I need some guide, so please advise:
client-applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring-1.4.0.xsd
http://cxf.apache.org/transports/camel http://cxf.apache.org/transports/camel.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-camel.xml" />
<!-- Directly defined ConnectionFactory -->
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<!-- By defining a JmsComponent called jms you can use the JMS transport in routes
You may define several of these components if you have different JMS servers for
different services. They can be distinguished in the routes by their id
-->
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="useMessageIDAsCorrelationID" value="true" />
</bean>
<!-- Add the camel transport to CXF. So you can define endpoint in the form camel://direct:<EndpointName>
in cxf client and server endpoints. These endpoints are then available in camel
as direct:<EndpointName> -->
<bean class="org.apache.camel.component.cxf.transport.CamelTransportFactory">
<property name="bus" ref="cxf" />
<property name="camelContext" ref="camelContext" />
<property name="transportIds">
<list>
<value>http://cxf.apache.org/transports/camel</value>
</list>
</property>
</bean>
<!-- Define a cxf endpoint based on client stub generated from a wsdl.
It is important to provide serviceName and endpointName so the wsdl is not needed
at runtime. As far as I know the serviceName and endpointName do not have to have a special
convention but it is good practice to use the service namespace and Service Interface name in the names
-->
<client id="CustomerService" xmlns="http://cxf.apache.org/jaxws" xmlns:customer="http://customerservice.example.com/"
serviceName="customer:CustomerServiceService" endpointName="customer:CustomerServiceEndpoint"
address="camel://direct:CustomerService" serviceClass="com.example.customerservice.CustomerService">
<features>
<!-- Enables logging of SOAP messages. -->
<!-- <logging xmlns="http://cxf.apache.org/core" /> -->
</features>
</client>
<!-- This context defines a route for each endpoint. For client endpoints you route from
the cxf endpoint to the jms queue or topic. For servers you route from the jms queue or
topic to the cxf endpoint -->
<camelContext id="camelContext" xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="direct:CustomerService" />
<to uri="jms://queue:CustomerService" />
</route>
</camelContext>
</beans>
server-applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring-1.4.0.xsd
http://cxf.apache.org/transports/camel http://cxf.apache.org/transports/camel.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-camel.xml" />
<!-- Directly defined ConnectionFactory -->
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<!-- By defining a JmsComponent called jms you can use the JMS transport in routes
You may define several of these components if you have different JMS servers for
different services. They can be distinguished in the routes by their id
-->
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="useMessageIDAsCorrelationID" value="true" />
</bean>
<!-- Add the camel transport to CXF. So you can define endpoint in the form camel://direct:<EndpointName>
in cxf client and server endpoints. These endpoints are then available in camel
as direct:<EndpointName> -->
<bean class="org.apache.camel.component.cxf.transport.CamelTransportFactory">
<property name="bus" ref="cxf" />
<property name="camelContext" ref="camelContext" />
<property name="transportIds">
<list>
<value>http://cxf.apache.org/transports/camel</value>
</list>
</property>
</bean>
<!-- Define a cxf endpoint based on client stub generated from a wsdl.
It is important to provide serviceName and endpointName so the wsdl is not needed
at runtime. As far as I know the serviceName and endpointName do not have to have a special
convention but it is good practice to use the service namespace and Service Interface name in the names
-->
<endpoint
xmlns="http://cxf.apache.org/jaxws"
xmlns:customer="http://customerservice.example.com/"
id="CustomerService"
address="camel://direct:CustomerService"
serviceName="customer:CustomerServiceService"
endpointName="customer:CustomerServiceEndpoint"
implementor="com.example.customerservice.impl.CustomerServiceImpl">
<features>
<!-- Enables logging of SOAP messages. -->
<logging xmlns="http://cxf.apache.org/core" />
</features>
</endpoint>
<!-- This context defines a route for each endpoint. For client endpoints you route from
the cxf endpoint to the jms queue or topic. For servers you route from the jms queue or
topic to the cxf endpoint -->
<camelContext id="camelContext" trace="true" xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="jms://queue:CustomerService" />
<to uri="direct:CustomerService" />
</route>
</camelContext>
</beans>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你只需要将 替换
为
`
you just need to replace the
With
`