Mule 定时查询数据库获取数据调用webservice例子(Poll,WebServiceConsumer,java转换器)
1.用Poll定时从数据里查数据,java转换器转换成soup,调用webservice
2.Poll,频率、启动后延迟、时间单位,图例是1000ms执行一次,在AnyPoint里Poll不会按频率执行,只会执行1次,发布到mule-standalone后正常。
3.java转换器,如果转出为soup的话,MINE_TYPE = application/xml,java转换的类class="com.main.convert2Soup"
java转换器
该类需要:
import org.mule.transformer.AbstractMessageTransformer;
public class convert2Soup extends AbstractMessageTransformer
4.处理soap String需要按以下方式:
5.例子:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:ws="http://www.mulesoft.org/schema/mule/ws" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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.6.0"
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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.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/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.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/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd">
<db:oracle-config name="Oracle_Configuration" host="127.0.0.1" port="1521" instance="orcl" user="hlyy" password="hlyy" doc:name="Oracle Configuration"/>
<ws:consumer-config name="Web_Service_Consumer" wsdlLocation="http://localhost:8333/soap/ws-service?wsdl" service="MyServiceService" port="MyServicePort" serviceAddress="http://localhost:8333/soap/ws-service" doc:name="Web Service Consumer"/>
<flow name="ptjobFlow">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="1000" />
<db:select config-ref="Oracle_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select t.treat_code arg0,'1' arg1,'1' arg2,'1'arg3,t.doct_code arg4 from patient t]]></db:parameterized-query>
</db:select>
</poll>
<foreach doc:name="For Each">
<!-- <json:object-to-json-transformer doc:name="Object to JSON"/>
<logger message="1:#[payload]" level="INFO" doc:name="Logger"/>
--><custom-transformer mimeType="application/xml" class="com.main.convert2Soup" doc:name="Java"/>
<logger message="2:#[payload]" level="INFO" doc:name="Logger"/>
<ws:consumer config-ref="Web_Service_Consumer" operation="getCall" doc:name="Web Service Consumer"/>
<logger level="INFO" doc:name="Logger"/>
</foreach>
</flow>
</mule>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下