2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.config;
24 import org.apache.activemq.ActiveMQConnectionFactory;
25 import org.apache.activemq.broker.BrokerService;
26 import org.apache.activemq.command.ActiveMQQueue;
27 import org.onap.aai.dmaap.JMSConsumer;
28 import org.onap.aai.dmaap.JMSProducer;
29 import org.springframework.beans.factory.annotation.Value;
30 import org.springframework.context.annotation.Bean;
31 import org.springframework.context.annotation.Configuration;
32 import org.springframework.context.annotation.Profile;
33 import org.springframework.jms.connection.CachingConnectionFactory;
34 import org.springframework.jms.core.JmsTemplate;
35 import org.springframework.jms.listener.DefaultMessageListenerContainer;
37 import javax.annotation.PostConstruct;
41 public class DmaapConfig {
43 @Value("${jms.bind.address}")
44 private String bindAddress;
48 System.setProperty("activemq.tcp.url", bindAddress);
51 @Bean(destroyMethod = "stop")
52 public BrokerService brokerService() throws Exception {
54 BrokerService broker = new BrokerService();
55 broker.addConnector(bindAddress);
56 broker.setPersistent(false);
57 broker.setUseJmx(false);
58 broker.setSchedulerSupport(false);
64 @Bean(name = "connectionFactory")
65 public ActiveMQConnectionFactory activeMQConnectionFactory(){
66 return new ActiveMQConnectionFactory(bindAddress);
70 public CachingConnectionFactory cachingConnectionFactory(){
71 return new CachingConnectionFactory(activeMQConnectionFactory());
74 @Bean(name = "destinationQueue")
75 public ActiveMQQueue activeMQQueue(){
76 return new ActiveMQQueue("IN_QUEUE");
80 public JmsTemplate jmsTemplate(){
81 JmsTemplate jmsTemplate = new JmsTemplate();
83 jmsTemplate.setConnectionFactory(activeMQConnectionFactory());
84 jmsTemplate.setDefaultDestination(activeMQQueue());
90 public JMSProducer jmsProducer(){
91 return new JMSProducer();
95 public JMSConsumer jmsConsumer() throws Exception {
96 return new JMSConsumer();
100 public DefaultMessageListenerContainer defaultMessageListenerContainer() throws Exception {
102 DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer();
104 messageListenerContainer.setConnectionFactory(cachingConnectionFactory());
105 messageListenerContainer.setDestinationName("IN_QUEUE");
106 messageListenerContainer.setMessageListener(jmsConsumer());
108 return messageListenerContainer;