Step 1: The bare-bone Spring Java configuration
1 2 3 4 5 6 7 |
//.... @Configuration @ComponentScan("com.myapp") public class MOMConfig { //.... } |
Step 2: How to connect? Configuring the “ConnectionFactory”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
//.... @Configuration @ComponentScan("com.myapp") public class MOMConfig { @Autowired private Environment environment; @Bean public ConnectionFactory connectionFactory() throws JMSException { MQTopicConnectionFactory cf = new MQTopicConnectionFactory(); cf.setTransportType(environment.getProperty("env.mq.transport.type", Integer.class, DEFAULT_MQ_TRANSPORT_TYPE)); cf.setHostName(environment.getRequiredProperty("env.mq.hostname")); cf.setChannel(environment.getRequiredProperty("env.mq.channel")); cf.setPort(environment.getRequiredProperty("env.mq.port", Integer.class)); cf.setQueueManager(environment.getRequiredProperty("env.mq.queue.manager")); cf.setClientID(environment.getProperty("env.mq.client.id", DEFAULT_MQ_CLIENT_ID) + "_" + environment.getRequiredProperty("env.mq.environment")); return cf; } } |
Step 3: What destination to use? Configure the destination. E.g. Topic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
//.... @Configuration @ComponentScan("com.myapp") public class MOMConfig { //..... @Bean public Destination destination() throws JMSException { MQTopic topic = new MQTopic(); topic.setBaseTopicName(environment.getProperty("myapp.topic", DEFAULT_TOPIC)); topic.setPersistence(environment.getProperty("env.mq.delivery.mode", Integer.class, DEFAULT_MQ_DELIVERY_MODE)); return topic; } } |
Step 4: The JMsTemplate that uses both the “ConnectionFactory” and the…