Skip to content

Package: JmsAssistantProducerWrapper

JmsAssistantProducerWrapper

nameinstructionbranchcomplexitylinemethod
JmsAssistantProducerWrapper(ActiveMQConnectionFactory, String, boolean, boolean)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
send(String, String, KapuaSecurityContext)
M: 45 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.broker.core.pool;
14:
15: import javax.jms.JMSException;
16: import javax.jms.TextMessage;
17: import javax.jms.Topic;
18:
19: import org.apache.activemq.ActiveMQConnectionFactory;
20: import org.eclipse.kapua.KapuaException;
21: import org.eclipse.kapua.broker.core.message.JmsUtil;
22: import org.eclipse.kapua.broker.core.message.MessageConstants;
23: import org.eclipse.kapua.broker.core.plugin.KapuaSecurityContext;
24:
25: /**
26: * Broker ({@link JmsProducerWrapper}) implementation.<BR>
27: * This class provide methods to send messages for the device life cycle (to be send outside to a device specific topic)
28: *
29: * @since 1.0
30: */
31: public class JmsAssistantProducerWrapper extends JmsProducerWrapper {
32:
33: public JmsAssistantProducerWrapper(ActiveMQConnectionFactory vmconnFactory, String destination, boolean transacted, boolean start) throws JMSException, KapuaException {
34: super(vmconnFactory, destination, transacted, start);
35: }
36:
37: /**
38: * Send a text message to the specified topic
39: *
40: * @param topic
41: * @param message
42: * @throws JMSException
43: */
44: public void send(String topic, String message, KapuaSecurityContext kapuaSecurityContext) throws JMSException {
45: TextMessage textMessage = session.createTextMessage();
46: Topic jmsTopic = session.createTopic(topic);
47:
48: textMessage.setStringProperty(MessageConstants.PROPERTY_BROKER_ID, kapuaSecurityContext.getBrokerId());
49: textMessage.setStringProperty(MessageConstants.PROPERTY_CLIENT_ID, kapuaSecurityContext.getClientId());
50: textMessage.setLongProperty(MessageConstants.PROPERTY_SCOPE_ID, kapuaSecurityContext.getScopeIdAsLong());
51: textMessage.setStringProperty(MessageConstants.PROPERTY_ORIGINAL_TOPIC, JmsUtil.convertMqttWildCardToJms(topic));
52: textMessage.setLongProperty(MessageConstants.PROPERTY_ENQUEUED_TIMESTAMP, System.currentTimeMillis());
53: textMessage.setText(message);
54: textMessage.setJMSDestination(jmsTopic);
55:
56: producer.send(jmsTopic, textMessage);
57: }
58:
59: }