我正在寻找设计流程的正确方法。 如果要对5个不同的表执行数据库操作,是否需要5个数据库节点? 还是要声明3个流量变量,是否需要3个变量转换器? 我认为这使流程看起来不必要地复杂。 我可以在一个数据库节点中编写多个查询吗? 如果我不想编写Java类,正确的方法应该是什么?
回答您的问题:-
If I want to perform database operations on 5 different tables, do I need 5 database nodes?
不可以。可以通过单个DB连接器执行不同的操作来实现。 请浏览以下文档:-https: //docs.mulesoft.com/mule-user-guide/v/3.8/database-connector 。
您需要定义单个全局数据库连接器来连接您的数据库,并且可以由执行不同操作(选择,插入,更新等)的流程中的多个数据库组件引用。 请在这里检查:-
在Mule的数据库连接器中写入多个查询
if I want to declare 3 flow variables, do I need 3 Variable transformers?
不必这样做,可以使用<message-properties-transformer/>
,您可以使用scope="invocation"
属性一次在一个组件中定义多个变量。 例如:
<message-properties-transformer doc:name="Message Properties" scope="invocation">
<add-message-property key="var1" value="value1"/>
<add-message-property key="var2" value="value2"/>
</message-properties-transformer>
Can I write multiple queries in one database node?
对于插入,删除,更新操作,您可以使用批量选项ref在一个数据库组件中进行多个查询:-https: //docs.mulesoft.com/mule-user-guide/v/3.5/database-connector#bulk-updates : --
<db:bulk-execute config-ref="dbConfig">
update TABLE1 set NAME='Mercury' where POSITION=0;
update TABLE1 set NAME='Mercury' where POSITION=4
</db:bulk-execute>
您也可以在这里参考:-http: //www.slideshare.net/anir37/mule-db-bulk-execute
希望这个帮助:)