【问题标题】:What is the use of @TransactionAttribute@TransactionAttribute 有什么用
【发布时间】:2018-08-03 04:34:42
【问题描述】:

下面的MDB代码片段将作为消息提供者部署在JBoss和IBM MQ中,@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)有什么用 注解?为什么要保持在班级级别?

import javax.ejb.*;
import javax.jms.Message;
import javax.jms.TextMessage;
import javax.jms.JMSException;
import javax.ejb.MessageDriven;
import javax.jms.MessageListener;
import javax.ejb.ActivationConfigProperty;
import org.jboss.ejb3.annotation.ResourceAdapter;

@MessageDriven( name="MyMDB",
        activationConfig = 
        { 
            @ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),
            @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"),
            @ActivationConfigProperty(propertyName = "hostName", propertyValue = "MQ.HOST.NAME"),
            @ActivationConfigProperty(propertyName = "port", propertyValue = "MQ.PORT"),
            @ActivationConfigProperty(propertyName = "channel", propertyValue = "MQ.CHANNEL.NAME"),
            @ActivationConfigProperty(propertyName = "queueManager", propertyValue = "MQ.QUEUE.MANAGER"),
            @ActivationConfigProperty(propertyName = "destination", propertyValue = "MQ.QUEUE.NAME"),
            @ActivationConfigProperty(propertyName = "transportType", propertyValue = "MQ.CLIENT")
        }) 
@ResourceAdapter(value = "wmq.jmsra.rar")
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)

public class MyMDB implements MessageListener{

    public void onMessage(Message message) {
        TextMessage textMessage = (TextMessage) message;
        try {
            System.out.println("nnt Message Received by MDB : "+ textMessage.getText());
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}

【问题讨论】:

    标签: jakarta-ee transactions ibm-mq message-driven-bean


    【解决方案1】:

    您包含的 sn-p 代表 MDB 的声明性事务配置,它告诉容器它应该如何管理此 MDB 的事务。

    我找不到比 java 事务设计策略书的引用更好的这个属性的解释:

    NotSupported 属性(Spring 中的 PROPAGATION_NOT_SUPPORTED)告诉容器被调用的方法不使用事务。如果事务已经开始,它将被挂起,直到方法完成。如果不存在事务,容器将调用该方法而不启动事务

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-04
      • 2013-11-24
      • 1970-01-01
      • 1970-01-01
      • 2015-09-07
      • 1970-01-01
      • 2014-07-29
      • 2015-02-18
      相关资源
      最近更新 更多