Mule - Schedule a flow to consume a web service

a 夏天 提交于 2020-01-16 08:48:11

问题


I'm new to Mule, and wanted to do one "simple" thing :

  • Every X seconds, call a soap webservice operation and store the result in a file.

My Flow looks actually like this :

<?xml version="1.0" encoding="UTF-8"?>
    ...
    <custom-transformer class="net.cpy.samples.webservices.SampleMessage" name="MessageWs" doc:name="MessageWs"/>
    <flow name="csvPublisher" doc:name="csvPublisher">
        <quartz:inbound-endpoint jobName="job1" repeatInterval="5000" responseTimeout="10000" doc:name="Quartz">
            <quartz:event-generator-job/>
        </quartz:inbound-endpoint>
        <cxf:jaxws-client operation="getMessages" clientClass="net.cpy.samples.webservices.MessageServiceService" port="MessageServicePort" wsdlLocation="http://localhost:8080/webservices-0.0.1-SNAPSHOT/MessageService?wsdl" enableMuleSoapHeaders="true" doc:name="SOAP Client">
            <cxf:inInterceptors/>
            <cxf:outInterceptors/>
        </cxf:jaxws-client>
        <http:outbound-endpoint exchange-pattern="request-response" address="http://localhost:8080/webservices-0.0.1-SNAPSHOT/MessageService" doc:name="HTTP"/>
        <file:outbound-endpoint path="/tmp" outputPattern="output.xml" responseTimeout="10000" doc:name="File"/>
    </flow>
</mule>

The WSDL of my sample webservice is :

    <?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="MessageServiceService" targetNamespace="http://webservices.samples.cpy.net/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservices.samples.cpy.net/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wsdl:types>
<xs:schema elementFormDefault="unqualified" targetNamespace="http://webservices.samples.cpy.net/" version="1.0" xmlns:tns="http://webservices.samples.cpy.net/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="getMessages" type="tns:getMessages"/>
<xs:element name="getMessagesResponse" type="tns:getMessagesResponse"/>
<xs:element name="sampleMessage" type="tns:sampleMessage"/>
<xs:complexType name="getMessages">
    <xs:sequence/>
  </xs:complexType>
<xs:complexType name="getMessagesResponse">
    <xs:sequence>
      <xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="tns:sampleMessage"/>
    </xs:sequence>
  </xs:complexType>
<xs:complexType name="sampleMessage">
    <xs:sequence>
      <xs:element minOccurs="0" name="content" type="xs:string"/>
      <xs:element minOccurs="0" name="date" type="xs:dateTime"/>
      <xs:element minOccurs="0" name="id" type="xs:long"/>
      <xs:element minOccurs="0" name="signature" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
  </wsdl:types>
  <wsdl:message name="getMessagesResponse">
    <wsdl:part element="tns:getMessagesResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="getMessages">
    <wsdl:part element="tns:getMessages" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="MessageService">
    <wsdl:operation name="getMessages">
      <wsdl:input message="tns:getMessages" name="getMessages">
    </wsdl:input>
      <wsdl:output message="tns:getMessagesResponse" name="getMessagesResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="MessageServiceServiceSoapBinding" type="tns:MessageService">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getMessages">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="getMessages">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="getMessagesResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="MessageServiceService">
    <wsdl:port binding="tns:MessageServiceServiceSoapBinding" name="MessageServicePort">
      <soap:address location="http://localhost:8080/webservices-0.0.1-SNAPSHOT/MessageService"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

For the moment, I try to use Quartz to schedule the web services calls, jaxws-client to generate the soap request and http transport to call the service.

I use cxf to generate the client code from the wsdl.

Can someone give me some advices, on how to do it ?

I'm using the latest version of mule (CE version).

Thanks in advance for any help.


回答1:


On issue is that you haven't specified a payload in the event-generator-job so a NullPayload is generated, which probably stops the flow pretty quickly (nothing to dispatch).

Either have event-generator-job to generate the objects to use for the CXF invocation.

Or, assuming that the MessageWs transformer's job is to create the payload for the CXF invocation, have event-generator-job generate a dummy payload and let the transformer wipe it out with the real payload:

<flow name="csvPublisher" doc:name="csvPublisher">
    <quartz:inbound-endpoint jobName="job1" repeatInterval="5000" responseTimeout="10000" doc:name="Quartz">
        <quartz:event-generator-job>
            <quartz:payload>dummy</quartz:payload>
        </quartz:event-generator-job>
    </quartz:inbound-endpoint>
    <transformer ref="MessageWs" />
    <cxf:jaxws-client operation="getMessages" ...



回答2:


You can also use Mule poll to schedule the flow by configuring the frequency attribute. Here for your reference :- https://developer.mulesoft.com/docs/display/current/Poll+Reference



来源:https://stackoverflow.com/questions/12029203/mule-schedule-a-flow-to-consume-a-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!