繁体   English   中英

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

[英]Mule ESB: Setup JMS Endpoint for WMQ Queue

目前我正在使用mule,需要在WMQ Queue中编写。 但是我不想使用WMQ端点,而是希望使用JMS Endpoint来实现。 这是我的配置:

<?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>

我已经使用JMS端点成功读取了来自WMQ Queue的消息。 但是,当我尝试使用JMS Endpoint在WMQ Queue中编写一些消息时,我的服务器出现以下错误:

2014-07-22 10:11:27,064 [Axis2任务]错误WMQMsg - 预期的MQ消息格式'MQSTR',但收到'MQHRF2'2014-07-22 10:11:27,064 [Axis2任务] WARN QMgrConnection - 将msg移入1次尝试/尝试后的死信队列:414D51206C6F63616C6D616E616765721A0CCE5320003C0 2 [致命错误]:1:1:Prolog中的内容是nichtzulõssig。 错误:'Prolog中的内容是nichtzulõssig'。 2014-07-22 10:11:27,064 [Axis2任务] WARN ESBMsg - 错误美化ESBMsg进行日志打印

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

然后,从我的研究中,我发现我不能直接在url中设置“?targetClient”。 而不是那样,我需要创建一个Java类来设置“?targetClient”。 要创建这些类,我按照以下URL中的说明进行操作

创建自定义JMSSupport类

但不幸的是,它也不适合我。 任何人都知道如何解决它? 谢谢。

注意:在Apache Camel中,我可以通过添加以下内容来解决它:

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

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_IBM_Character_Set”的属性(如果不是,我们将在向JMS端点发送请求之前获得“预期的MQ消息字符集'819',但收到'1208'”错误)。 这是我配置它的方式:

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

只是为了您的信息,通过将WMQ端点更改为JMS端点,确保它可以提高性能。

希望它会有用:D

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM