use of org.eclipse.kapua.transport.message.mqtt.MqttMessage in project kapua by eclipse.
the class MqttClientTest method testMqttClientPublish.
/**
* Ignoring this test for a while. We should fix the build in the first place and then use embedded ActiveMQ
* broker for tests.
*/
@Ignore
@Test
public void testMqttClientPublish() throws Exception {
MqttClientConnectionOptions clientConnectOptions = new MqttClientConnectionOptions();
clientConnectOptions.setClientId(ClientIdGenerator.getInstance().next(MqttClientTest.class.getSimpleName()));
clientConnectOptions.setUsername(username);
clientConnectOptions.setPassword(password.toCharArray());
clientConnectOptions.setEndpointURI(SystemUtils.getBrokerURI());
//
// Connect
MqttClient mqttClient = new MqttClient();
try {
mqttClient.connectClient(clientConnectOptions);
} catch (Exception e) {
fail(e.getMessage());
}
assertTrue("client.connected", mqttClient.isConnected());
//
// Send
String sendTopic = "$EDC/kapua-sys/" + mqttClient.getClientId() + "/" + MqttClientTest.class.getSimpleName() + "/testMqttClientSendTopic";
MqttTopic mqttTopic = new MqttTopic(sendTopic);
MqttPayload mqttPayload = new MqttPayload("testMqttClientSendPayload".getBytes());
MqttMessage mqttMessage = new MqttMessage(mqttTopic, new Date(), mqttPayload);
try {
mqttClient.publish(mqttMessage);
} catch (Exception e) {
fail(e.getMessage());
}
// Disconnect
try {
mqttClient.disconnectClient();
} catch (Exception e) {
fail(e.getMessage());
}
assertFalse("client.connected", mqttClient.isConnected());
}
use of org.eclipse.kapua.transport.message.mqtt.MqttMessage in project kapua by eclipse.
the class MqttFacadeTest method testMqttClientSend.
/**
* Ignoring this test for a while. We should fix the build in the first place and then use embedded ActiveMQ
* broker for tests.
*/
@Ignore
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testMqttClientSend() throws Exception {
//
// Get facade
KapuaLocator locator = KapuaLocator.getInstance();
TransportClientFactory transportFacadeFactory = locator.getFactory(TransportClientFactory.class);
TransportFacade transportFacade = transportFacadeFactory.getFacade();
assertNotNull("client.clientId", transportFacade.getClientId());
//
// Send
String sendTopic = "$EDC/kapua-sys/" + transportFacade.getClientId() + "/" + MqttClientTest.class.getSimpleName() + "/testTransportFacadeSend";
MqttTopic mqttTopic = new MqttTopic(sendTopic);
MqttPayload mqttPayload = new MqttPayload("testTransportFacadeSendPayload".getBytes());
MqttMessage mqttMessage = new MqttMessage(mqttTopic, new Date(), mqttPayload);
TransportMessage responseMessage = null;
try {
responseMessage = transportFacade.sendSync(mqttMessage, null);
} catch (Exception e) {
fail(e.getMessage());
}
//
// Verify
assertNull("responseMessage", responseMessage);
// Clean
try {
transportFacade.clean();
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.eclipse.kapua.transport.message.mqtt.MqttMessage in project kapua by eclipse.
the class MqttClientCallback method messageArrived.
/**
* Implements the API signature {@link MqttCallback#messageArrived(String, org.eclipse.paho.client.mqttv3.MqttMessage)}.
* <p>
* Each {@link org.eclipse.paho.client.mqttv3.MqttMessage} arrived is converted into a
* {@link MqttMessage} and added to the list of received messages.
* </p>
* <p>
* If the total number of received reaches the limit set for expected response messages
* the {@code notifyAll()} is invoked
* </p>
*
* @since 1.0.0
*/
@Override
public void messageArrived(String stringTopic, org.eclipse.paho.client.mqttv3.MqttMessage message) throws Exception {
MqttTopic mqttTopic = new MqttTopic(stringTopic);
MqttPayload mqttPayload = new MqttPayload(message.getPayload());
MqttMessage mqttMessage = new MqttMessage(mqttTopic, new Date(), mqttPayload);
// Add to the received responses
if (responses == null) {
responses = new ArrayList<MqttMessage>();
}
//
// Convert MqttMessage to the given device-levelMessage
responses.add(mqttMessage);
// notify if all expected responses arrived
if (expectedResponses == responses.size()) {
synchronized (this) {
notifyAll();
}
}
}
use of org.eclipse.kapua.transport.message.mqtt.MqttMessage in project kapua by eclipse.
the class TranslatorDataKuraMqtt method translate.
@Override
public MqttMessage translate(KuraMessage kuraMessage) throws KapuaException {
//
// Mqtt request topic
MqttTopic mqttRequestTopic = translate(kuraMessage.getChannel());
//
// Mqtt payload
MqttPayload mqttPayload = translate(kuraMessage.getPayload());
// Return Mqtt message
return new MqttMessage(mqttRequestTopic, new Date(), mqttPayload);
}
use of org.eclipse.kapua.transport.message.mqtt.MqttMessage in project kapua by eclipse.
the class TranslatorRequestKuraMqtt method translate.
@Override
public MqttMessage translate(KuraRequestMessage kuraMessage) throws KapuaException {
//
// Mqtt request topic
MqttTopic mqttRequestTopic = translate(kuraMessage.getChannel());
//
// Mqtt response topic
MqttTopic mqttResponseTopic = generateResponseTopic(kuraMessage.getChannel());
//
// Mqtt payload
MqttPayload mqttPayload = translate(kuraMessage.getPayload());
// Return Mqtt message
return new MqttMessage(mqttRequestTopic, mqttResponseTopic, mqttPayload);
}
Aggregations