在mule的事务可能为jdbc事务,jms事务,xa事务等,多种事务.这里讲解事务的几个动作:
相关的文档:
https://www.mulesoft.org/documentation-3.2/display/MULE2USER/Transaction+Management
transaction可以使用的动作为:
NONE - Never participate in a transaction.(不采用事务)
ALWAYS_BEGIN - Always start a new transaction when receiving a message. If a previous transaction exists, it commits that transaction.(接收消息时候必须有一个新的事务,如果事务已经存在,则先commit,在创建新事务.)
BEGIN_OR_JOIN - If a transaction is already in progress when an event is received, join the transaction, otherwise start a new transaction.(采用事务,如果事务存在,直接使用,如果不存在,创建新事务)
ALWAYS_JOIN - Always expects a transaction to be in progress when an event is received. If there is no transaction, an exception is thrown.(在接收消息时候总是期望有一个事务,如果事务不存在,抛出异常信息)
JOIN_IF_POSSIBLE - Will join the current transaction if one is available. Otherwise, no transaction is created (如果事务存在则使用事务,如果事务不存在,则不创建事务)
举例:
jms-queue-with-transaction.xml
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <vm:connector name="VMQueue"/> <!-- 创建链接 --> <jms:activemq-connector name="jmsConnector" maxRedelivery="1"> <dispatcher-threading-profile doThreading="false"/> </jms:activemq-connector> <!-- 定义压缩转换器 --> <gzip-compress-transformer name="Compress"/> <gzip-uncompress-transformer name="Uncompress"/> <!-- 定义输入队列 --> <endpoint name="in" address="jms://queue/in" exchange-pattern="one-way"/> <!-- see MULE-3342 for what this test is supposed to check --> <model name="model"> <service name="vm-to-jms-queue"> <inbound> <inbound-endpoint address="vm://in" exchange-pattern="one-way"/> </inbound> <outbound> <pass-through-router> <outbound-endpoint ref="in" > <jms:transaction action="ALWAYS_BEGIN" timeout="3000"/> </outbound-endpoint> </pass-through-router> </outbound> </service> <service name="jms-to-vm"> <inbound> <inbound-endpoint ref="in"/> </inbound> <outbound> <pass-through-router> <outbound-endpoint address="vm://out" exchange-pattern="one-way"/> </pass-through-router> </outbound> </service> </model> </mule>
测试代码:
public class MuleJMSMain { public static void main(String[] args) { try { String configFile = "jms-queue-with-transaction.xml"; String[] configFileArr = new String[] {configFile }; MuleContextFactory muleContextFactory = new DefaultMuleContextFactory(); MuleContext context = muleContextFactory .createMuleContext(new SpringXmlConfigurationBuilder(configFileArr)); context.start(); LocalMuleClient client = context.getClient(); client.send("vm://in", new DefaultMuleMessage("i love china ", context)); MuleMessage response = client.request("vm://out", 100000); System.out.println("payload as string :"+response.getPayloadAsString()); } catch (Exception e) { e.printStackTrace(); } } }
相关推荐
Mule ESB 是一个轻量级的基于java的企业服务总线和集成平台, 使得开发人员可以快速,简单的连接多个应用, 使得它们可以交换数据。 Mule ESB 容易集成现有异构系统,包括:JMS, Web Services, JDBC, HTTP, 等. ESB...
文档主要介绍了Mule ESB的使用方法,并结合具体实例加深对ESB的理解,对新手很有帮助哦!
Mule ESB 项目在Linux中的部署与开发与应用案例
图整体结构从上图可见,Mule通过Transports/Connectors与外围的异构系统连接,提供Routing(路由)、TransactionManagement(事务管理)、Transformation(转换)、MessageBroker(消息代理)、...
Mule ESB应用部署 Mule ESB应用的目录结构,配置文件说明
ESB原理及Mule ESB实践
mule,mule esb,Mule,ESB
MuleESB3.0 属于轻量级的消息框架和整合平台,mule云
mule esb开发手册
MuleESB集成webservice+restful(sprintboot+mybatis+mysql)+activeMQ+javamail,五天的研究成果,集成了我所关注的点,希望有更多的朋友一起学习进步。
mule esb 项目 例子 入门
mule esb mule esb 开发工具
MuleEsb开源框架简介.pdf
mule esb mule esb打包手册文档
mule esb 的 简单介绍, 以及一些主要特性的介绍
企业服务总线(Mule ESB)的研究与实现
MuleESB_3.0_中文教程
mule esb 3 user guider: 社区成熟,文档丰富的开源esb mule用户手册