renaming/constant instead of literal/unused items
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / dmaap / AAIDmaapEventJMSProducer.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  *  Modifications Copyright © 2018 IBM.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22 package org.onap.aai.dmaap;
23
24 import org.apache.activemq.ActiveMQConnectionFactory;
25 import org.apache.activemq.command.ActiveMQQueue;
26 import org.json.JSONObject;
27 import org.onap.aai.util.AAIConfig;
28 import org.springframework.jms.connection.CachingConnectionFactory;
29 import org.springframework.jms.core.JmsTemplate;
30
31 public class AAIDmaapEventJMSProducer implements MessageProducer {
32
33     private JmsTemplate jmsTemplate;
34
35     public AAIDmaapEventJMSProducer() {
36         if("true".equals(AAIConfig.get("aai.jms.enable", "true"))){
37             this.jmsTemplate = new JmsTemplate();
38             String activeMqTcpUrl = System.getProperty("activemq.tcp.url", "tcp://localhost:61547");
39             this.jmsTemplate.setConnectionFactory(new CachingConnectionFactory(new ActiveMQConnectionFactory(activeMqTcpUrl)));
40             this.jmsTemplate.setDefaultDestination(new ActiveMQQueue("IN_QUEUE"));
41         }
42     }
43
44     public void sendMessageToDefaultDestination(JSONObject finalJson) {
45         if(jmsTemplate != null){
46             jmsTemplate.convertAndSend(finalJson.toString());
47             CachingConnectionFactory ccf = (CachingConnectionFactory) this.jmsTemplate.getConnectionFactory();
48             ccf.destroy();
49         }
50     }
51 }