spring_reference/IV. Spring Boot features/32.4. Mixing XA and non-XA ...

21 lines
1.0 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 32.4. 混合XA和non-XA的JMS连接
当使用JTA时主要的JMS ConnectionFactory bean将是XA aware并参与到分布式事务中。有些情况下你可能需要使用non-XA的ConnectionFactory去处理一些JMS消息。例如你的JMS处理逻辑可能比XA超时时间长。
如果想使用一个non-XA的ConnectionFactory你可以注入nonXaJmsConnectionFactory bean而不是@Primary jmsConnectionFactory bean。为了保持一致jmsConnectionFactory bean将以别名xaJmsConnectionFactor来被使用。
示例如下:
```java
// Inject the primary (XA aware) ConnectionFactory
@Autowired
private ConnectionFactory defaultConnectionFactory;
// Inject the XA aware ConnectionFactory (uses the alias and injects the same as above)
@Autowired
@Qualifier("xaJmsConnectionFactory")
private ConnectionFactory xaConnectionFactory;
// Inject the non-XA aware ConnectionFactory
@Autowired
@Qualifier("nonXaJmsConnectionFactory")
private ConnectionFactory nonXaConnectionFactory;
```