Apache camel apachecamel和ibmq

Apache camel apachecamel和ibmq,apache-camel,ibm-mq,Apache Camel,Ibm Mq,寻找ApacheCamel和IBM MQ之间集成的一些示例 Apache camel充当MQ和基于java的套接字应用程序之间的中间件路由器 我可以打开那个链接。重试:您应该在组件扫描包中定义JmsComponent bean,并为其提供所有连接工厂属性,并在路由中使用该bean。 例如: 在您的路线中添加以下内容 camelContext.addRoutes( new RouteBuilder() {

寻找ApacheCamel和IBM MQ之间集成的一些示例


Apache camel充当MQ和基于java的套接字应用程序之间的中间件路由器

我可以打开那个链接。重试:

您应该在组件扫描包中定义JmsComponent bean,并为其提供所有连接工厂属性,并在路由中使用该bean。 例如:

在您的路线中添加以下内容

  camelContext.addRoutes(
                new RouteBuilder()
                {
                    @Override
                    public void configure() throws Exception
                    {
                        from("ibmmq:topic:YY.ZZZ").to("stream:out"); //YY.ZZZ is your topic name. If Queue use ibmmq:queue:YY.ZZZ.
                    }
                });

如果您正在使用“stream:out”进行测试,请在依赖项和camel stream中包含camel jms和IBM MQ库。

我所能获得的最好结果如下所示,如一个本身承载camel上下文和路由的Spring XML应用程序上下文所示。此示例与IBM本机MQ JCA兼容的资源适配器v7.5、CAMEL 2.16和Spring core 4.2一起使用。我已经在Glassfish、Weblogic和JBoss EAP7服务器中部署了它

复杂性必然与处理MQ报告流有关,这些报告的原理与普通JMS消息回复的原理相冲突。有关详细说明,请参阅

这个基于CAMEL XML DSL的示例是自包含的,并且易于测试

我们从Spring和CAMEL声明开始:

<?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:util="http://www.springframework.org/schema/util" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd   
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
    http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">

驼峰上下文有两条路径:MQ到JMS和JMS到MQ,在这里链接起来形成一个桥以简化测试

<camel:camelContext id="mqBridgeCtxt">
<camel:route id="mq2jms" autoStartup="true">

奇怪:在Weblogic上,获取(例如)3个侦听器的唯一方法是强制3个连接(按顺序使用3个Camel:from语句),每个连接最多1个会话,否则会出现MQ错误:MQJCA1018:每个连接只允许一个会话。在JBoss上,您可以简单地调整concurrentConsumers=

  <camel:from uri="wmq:queue:TEST.Q1?concurrentConsumers=1&amp;disableReplyTo=true&amp;
        acknowledgementModeName=SESSION_TRANSACTED"/> 

上面的disable disableReplyTo选项确保在我们可以测试MQ消息类型为1=请求(-reply)或8=数据报(单向!)之前,CAMEL不会生成应答。这里没有说明测试和应答结构

然后,我们在下一次发布到普通JMS时将EIP强制为InOnly,以与入站MQ模式一致

  <camel:setExchangePattern pattern="InOnly"/>
  <!-- camel:process ref="reference to your MQ message processing bean fits here" / -->
  <camel:to uri="ref:innerQueue" />
</camel:route>

这结束了MQ到jms的路由;接下来,jms到MQ的路由仍然处于相同的驼峰上下文中:

<camel:route id="jms2mq"  autoStartup="true">
  <camel:from uri="ref:innerQueue" />
  <!-- remove inner message headers and properties to test without inbound side effects! -->
  <camel:removeHeaders pattern="*"/> 
  <camel:removeProperties pattern="*" />
  <!-- camel:process ref="reference to your MQ message preparation bean fits here" / -->

现在是远程目标返回MQ CoD报告的请求标志。我们还强制MQ消息为数据报类型(值8)

2048
64
8.
ReplyTo队列可以通过ReplyToURI选项指定,也可以作为如下所示的标头指定

接下来,我们将使用CamelJmsDestinationName头强制抑制jmsmq消息头MQRFH2(使用targetClient mqurl选项值1)。换句话说,我们希望发送一条普通的MQ二进制消息(即,只有MQMD消息描述符后跟有效负载)

TEST.REPLYTOQ
queue://MYQMGR/TEST.Q2?targetClient=1
更多的MQMD字段可以通过保留的JMS属性进行控制,如下所示。请参阅IBM文档中的限制

  <camel:setHeader headerName="JMS_IBM_Format"><camel:constant>MQSTR   </camel:constant></camel:setHeader>
  <camel:setHeader headerName="JMSCorrelationID"><camel:constant>_PLACEHOLDER_24_CHARS_ID_</camel:constant></camel:setHeader>
MQSTR
_占位符\u 24\u字符\u ID_
URI中的目标队列被上面的CamelJmsDestinationName覆盖,因此URI中的队列名称成为占位符

URI选项preserveMessageQos是这样一个选项——正如所观察到的那样——允许发送设置了ReplyTo数据的消息(以获取MQ CoD报告),但通过强制执行InOnly MEP防止CAMEL实例化应答消息侦听器

  <camel:to uri="wmq:queue:PLACEHOLDER.Q.NAME?concurrentConsumers=1&amp;
            exchangePattern=InOnly&amp;preserveMessageQos=true&amp;
            includeSentJMSMessageID=true" />
</camel:route>
</camel:camelContext>

我们还没有完成,我们仍然需要为本机JMS提供程序和Websphere MQ(通过本机IBM WMQ JCA资源适配器)声明队列工厂,以便根据您的上下文进行调整。我们在这里使用JNDI查找管理对象

<camel:endpoint id="innerQueue" uri="jmsloc:queue:transitQueue">
</camel:endpoint>

<jee:jndi-lookup id="mqQCFBean" jndi-name="jms/MYQMGR_QCF"/>
<jee:jndi-lookup id="jmsraQCFBean" jndi-name="jms/jmsra_QCF"/>

<bean id="jmsloc" class="org.apache.camel.component.jms.JmsComponent">
  <property name="connectionFactory" ref="jmsraQCFBean" />
</bean>

<bean id="wmq" class="org.apache.camel.component.jms.JmsComponent">
  <property name="connectionFactory" ref="mqQCFBean" />
</bean>

</beans>

从JNDI获取工厂(和JCA适配器)的另一种方法是将JMS客户机声明为Springbean。在Weblogic和Glassfish中,部署本机IBM JCA资源适配器并创建JNDI资源将更好地激发您的灵感,然后在上面的Spring上下文中引用JNDI资源,在JBoss中,直接MQ客户机bean声明最适合(如下所示)



欢迎评论和改进。

我使用带有MQConnectionFactory的JmsComponent完成了这项工作,这是我的代码:

@Bean(name = "wmq")
public JmsComponent wmq() throws JMSException {

    JmsComponent wmq = new JmsComponent();

    MQConnectionFactory mqConnectionFactory =  new MQConnectionFactory();
    mqConnectionFactory.setTransportType(1);
    mqConnectionFactory.setHostName("localhost");
    mqConnectionFactory.setPort(1414);
    mqConnectionFactory.setQueueManager("QMGRSCORE");
    mqConnectionFactory.setChannel("EXTAPP.SRVCONN");

    wmq.setConnectionFactory(mqConnectionFactory);

    return wmq;

}
在我的路线上,我这样称呼:

from("wmq:queue:myqueue").id("myMq")

这有帮助吗:?你提供的链接不起作用,说页面不存在。很奇怪!几小时前我读了那篇文章,并发布了链接。
<camel:endpoint id="innerQueue" uri="jmsloc:queue:transitQueue">
</camel:endpoint>

<jee:jndi-lookup id="mqQCFBean" jndi-name="jms/MYQMGR_QCF"/>
<jee:jndi-lookup id="jmsraQCFBean" jndi-name="jms/jmsra_QCF"/>

<bean id="jmsloc" class="org.apache.camel.component.jms.JmsComponent">
  <property name="connectionFactory" ref="jmsraQCFBean" />
</bean>

<bean id="wmq" class="org.apache.camel.component.jms.JmsComponent">
  <property name="connectionFactory" ref="mqQCFBean" />
</bean>

</beans>
<bean id="mqCFBean" class="com.ibm.mq.jms.MQXAConnectionFactory">
    <property name="hostName" value="${mqHost}"/>
    <property name="port" value="${mqPort}"/>
    <property name="queueManager" value="${mqQueueManager}"/>
    <property name="channel" value="${mqChannel}"/>
    <property name="transportType" value="1"/> <!-- This parameter is fixed and compulsory to work with pure MQI java libraries -->
    <property name="appName" value="${connectionName}"/>
</bean>

<bean id="wmq" class="org.apache.camel.component.jms.JmsComponent">
    <property name="connectionFactory" ref="mqCFBean"/>
    <property name="transacted" value="true"/>
    <property name="acknowledgementModeName" value="AUTO_ACKNOWLEDGE"/>
</bean>
@Bean(name = "wmq")
public JmsComponent wmq() throws JMSException {

    JmsComponent wmq = new JmsComponent();

    MQConnectionFactory mqConnectionFactory =  new MQConnectionFactory();
    mqConnectionFactory.setTransportType(1);
    mqConnectionFactory.setHostName("localhost");
    mqConnectionFactory.setPort(1414);
    mqConnectionFactory.setQueueManager("QMGRSCORE");
    mqConnectionFactory.setChannel("EXTAPP.SRVCONN");

    wmq.setConnectionFactory(mqConnectionFactory);

    return wmq;

}
from("wmq:queue:myqueue").id("myMq")