Mule ESB 学习笔记(10)mule事务配置

阅读更多

       在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

 

 

 




    
     
     
    
        
    
    
    
    
    
    
  
    
    
    
    
    
        
            
                
            
            
                
                    
                        
                    
                
            
        
        
        
            
                
            
            
                
                    
                
            
        
    

 

测试代码:

 

 

 

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,EIP,SOA,JMS,queue)