Mule ESB:为WMQ队列设置JMS端点

Mule ESB:为WMQ队列设置JMS端点,jms,mule,ibm-mq,Jms,Mule,Ibm Mq,目前我正在与mule合作,需要在WMQ队列中编写。但我不想使用WMQ端点,而是想使用JMS端点。以下是我的配置: <?xml version="1.0" encoding="UTF-8"?> <mule xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:jetty="http://www.mulesoft.org/schema/mule/jetty" xmlns:scripting="http://www.mu

目前我正在与mule合作,需要在WMQ队列中编写。但我不想使用WMQ端点,而是想使用JMS端点。以下是我的配置:

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

<mule xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:jetty="http://www.mulesoft.org/schema/mule/jetty" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:wmq="http://www.mulesoft.org/schema/mule/ee/wmq" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:ajax="http://www.mulesoft.org/schema/mule/ajax" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1"
    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-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd
http://www.mulesoft.org/schema/mule/ajax http://www.mulesoft.org/schema/mule/ajax/current/mule-ajax.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/ee/wmq http://www.mulesoft.org/schema/mule/ee/wmq/current/mule-wmq-ee.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/jetty http://www.mulesoft.org/schema/mule/jetty/current/mule-jetty.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd">
    <wmq:connector name="WMQ" hostName="localhost" port="1414" queueManager="localmanager" validateConnections="true" doc:name="WMQ" ccsId="819"/>
    <data-mapper:config name="map_to_xml" transformationGraphPath="map_to_xml.grf" doc:name="map_to_xml"/>
    <data-mapper:config name="xml_to_json" transformationGraphPath="xml_to_json.grf" doc:name="xml_to_json"/>

    <jms:connector name="jmsConnector"
        connectionFactoryJndiName="jms/ConnectionFactory"
        jndiInitialFactory="com.ibm.websphere.naming.WsnInitialContextFactory"
        specification="1.1"
        connectionFactory-ref="MQConnectionFactory">
        <spring:property name="jmsSupport" ref="customJmsSupport"/>
    </jms:connector>
    <spring:beans>
        <spring:bean id="customJmsSupport" class="CustomJms11Support">
            <spring:constructor-arg ref="jmsConnector" />
        </spring:bean>
        <spring:bean name="MQConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
            <spring:property name="hostName" value="localhost"/>
            <spring:property name="port" value="1414"/>
            <spring:property name="queueManager" value="localmanager"/>
            <spring:property name="transportType" value="1"/>
        </spring:bean>
    </spring:beans>

    <flow name="RequestFlow" doc:name="RequestFlow">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8088" path="uebermittleAusweisdaten" doc:name="HTTP" contentType="text/html"/>
        <expression-filter expression="#[message.payload !='/favicon.ico']" doc:name="Expression"/>
        <jersey:resources doc:name="REST">
            <component class="de.fraport.sources.RestClass"/>
        </jersey:resources>
        <set-variable variableName="id" value="#[message.id]" doc:name="Message ID"/>
        <json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
        <data-mapper:transform config-ref="map_to_xml" doc:name="Map To XML">
            <data-mapper:input-arguments>
                <data-mapper:input-argument key="id">#[flowVars['id']]</data-mapper:input-argument>
            </data-mapper:input-arguments>
        </data-mapper:transform>
        <flow-ref name="Subflow1" doc:name="Flow Reference"/>
        <parse-template location="D:\Workspace\ajax_rest\src\main\app\www\index.html" doc:name="Parse Template"/>
    </flow>
    <sub-flow name="Subflow1" doc:name="Subflow1">
        <mulexml:xslt-transformer encoding="ISO8859-1" maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="D:\Workspace\ajax_rest\mobako.sender.xsl" doc:name="SOAP Envelope"/>
        <mulexml:dom-to-xml-transformer outputEncoding="ISO8859-1" doc:name="DOM to XML"/>
        <outbound-endpoint doc:name="JMS" address="jms://LSMH.ZKSEAP.SERVICEBUS" connector-ref="jmsConnector" encoding="ISO8859-1"/>
        <!-- <wmq:outbound-endpoint queue="LSMH.ZKSEAP.SERVICEBUS" encoding="ISO8859-1" connector-ref="WMQ" doc:name="ZKSEAP IN"/> -->
        <set-property propertyName="MULE_CORRELATION_ID" value="#[function:dateStamp:yyyy-MM-dd HH:mm:ss]" doc:name="Set Correlation ID"/>
        <request-reply>  
            <vm:outbound-endpoint path="sender">  
                <message-properties-transformer scope="outbound"> 
                    <delete-message-property key="MULE_REPLYTO"/> 
                </message-properties-transformer> 
            </vm:outbound-endpoint>  
            <vm:inbound-endpoint path="response">  
                <logger level="INFO" message="#[string:XXXXXX 1:  #[message.inboundProperties]"/> 
            </vm:inbound-endpoint> 
        </request-reply>
    </sub-flow>
    <flow name="ResponseFlow" doc:name="ResponseFlow">
        <inbound-endpoint address="jms://ZKSEAP.LSMH.SERVICEBUS" connector-ref="jmsConnector" doc:name="ZKSEAP OUT"/>
        <!-- <wmq:inbound-endpoint queue="ZKSEAP.LSMH.SERVICEBUS" connector-ref="WMQ" doc:name="ZKSEAP OUT" encoding="UTF-8"/> -->
        <set-property propertyName="MULE_CORRELATION_ID" value="#[function:dateStamp:yyyy-MM-dd HH:mm:ss]" doc:name="Set Correlation ID"/>
        <data-mapper:transform doc:name="XML To JSON" config-ref="xml_to_json"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <vm:outbound-endpoint path="response" doc:name="Response Outbound" exchange-pattern="one-way"/>
    </flow>
