我在WSO2 ESB中有一个代理服务,它通过JMS监听队列,然后在一些处理之后将消息发送到另一个队列。它工作正常。我正在实现此服务的故障序列,如果端点被挂起,那么它应该将消息发送到错误队列。在故障序列中,WSO2 ESB正在生成ERROR_MESSAGE,ERROR_DETAIL,ERROR_EXCEPTION,但它不生成ERROR_CODE。
故障序列:
<faultSequence xmlns="http://ws.apache.org/ns/synapse">
<log level="full" separator="**********Fault Sequence File Processor***********">
<property name="ErrorCode" expression="get-property('ERROR_CODE')"></property>
<property name="ErrorMessage" expression="get-property('ERROR_MESSAGE')"></property>
<property name="ErrorDetail" expression="get-property('ERROR_DETAIL')"></property>
<property name="ErrrorException" expression="get-property('ERROR_EXCEPTION')"></property>
</log>
<payloadFactory media-type="xml">
<format>
<MessageFormat xmlns="">
<ECode>$1</ECode>
<EMsg>$2</EMsg>
<EDetail>$3</EDetail>
<EException>$4</EException>
</MessageFormat>
</format>
<args>
<arg expression="get-property('ERROR_CODE')" evaluator="xml"></arg>
<arg expression="get-property('ERROR_MESSAGE')" evaluator="xml"></arg>
<arg expression="get-property('ERROR_DETAIL')" evaluator="xml"></arg>
<arg expression="get-property('ERROR_EXCEPTION')" evaluator="xml"></arg>
</args>
</payloadFactory>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"></property>
<property name="ClientApiNonBlocking" action="remove" scope="axis2"></property>
<send>
<endpoint key="conf:/endpoints/ErrorQueue.xml"></endpoint>
</send>
</faultSequence>
端点我要暂停:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="Endpoint">
<address uri="jms:/RequestQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://192.168.1.33:61616&transport.jms.DestinationType=queue" format="pox">
<timeout>
<duration>6000</duration>
</timeout>
<markForSuspension>
<errorCodes>101504, 101505, 303001, 303000</errorCodes>
<retriesBeforeSuspension>1</retriesBeforeSuspension>
<retryDelay>1</retryDelay>
</markForSuspension>
<suspendOnFailure>
<errorCodes>101500, 101501, 101506, 101507, 101508, 303001, 303000</errorCodes>
<initialDuration>1000</initialDuration>
<progressionFactor>2</progressionFactor>
<maximumDuration>6400</maximumDuration>
</suspendOnFailure>
</address>
</endpoint>
注意: &#34;地址&#34; URI中提到的 IP 不正确,这就是服务进入故障序列的原因。
错误队列输出:
<MessageFormat><ECode>0</ECode><EMsg>Unexpected error during sending message out</EMsg><EDetail>org.apache.synapse.SynapseException: Unexpected error during sending message out
at org.apache.synapse.core.axis2.Axis2Sender.handleException(Axis2Sender.java:172)
at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:71)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:338)
at org.apache.synapse.endpoints.AbstractEndpoint.send(AbstractEndpoint.java:333)
at org.apache.synapse.endpoints.AddressEndpoint.send(AddressEndpoint.java:59)
at org.apache.synapse.endpoints.IndirectEndpoint.send(IndirectEndpoint.java:54)
at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:196)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.mediators.eip.Target.mediate(Target.java:106)
at org.apache.synapse.mediators.eip.splitter.IterateMediator.mediate(IterateMediator.java:146)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:196)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:166)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.axis2.transport.base.AbstractTransportListener.handleIncomingMessage(AbstractTransportListener.java:328)
at org.apache.synapse.transport.vfs.VFSTransportListener.processFile(VFSTransportListener.java:597)
at org.apache.synapse.transport.vfs.VFSTransportListener.scanFileOrDirectory(VFSTransportListener.java:328)
at org.apache.synapse.transport.vfs.VFSTransportListener.poll(VFSTransportListener.java:158)
at org.apache.synapse.transport.vfs.VFSTransportListener.poll(VFSTransportListener.java:107)
at org.apache.axis2.transport.base.AbstractPollingTransportListener$1$1.run(AbstractPollingTransportListener.java:67)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.axis2.AxisFault: Unable to create a JMSMessageSender for : null
at org.apache.axis2.transport.base.AbstractTransportSender.handleException(AbstractTransportSender.java:226)
at org.apache.axis2.transport.jms.JMSSender.sendMessage(JMSSender.java:129)
at org.apache.axis2.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:112)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:297)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:482)
at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:59)
... 33 more
Caused by: javax.jms.JMSException: Could not connect to broker URL: tcp://192.168.1.33:61616. Reason: java.net.NoRouteToHostException: No route to host
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:301)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:246)
at org.apache.activemq.ActiveMQConnectionFactory.createQueueConnection(ActiveMQConnectionFactory.java:203)
at org.apache.axis2.transport.jms.JMSOutTransportInfo.createJMSSender(JMSOutTransportInfo.java:363)
at org.apache.axis2.transport.jms.JMSSender.sendMessage(JMSSender.java:127)
... 39 more
</EDetail><EException></EException></MessageFormat>
问题: 为什么WSO2 ESB不生成ERROR_CODE?我必须得到错误代码,并在错误代码的基础上做出一些进一步的逻辑。
答案 0 :(得分:1)
这是WSO2 ESB的默认行为。在端点故障情况下,WSO2 ESB返回0作为ErrorCode但错误详细信息和错误消息具有特定的错误消息。您可以做的是,使用Filter mediator或Switch mediator,您可以制作自定义错误代码和消息。
<filter xmlns:ns="http://org.apache.synapse/xsd" source="json-eval($.node[0].nid)" regex="100">
<then>
//your business here
</then>
<else>
//your business here
</else>
</filter>