如果使用WSO2 ESB在介体中发生异常,如何中断/停止序列

时间:2014-11-18 07:11:08

标签: jms wso2 wso2esb

我正在尝试实现逻辑,如果在执行序列期间发生任何错误,例如JMS端点无效,那么序列应该放在这里并记录消息。

实际调解如下:

验证 - >克隆 - >附加日志克隆中介快照。enter image description here

我的服务代码是:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="AdapterService"
       transports="jms"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log level="full" separator="..... XML Received..."/>
         <validate source="//DOCUMENT03">
            <schema key="conf:/DOCUMENT03_CUSTOM.xsd"/>
            <on-fail>
               <makefault version="pox">
                  <reason value="Invalid XML"/>
                  <detail>Error while validating  XML at  Adapter Service.</detail>
               </makefault>
               <log level="full" category="ERROR" separator="... XML Error..."/>
               <drop/>
            </on-fail>
         </validate>
         <clone>
            <target>
               <sequence>
                  <script language="js">mc.getEnvelope().getBody().getFirstElement().getFirstElement().getFirstElement().detach();</script>
                  <log level="full"/>
                  <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
                  <send>
                     <endpoint>
                        <address uri=**"jms:/BookingMessage?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://1929.168.1.113:61616&amp;transport.jms.DestinationType=queue"**
                                 format="pox">
                           <timeout>
                              <duration>10</duration>
                              <responseAction>fault</responseAction>
                           </timeout>
                           <suspendOnFailure>
                              <errorCodes>101507,101505,101503</errorCodes>
                              <progressionFactor>1.0</progressionFactor>
                              <maximumDuration>10</maximumDuration>
                           </suspendOnFailure>
                           <markForSuspension>
                              <errorCodes>101508,101504</errorCodes>
                              <retriesBeforeSuspension>5</retriesBeforeSuspension>
                              <retryDelay>10</retryDelay>
                           </markForSuspension>
                        </address>
                     </endpoint>
                  </send>
                  <payloadFactory media-type="xml">
                     <format>
                        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                           <soapenv:Body>$1</soapenv:Body>
                        </soapenv:Envelope>
                     </format>
                     <args>
                        <arg xmlns:tns="http://com.sanomalearning/cdm/finance/generalledger/v1"
                             evaluator="xml"
                             expression="//DOCUMENT03/CMMHeader"/>
                     </args>
                  </payloadFactory>
                  <log level="full"/>
                  <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
                  <send>
                     <endpoint key="conf:/CMMHeaderQueueUrl"/>
                  </send>
                  <log level="full" separator="Message Sent to Queue"/>
               </sequence>
            </target>
         </clone>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
      <faultSequence>
         <log level="custom" separator=",">
            <property name="text" value="***FAult Handler***"/>
         </log>
         <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
         <drop/>
         <log level="custom">
            <property name="text" value="An unexpected error occured"/>
            <property name="message" expression="get-property('ERROR_MESSAGE')"/>
            <property name="code" expression="get-property('ERROR_CODE')"/>
            <property name="detail" expression="get-property('ERROR_DETAIL')"/>
            <property name="exception" expression="get-property('ERROR_EXCEPTION')"/>
         </log>
         <drop/>
      </faultSequence>
   </target>
   <parameter name="transport.jms.ContentType">
      <rules>
         <jmsProperty>contentType</jmsProperty>
         <default>application/xml</default>
      </rules>
   </parameter>
   <parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
   <parameter name="transport.jms.DestinationType">queue</parameter>
   <parameter name="transport.jms.Destination">AdapterService.01.Request.Queue</parameter>
   <description/>
</proxy>

现在,当我从队列接收到请求后执行此服务时,它不会向无效队列发送消息,而是向第二个Url发送消息。现在我想如果消息没有发送到无效端点,那么序列应该被丢弃。无效的网址是粗体。

1 个答案:

答案 0 :(得分:0)

AFAIK您无法在一个克隆介体中的同一目标下定义两个发送调解器,而是必须在两个不同的目标中定义这些调解器。

如果您能详细说明您的要求,也会有所帮助。对于关于JMS端点的解决方案是无效问题,您可以做的是在故障序列中定义drop mediator。