Apache Camel: Is it possible to configure WMQ with

2020-03-06 18:19发布

currently I am working with apache camel and wmq. For the camel configuration and routing, I am using Java DSL. But I could not find any example about how to configure WMQ by using Java DSL.

Here is what I get when I tried to configure WMQ:

config.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" default-init-method="init" xmlns:util="http://www.springframework.org/schema/util" xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xs http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://www.springframework.org/schema/osgi  http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <import resource="classpath:/META-INF/spring/components.xml"/>

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">

        <route>
            <from uri="jms:LQ.SERVICEPROVIDER.CAMEL.SERVICEBUS"/>

            <setHeader headerName="ID">
                <xpath resultType="java.lang.Integer">//id</xpath>
            </setHeader>
            <setHeader headerName="FIRSTNAME">
                <xpath resultType="java.lang.String">//vorname</xpath>
            </setHeader>
            <setHeader headerName="LASTNAME">
                <xpath resultType="java.lang.String">//nachname</xpath>
            </setHeader>

            <to uri="sql:insert into USERS (ID, FIRSTNAME, LASTNAME, BEARBEITET) values (:#ID, :#FIRSTNAME, :#LASTNAME, TRUE)"/>
        </route>

    </camelContext>
</beans>

component.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" default-init-method="init" xmlns:util="http://www.springframework.org/schema/util" xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xs http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://www.springframework.org/schema/osgi  http://www.springframework.org/schema/osgi/spring-osgi.xsd"> 

    <!-- ************************************************************************** -->
    <!-- ***************  JMS - Configuration                       *************** -->
    <!-- ************************************************************************** -->

    <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="jmsCachedConnectionFactory" />
        <property name="exceptionListener" ref="jmsCachedConnectionFactory" />
        <property name="transacted" value="true"/>
        <property name="transactionManager" ref="txManager" />
    </bean>

    <bean id="jmsCachedConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
        <property name="targetConnectionFactory" ref="jmsConnectionFactory" />
        <property name="sessionCacheSize" value="15" />
    </bean>

    <bean id="jmsConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
        <property name="channel" value="${mq.prod.channel}" />
        <property name="hostName" value="${mq.prod.host}" />
        <property name="port" value="${mq.prod.port}" />
        <property name="queueManager" value="${mq.prod.manager}" />
        <property name="transportType" value="1" />
    </bean>

    <bean id="txManager" class="org.springframework.jms.connection.JmsTransactionManager">
        <property name="connectionFactory" ref="jmsCachedConnectionFactory" />
    </bean>

But, as I said before I dont want to use Spring to configure it. I prefer to use Java DSL. Is it possible? If yes could you please give me some example or references?

Your help is so much appreciated. Thanks.

1条回答
贼婆χ
2楼-- · 2020-03-06 18:50

First I propose to see this as tutorial about how to integrate camel with websphere MQ. Hope it can help.

Instead of this I think you should read following links which there are some good advice about using Websphere MQ or another JMS implementation rather than ActiveMQ.

  1. http://camel.apache.org/jms.html
  2. http://java.dzone.com/articles/apache-camel-tutorial-eip
  3. http://camel.465427.n5.nabble.com/Error-when-using-Camel-write-to-Websphere-MQ-td5727817.html
  4. http://camel.465427.n5.nabble.com/IBM-MQ-and-CAMEL-td5591661.html
  5. http://camel.465427.n5.nabble.com/Can-Camel-communicate-over-IBM-MQ-sender-receiver-channels-td4429050.html
  6. Connecting Apache ServiceMix to Websphere MQ
查看更多
登录 后发表回答