[英]Save value from database in a session variable Mule esb
Im developing a sample bookstare in mule esb and Im using mysql as database. 我用mysql作为数据库在mule esb和Im中开发了一个示例bookstare。 My database has a table named 'Stock' whose has 2 attr (isbn and quantity) for the registered books I offer on the form.
我的数据库中有一个名为“库存”的表,该表具有我在表格上提供的注册书籍的2 attr(isbn和数量)。 What i want is checking the number of books the client ask by the form dont increase the existence books (quantity) on my database to do the order.
我想要的是通过表格检查客户要求的书数,不要增加我数据库中存在的书(数量)以进行订购。
I have that flow: 我有这样的流程:
<flow name="Facturacion" doc:name="Facturacion">
<composite-source doc:name="Composite Source">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8086" doc:name="HTTP" path="Facturacion" transformer-refs="HttpToPedido"/>
<file:inbound-endpoint responseTimeout="10000" doc:name="File" moveToDirectory="tmp" path="tmp/pedidos"/>
</composite-source>
<component doc:name="Generar Pedido" class="org.mule.components.GenerarPedido"/>
<set-session-variable variableName="dataTemp" value="#[message.payload.cantidadPedida]" doc:name="Session Variable"/>
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT cantidad FROM stock WHERE isbn = #[payload.isbn]]]></db:parameterized-query>
</db:select>
<collection-splitter doc:name="Collection Splitter"/>
<choice doc:name="Choice">
<when expression="#[sessionVars['dataTemp'] >= payload.cantidadPedida]">
<vm:outbound-endpoint exchange-pattern="one-way" path="procesarPedido" doc:name="Procesar Pedido Disponible"/>
</when>
<otherwise>
<vm:outbound-endpoint exchange-pattern="one-way" path="rechazarStock" doc:name="Rechazar por falta en Stock"/>
</otherwise>
</choice>
<collection-aggregator failOnTimeout="true" doc:name="Collection Aggregator"/>
<set-payload value="#[payload];" doc:name="Set Payload"/>
</flow>
Any solve to that? 有什么解决办法吗? What i need is compare de value of the quantity of the book in order from payload with the value in my 'stock table' from my database.
我需要的是按顺序比较有效负载中的书籍数量的值与数据库中“库存表”中的值。
Thanks! 谢谢!
I don't know exactly what you're trying to achieve, but to store the result of the database query in a session var, all you need to use is an enricher, where you specify the target to be the session var: 我不确切知道您要实现的目标,但是要将数据库查询的结果存储在会话变量中,您需要使用的只是一个扩充程序,您可以在其中指定目标为会话变量:
<enricher target="#[sessionVars.test]" doc:name="Message Enricher">
<!-- database call -->
</enricher>
If this is not what you're after, you can divulge further information about your usecase. 如果这不是您想要的,则可以透露有关用例的更多信息。
What about to use a filter? 怎样使用过滤器?
The following app: 以下应用:
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" />
<db:mysql-config name="MySQL_Configuration" url="jdbc:mysql://localhost:3306/esb?user=root&amp;password=" />
<flow name="databasetestsFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" />
<db:select config-ref="MySQL_Configuration" >
<db:parameterized-query><![CDATA[select name from test where id=#[message.inboundProperties.'http.query.params'.id]]]></db:parameterized-query>
</db:select>
<expression-filter expression="#[payload.size()==1 && payload[0].name=="one"]" />
<set-payload value="PROCESSED" />
</flow>
returns "PROCESSED" only when the id is 1, for example: 仅当id为1时才返回“ PROCESSED”,例如:
curl http://localhost:8081\?id\=1
You could change the filter expression to something like: 您可以将过滤器表达式更改为:
#[sessionVars['dataTemp'] >= payload[0].cantidadPedida]
You also can store the database results in a session var by using the target
attribute in the db:select
processor, for example: 您还可以通过使用
db:select
处理器中的target
属性将数据库结果存储在会话var中,例如:
target="#[sessionVars.results]"
HTH, Marcos HTH,马科斯
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT cantidad FROM stock WHERE isbn = #[payload.isbn]]]></db:parameterized-query>
</db:select>
<set-session-variable variableName="dataTemp" value="#[payload.cantidad]" doc:name="dataTemp"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.