java - Apache Camel : Is it possible to configure WMQ without using Spring?

标签 java jms apache-camel ibm-mq dsl

目前我正在使用 apache camel 和 wmq。对于 Camel 配置和路由,我使用的是 Java DSL。但是我找不到任何关于如何使用 Java DSL 配置 WMQ 的示例。

这是我在尝试配置 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>

但是,正如我之前所说,我不想使用 Spring 来配置它。我更喜欢使用 Java DSL。是否可以?如果是,请给我一些例子或引用资料好吗?

非常感谢您的帮助。谢谢。

最佳答案

关于java - Apache Camel : Is it possible to configure WMQ without using Spring?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24014807/

相关文章:

java - 无法在矩形顶部创建按钮

java - 为什么Spring框架更喜欢互斥而不是 volatile ?

java - 消息驱动 Bean 消息

java - 消费者如何通知JMS队列保存消息

java - 在 spring boot 中使用现有的 http 服务器作为 Camel 端点

java - 为什么这个数据库同步例程失败?

java - 如何传入 "Class<HostResolver> hostResolver"形式的变量

java - 在 Redhat MRG/Apache QPID 中创建仅浏览队列

java - 如何从 java camel 测试中的模拟端点提取消息正文?

java - apache Camel - 将消息警报添加到死信队列