Utrzymuj transakcję w przepływie integracji Spring
Brama Inboud:
<int-http:inbound-gateway id="inbound.gateway"
request-channel="transactional.channel.input"
reply-channel="channel.output"
error-channel="channel.error"
request-payload-type="java.lang.String"
</int-http:inbound-gateway>
Definicja porady:
<tx:advice id="advice">
<tx:attributes>
<tx:method name="send" propagation="REQUIRES_NEW" rollback-for="MyClassException"/>
</tx:attributes>
</tx:advice>
Konfiguracja porad:
<aop:config>
<aop:advisor advice-ref="advice" pointcut="bean(transactional.channel.input)"/>
</aop:config>
Łańcuch, który musi być transakcyjny:
<int:chain input-channel="transactional.channel.input" output-channel="non.transactional.channel.input>
<int:service-activator ref="v1.registerUser.service" method="registerUser"/>
<int:service-activator ref="v1.saveObject.service" method="saveObject"/>
</int:chain>
Łańcuch, który wymaga wcześniejszej transakcji, aby wygenerować identyfikator obiektu w ostatnim kroku łańcucha transational:
<int:chain input-channel="non.transactional.channel.input" output-channel="channel.output">
<int:service-activator ref="v1.getObjectId.service" method="getObjectId"/>
<int:object-to-json-transformer/>
</int:chain>
Mając ten uproszczony kontekst, kiedy uzyskuję dostęp do identyfikatora w usłudze getObjectId, transakcja nie została wykonana.
Tak więc transakcja wydaje się być zatwierdzona na poziomie wyjściowym bramy wejściowej.