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=========================================================
21 package org.onap.aai.web;
23 import javax.annotation.PostConstruct;
25 import org.apache.activemq.ActiveMQConnectionFactory;
26 import org.apache.activemq.broker.BrokerService;
27 import org.apache.activemq.command.ActiveMQQueue;
28 import org.onap.aai.dmaap.AAIDmaapEventJMSConsumer;
29 import org.onap.aai.dmaap.AAIDmaapEventJMSProducer;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.beans.factory.annotation.Qualifier;
32 import org.springframework.beans.factory.annotation.Value;
33 import org.springframework.context.ApplicationContext;
34 import org.springframework.context.annotation.Bean;
35 import org.springframework.context.annotation.Configuration;
36 import org.springframework.context.annotation.Profile;
37 import org.springframework.http.HttpHeaders;
38 import org.springframework.jms.connection.CachingConnectionFactory;
39 import org.springframework.jms.core.JmsTemplate;
40 import org.springframework.jms.listener.DefaultMessageListenerContainer;
41 import org.springframework.web.client.RestTemplate;
45 public class DmaapConfig {
48 private ApplicationContext ctx;
51 @Qualifier("dmaapRestTemplate")
52 private RestTemplate dmaapRestTemplate;
55 @Qualifier("dmaapHeaders")
56 private HttpHeaders dmaapHeaders;
58 @Value("${jms.bind.address}")
59 private String bindAddress;
63 System.setProperty("activemq.tcp.url", bindAddress);
66 @Bean(destroyMethod = "stop")
67 public BrokerService brokerService() throws Exception {
69 BrokerService broker = new BrokerService();
70 broker.addConnector(bindAddress);
71 broker.setPersistent(false);
72 broker.setUseJmx(false);
73 broker.setSchedulerSupport(false);
79 @Bean(name = "connectionFactory")
80 public ActiveMQConnectionFactory activeMQConnectionFactory() {
81 return new ActiveMQConnectionFactory(bindAddress);
85 public CachingConnectionFactory cachingConnectionFactory() {
86 return new CachingConnectionFactory(activeMQConnectionFactory());
89 @Bean(name = "destinationQueue")
90 public ActiveMQQueue activeMQQueue() {
91 return new ActiveMQQueue("IN_QUEUE");
95 public JmsTemplate jmsTemplate() {
96 JmsTemplate jmsTemplate = new JmsTemplate();
98 jmsTemplate.setConnectionFactory(activeMQConnectionFactory());
99 jmsTemplate.setDefaultDestination(activeMQQueue());
105 public AAIDmaapEventJMSProducer jmsProducer() {
106 return new AAIDmaapEventJMSProducer();
109 @Bean(name = "jmsConsumer")
110 public AAIDmaapEventJMSConsumer jmsConsumer() throws Exception {
111 return new AAIDmaapEventJMSConsumer(ctx.getEnvironment(), dmaapRestTemplate, dmaapHeaders);
115 public DefaultMessageListenerContainer defaultMessageListenerContainer() throws Exception {
117 DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer();
119 messageListenerContainer.setConnectionFactory(cachingConnectionFactory());
120 messageListenerContainer.setDestinationName("IN_QUEUE");
121 messageListenerContainer.setMessageListener(jmsConsumer());
123 return messageListenerContainer;