2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.config;
22 import org.apache.activemq.ActiveMQConnectionFactory;
23 import org.apache.activemq.broker.BrokerService;
24 import org.apache.activemq.command.ActiveMQQueue;
25 import org.onap.aai.dmaap.JMSConsumer;
26 import org.onap.aai.dmaap.JMSProducer;
27 import org.springframework.beans.factory.annotation.Value;
28 import org.springframework.context.annotation.Bean;
29 import org.springframework.context.annotation.Configuration;
30 import org.springframework.context.annotation.Profile;
31 import org.springframework.jms.connection.CachingConnectionFactory;
32 import org.springframework.jms.core.JmsTemplate;
33 import org.springframework.jms.listener.DefaultMessageListenerContainer;
35 import javax.annotation.PostConstruct;
39 public class DmaapConfig {
41 @Value("${jms.bind.address}")
42 private String bindAddress;
46 System.setProperty("activemq.tcp.url", bindAddress);
49 @Bean(destroyMethod = "stop")
50 public BrokerService brokerService() throws Exception {
52 BrokerService broker = new BrokerService();
53 broker.addConnector(bindAddress);
54 broker.setPersistent(false);
55 broker.setUseJmx(false);
56 broker.setSchedulerSupport(false);
62 @Bean(name = "connectionFactory")
63 public ActiveMQConnectionFactory activeMQConnectionFactory(){
64 return new ActiveMQConnectionFactory(bindAddress);
68 public CachingConnectionFactory cachingConnectionFactory(){
69 return new CachingConnectionFactory(activeMQConnectionFactory());
72 @Bean(name = "destinationQueue")
73 public ActiveMQQueue activeMQQueue(){
74 return new ActiveMQQueue("IN_QUEUE");
78 public JmsTemplate jmsTemplate(){
79 JmsTemplate jmsTemplate = new JmsTemplate();
81 jmsTemplate.setConnectionFactory(activeMQConnectionFactory());
82 jmsTemplate.setDefaultDestination(activeMQQueue());
88 public JMSProducer jmsProducer(){
89 return new JMSProducer();
93 public JMSConsumer jmsConsumer() throws Exception {
94 return new JMSConsumer();
98 public DefaultMessageListenerContainer defaultMessageListenerContainer() throws Exception {
100 DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer();
102 messageListenerContainer.setConnectionFactory(cachingConnectionFactory());
103 messageListenerContainer.setDestinationName("IN_QUEUE");
104 messageListenerContainer.setMessageListener(jmsConsumer());
106 return messageListenerContainer;