春季-在提交插入的记录之前,在MDB中发送和接收的JMS消息

时间:2019-06-21 14:10:26

标签: java spring spring-transactions

我有一个非常简单的场景,其中涉及应用程序服务器(WebSphere)中的数据库和JMS。

我正在使用Spring框架,并且是Spring事务管理的新手。

我还检查了我的交易经理的日志  org.springframework.transaction.jta.WebSphereUowTransactionManager。

我的bean.xml看起来像这样。

<tx:annotation-driven transaction-manager="transactionManager"/>    
<tx:jta-transaction-manager />

<Bean id="helper" class="Helper"></bean>
<Bean id="data" class="Data">
<properties name ="helper" ref ="helper"/>
</bean>

我的代码如下。

import com.intellect.ipsh.stpframework.jms.JMSUtil;

Class Data implements ApplicationContextAware {

private JMSUtil jmsUtil;
private Helper helper;
private String commonsQueueDestination = "MYQUEUE";
@Override
    public void setApplicationContext(ApplicationContext arg0) throws BeansException {
        this.context = arg0;
    jmsUtil = (JMSUtil )    arg0.getBean("jmsUtil");
    }


public void process(){
helper.saveData("some input");
helper.sendMessage("{"key":"Value"}");
}

public void sendMessage(String requestJson){
jmsUtil.sendTo(commonsQueueDestination, requestJson.toString());
}

}

Class Helper {
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void saveData(Object d){
//JDBC to insert data (throght DBLink )
}
}

现在,当在WebSphere中执行以上代码时,插入的记录将提交给我的事务方法,我的消息正在到达其目标MDB,因为我的记录未找到错误。

0 个答案:

没有答案