</mule>

#[flowVars['id']]
我已经使用JMS端点成功地从WMQ队列读取消息。然而,当我试图使用JMS端点在WMQ队列中写入一些消息时,我从服务器上得到了以下错误:

2014-07-22 10:11:27064[Axis2任务]错误WMQMsg-应为MQ 消息格式“MQSTR”,但收到“MQHRF2”2014-07-22 10:11:27064[Axis2任务]警告QMgrConnection-将消息移动到死区 尝试1次/次后的信件队列: 414D51206C6F63616C6D616E616765721A0CCE320003C0 2[致命错误]:1:1: 内容是序言中的nicht zulõssig。错误:“内容不正确。” 序言中的zulõssig。'2014-07-22 10:11:27064[Axis2任务]警告ESBMsg -为日志打印对ESBMsg进行修饰时出错

我知道发生此错误是因为我试图写入非JMS队列。我还知道我必须通过设置“?targetClient=1”来解决它。但是,当我尝试将targetClient属性添加到队列URL中时,仍然出现错误(WMQ似乎也将该属性识别为URL)

然后,通过我的研究,我发现我不能直接在url中设置“?targetClient”。相反,我需要创建一个Java类来设置“?targetClient”。为了创建这些类,我遵循以下URL中的一些说明

但不幸的是,它对我也不起作用。有人知道我该怎么解决吗?谢谢

注意:在Apache Camel中,我只需添加以下内容即可解决此问题:

<setHeader headerName="CamelJmsDestinationName">
    <constant>queue:///LSMH.ZKSEAP.SERVICEBUS?targetClient=1</constant>    
</setHeader>

queue:///LSMH.ZKSEAP.SERVICEBUS?targetClient=1    

Mule ESB中是否有类似的功能?

刚刚解决了问题:

我们需要创建一个java类来设置targetClient,这是正确的。要做到这一点,我们可以遵循我上面给出的链接。但是,我们需要稍微更改代码。 以下是正确的代码:

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Session;

import org.mule.api.endpoint.ImmutableEndpoint;
import org.mule.transport.jms.Jms11Support;
import org.mule.transport.jms.JmsConnector;

import com.ibm.mq.jms.JMSC;
import com.ibm.mq.jms.MQQueue;

/**
* Implements WebSphere MQ specific JMS support for Mule. The class
* overrides the createDestination method to intercept JMS Queue object
* creation and sets the targetClient=1 property on created MQQueue
* objects. This is necessary to prevent non-JMS consumers from being
* choked by RFH2 headers.
*/
public class CustomJms11Support extends Jms11Support {

    public CustomJms11Support(JmsConnector connector) {
        super(connector);
    }

    @Override
    public Destination createDestination(Session session, String name, boolean
    topic, ImmutableEndpoint ie) throws JMSException {
        Destination destination = super.createDestination(session, name, topic, ie);
        if (destination instanceof MQQueue){
            ((MQQueue) destination).setTargetClient(JMSC.MQJMS_CLIENT_NONJMS_MQ);
        }
        return destination;
    }
}
然后,在将请求发送到JMS端点之前,我们需要设置一个名为“JMS_IBM_Character_set”的属性(如果不是,我们将得到“预期的MQ消息characterSet'819',但收到'1208'”错误)。以下是我如何配置它:

<set-property propertyName="JMS_IBM_Character_Set" value="ISO8859_1" doc:name="Property"/>

仅供参考,通过将WMQ端点更改为JMS端点,可以确保提高性能


希望它会有用:D

OOC为什么不使用WMQ端点?JMS-one的优势是什么?@DavidDossot,因为我尝试使用Camel和Mule来配置我的项目,并且在Camel中我使用JMS端点,我发现Camel-one的性能比Mule-one更快。我认为,这是由JMS端点引起的。我的意思是,JMS连接比WMQ连接快。这就是为什么,为了证明我的理论,我尝试将Mule中的WMQ替换为JMS端点。最终的结果是,当我尝试将读取WMQ替换为JMS时,性能更快。但是我在替换write WMQ时遇到了一个问题。此外,WMQ endpoint仅在企业版中可用,对吗?是的,WMQ是EE:感谢您详细介绍了您试图实现的目标。