22
33import java .sql .SQLException ;
44
5- import javax .jms .ConnectionFactory ;
5+ import javax .jms .Destination ;
66import javax .jms .JMSException ;
77import javax .jms .QueueConnectionFactory ;
8+ import javax .jms .Session ;
89import javax .sql .DataSource ;
910
1011import org .slf4j .Logger ;
1112import org .slf4j .LoggerFactory ;
1213import org .springframework .beans .factory .annotation .Autowired ;
14+ import org .springframework .boot .autoconfigure .jms .DefaultJmsListenerContainerFactoryConfigurer ;
1315import org .springframework .context .annotation .Bean ;
1416import org .springframework .context .annotation .Configuration ;
15- import org .springframework .jms .core .JmsTemplate ;
17+ import org .springframework .core .env .Environment ;
18+ import org .springframework .jms .config .DefaultJmsListenerContainerFactory ;
19+ import org .springframework .jms .config .JmsListenerContainerFactory ;
20+ import org .springframework .jms .support .destination .DynamicDestinationResolver ;
1621
1722import oracle .jdbc .pool .OracleDataSource ;
1823import oracle .jms .AQjmsFactory ;
19- import oracle .ucp .jdbc .PoolDataSource ;
20- import org .springframework .core .env .Environment ;
2124
2225@ Configuration
2326public class OracleAQConfiguration {
24- Logger logger = LoggerFactory .getLogger (OracleAQConfiguration .class );
25-
26- @ Autowired
27- private Environment environment ;
28-
29- @ Bean
30- public DataSource dataSource () throws SQLException {
31- OracleDataSource ds = new OracleDataSource ();
32-
33- ds .setUser (environment .getProperty ("db_user" ));
34- logger .info ("USER: " + environment .getProperty ("db_user" ));
35-
36- ds .setPassword (environment .getProperty ("db_password" ));
37- logger .info ("Password: " + environment .getProperty ("db_password" ));
38-
39- ds .setURL (environment .getProperty ("db_url" ));
40- logger .info ("URL: " + environment .getProperty ("db_url" ));
41-
42- logger .info ("OracleAQConfiguration-->dataSource success" +ds );
43- return ds ;
44- }
45-
46- @ Bean
47- public QueueConnectionFactory connectionFactory (DataSource dataSource ) throws JMSException , SQLException {
48- logger .info ("OracleAQConfiguration-->AQ factory success" );
49- return AQjmsFactory .getQueueConnectionFactory (dataSource );
50- }
51-
52- @ Bean
53- public JmsTemplate jmsTemplate (ConnectionFactory conFactory ) throws Exception {
54- JmsTemplate jmsTemplate = new JmsTemplate ();
55- jmsTemplate .setDefaultDestinationName ("inventoryqueue" );
56- jmsTemplate .setSessionTransacted (true );
57- jmsTemplate .setConnectionFactory (conFactory );
58-
59- logger .info ("Jms Configuration-->jms template success" );
60- return jmsTemplate ;
61- }
27+ Logger logger = LoggerFactory .getLogger (OracleAQConfiguration .class );
28+
29+ @ Autowired
30+ private Environment environment ;
31+
32+ @ Bean
33+ public DataSource dataSource () throws SQLException {
34+ OracleDataSource ds = new OracleDataSource ();
35+
36+ ds .setUser (environment .getProperty ("db_user" ));
37+ logger .info ("USER: " + environment .getProperty ("db_user" ));
38+
39+ ds .setPassword (environment .getProperty ("db_password" ));
40+ logger .info ("Password: " + environment .getProperty ("db_password" ));
41+
42+ ds .setURL (environment .getProperty ("db_url" ));
43+ logger .info ("URL: " + environment .getProperty ("db_url" ));
44+
45+ logger .info ("OracleAQConfiguration: dataSource success" + ds );
46+ return ds ;
47+ }
48+
49+ @ Bean
50+ public QueueConnectionFactory connectionFactory (DataSource dataSource ) throws JMSException , SQLException {
51+ logger .info ("OracleAQConfiguration: connectionFactory success" );
52+ return AQjmsFactory .getQueueConnectionFactory (dataSource );
53+ }
54+
55+ @ Bean
56+ public JmsListenerContainerFactory <?> queueConnectionFactory (QueueConnectionFactory connectionFactory ,
57+ DefaultJmsListenerContainerFactoryConfigurer configurer ) {
58+ DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory ();
59+ configurer .configure (factory , connectionFactory );
60+ factory .setPubSubDomain (false );
61+ return factory ;
62+ }
63+
64+ @ Bean
65+ public JmsListenerContainerFactory <?> topicConnectionFactory (QueueConnectionFactory connectionFactory ,
66+ DefaultJmsListenerContainerFactoryConfigurer configurer ) {
67+ DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory ();
68+ configurer .configure (factory , connectionFactory );
69+ factory .setPubSubDomain (true );
70+ return factory ;
71+ }
72+
73+ @ Bean
74+ public DynamicDestinationResolver destinationResolver () {
75+ return new DynamicDestinationResolver () {
76+ @ Override
77+ public Destination resolveDestinationName (Session session , String destinationName , boolean pubSubDomain )
78+ throws JMSException {
79+ if (destinationName .contains ("INVENTORY" )) {
80+ pubSubDomain = true ;
81+ }
82+ return super .resolveDestinationName (session , destinationName , pubSubDomain );
83+ }
84+ };
85+ }
6286}
0 commit comments