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.web;
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.AAIDmaapEventJMSConsumer;
26 import org.onap.aai.dmaap.AAIDmaapEventJMSProducer;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.beans.factory.annotation.Qualifier;
29 import org.springframework.beans.factory.annotation.Value;
30 import org.springframework.context.ApplicationContext;
31 import org.springframework.context.annotation.Bean;
32 import org.springframework.context.annotation.Configuration;
33 import org.springframework.context.annotation.Profile;
34 import org.springframework.http.HttpHeaders;
35 import org.springframework.jms.connection.CachingConnectionFactory;
36 import org.springframework.jms.core.JmsTemplate;
37 import org.springframework.jms.listener.DefaultMessageListenerContainer;
39 import javax.annotation.PostConstruct;
40 import org.springframework.web.client.RestTemplate;
44 public class DmaapConfig {
47 private ApplicationContext ctx;
50 @Qualifier("dmaapRestTemplate")
51 private RestTemplate dmaapRestTemplate;
54 @Qualifier("dmaapHeaders")
55 private HttpHeaders dmaapHeaders;
57 @Value("${jms.bind.address}")
58 private String bindAddress;
62 System.setProperty("activemq.tcp.url", bindAddress);
65 @Bean(destroyMethod = "stop")
66 public BrokerService brokerService() throws Exception {
68 BrokerService broker = new BrokerService();
69 broker.addConnector(bindAddress);
70 broker.setPersistent(false);
71 broker.setUseJmx(false);
72 broker.setSchedulerSupport(false);
78 @Bean(name = "connectionFactory")
79 public ActiveMQConnectionFactory activeMQConnectionFactory(){
80 return new ActiveMQConnectionFactory(bindAddress);
84 public CachingConnectionFactory cachingConnectionFactory(){
85 return new CachingConnectionFactory(activeMQConnectionFactory());
88 @Bean(name = "destinationQueue")
89 public ActiveMQQueue activeMQQueue(){
90 return new ActiveMQQueue("IN_QUEUE");
94 public JmsTemplate jmsTemplate(){
95 JmsTemplate jmsTemplate = new JmsTemplate();
97 jmsTemplate.setConnectionFactory(activeMQConnectionFactory());
98 jmsTemplate.setDefaultDestination(activeMQQueue());
104 public AAIDmaapEventJMSProducer jmsProducer(){
105 return new AAIDmaapEventJMSProducer();
108 @Bean(name="jmsConsumer")
109 public AAIDmaapEventJMSConsumer jmsConsumer() throws Exception {
110 return new AAIDmaapEventJMSConsumer(ctx.getEnvironment(), dmaapRestTemplate, dmaapHeaders);
114 public DefaultMessageListenerContainer defaultMessageListenerContainer() throws Exception {
116 DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer();
118 messageListenerContainer.setConnectionFactory(cachingConnectionFactory());
119 messageListenerContainer.setDestinationName("IN_QUEUE");
120 messageListenerContainer.setMessageListener(jmsConsumer());
122 return messageListenerContainer;