2016-07-15 2 views
0

트랜잭션이 롤백되지 않는 이유를 알지 못해서 벽에 머리가 부러졌습니다.트랜잭션을 롤백하지 않는 Jms 메시지 기반 채널 adaper

내 프로젝트에 스프링 통합을 사용하고 아래처럼 내 applicationContext.xml 보인다 :

<context:component-scan base-package="com.jms.spring.integration.*"></context:component-scan> 

<tx:annotation-driven/> 

<int:poller default="true" id="poller" fixed-delay="500"></int:poller> 

<int-jms:message-driven-channel-adapter 
    channel="processEmpChannel" destination-name="com.test.inputqueue" acknowledge="transacted" connection-factory="targetConnectionFactory"/> 

<bean id="targetConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> 
    <property name="brokerURL" value="tcp://localhost:61616"></property> 
</bean> 
<bean id="springExample" class="com.jms.spring.integration.SpringIntegrationJmsExample"> 
</bean> 

<int:service-activator input-channel="processEmpChannel" 
    ref="springExample" method="handleClient"> 
    <int:poller ref="poller"></int:poller> 
</int:service-activator> 

내 자바 파일은 다음과 같다 :

package com.jms.spring.integration; 

import org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.jms.core.JmsTemplate; 
import org.springframework.transaction.annotation.Transactional; 

public class SpringIntegrationJmsExample { 
    @Transactional 
    public void handleClient(String str){ 
     System.out.println("handleClient"); 
     throw new RuntimeException("Throwing some runtime exception...."); 
    } 

    public static void main(String[] args) { 
     ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); 
    } 
} 

나는 큐에 메시지를 게시, I 예외는 보지만 대기열의 메시지는 소비됩니다. 트랜잭션이 롤백 중이 지 않으며 메시지가 대기열에 다시 저장되지 않습니다. 내가 어디로 잘못 가고 있는지 알려주세요.

답변

1

processEmpChannel은 QueueChannel이므로; 메시지가 채널 큐에 놓이면 (서비스에 의해 처리되기 전에) 트랜잭션이 커밋됩니다.

트랜잭션이 예상대로 작동하려면 DirectChannel을 사용해야하므로 서비스 활성화 기가 리스너 컨테이너 스레드에서 실행 (폴러 제거)됩니다.

Message ChannelsTransaction Support을 참조하십시오.

+0

감사합니다. 그것은 매력처럼 작용했습니다. 그러나 AMQ는 8 번 전달하려고 시도하고 메시지가 소비됩니다. 어떻게 죽은 대기열에 8 회 시도한 후에도 실패한 메시지를 넣으려면 어떻게 구성합니까? – zilcuanu

+1

브로커에 구성되었습니다. 이것은 JMS 스펙의 일부가 아닙니다. AMQ 문서를 검색하십시오. –