@Override public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception { s_logger.info( "mqtt message arrived. message " + topic + ":'" + new String(mqttMessage.getPayload()) + "' qos=" + mqttMessage.getQos() + " retained=" + mqttMessage.isRetained()); final String message = new String(mqttMessage.getPayload()); final int qos = mqttMessage.getQos(); final boolean retained = mqttMessage.isRetained(); final Date received = new Date(); if (m_session != null) { // prevent blocking of modal thread new ClientAsyncJob("mqtt message arrived (async wrapper)", m_session, true) { @Override protected void runVoid(IProgressMonitor monitor) throws Exception { // implement ui changes in a sync job new ClientSyncJob("mqtt message arrived", m_session) { @Override protected void runVoid(IProgressMonitor monitor1) throws Throwable { MessageHandlingService service = SERVICES.getService(MessageHandlingService.class); service.handleMessage(topic, message, qos, retained, received); } }.schedule(); } }.schedule(); } else { s_logger.error("client session is null"); } }
@Override public Message<?> toMessage(String topic, MqttMessage mqttMessage) { try { AbstractIntegrationMessageBuilder<Object> messageBuilder = getMessageBuilderFactory() .withPayload(mqttBytesToPayload(mqttMessage)) .setHeader(MqttHeaders.QOS, mqttMessage.getQos()) .setHeader(MqttHeaders.DUPLICATE, mqttMessage.isDuplicate()) .setHeader(MqttHeaders.RETAINED, mqttMessage.isRetained()); if (topic != null) { messageBuilder.setHeader(MqttHeaders.TOPIC, topic); } return messageBuilder.build(); } catch (Exception e) { throw new MessageConversionException("failed to convert object to Message", e); } }
private void processSetGet(String namePart, MqttMessage msg, boolean set) { if (msg.isRetained()) { L.finer("Ignoring retained message " + msg + " to " + namePart); return; } // Now translate the topic into a group address GroupAddressInfo gai = GroupAddressManager.getGAInfoForName(namePart); if (gai == null) { L.warning( "Unable to translate name " + namePart + " into a group address, ignoring message " + msg); return; } L.fine("Name " + namePart + " translates to GA " + gai.address); String data = new String(msg.getPayload(), StandardCharsets.UTF_8); if (set) KNXConnector.doGroupWrite(gai.address, data, gai); else KNXConnector.doGroupRead(gai.address, data, gai); }
/** * Store an MQTT message * * @param clientHandle identifier for the client storing the message * @param topic The topic on which the message was published * @param message the arrived MQTT message * @return an identifier for the message, so that it can be removed when appropriate */ @Override public String storeArrived(String clientHandle, String topic, MqttMessage message) { db = mqttDb.getWritableDatabase(); traceHandler.traceDebug( TAG, "storeArrived{" + clientHandle + "}, {" + message.toString() + "}"); byte[] payload = message.getPayload(); int qos = message.getQos(); boolean retained = message.isRetained(); boolean duplicate = message.isDuplicate(); ContentValues values = new ContentValues(); String id = java.util.UUID.randomUUID().toString(); values.put(MqttServiceConstants.MESSAGE_ID, id); values.put(MqttServiceConstants.CLIENT_HANDLE, clientHandle); values.put(MqttServiceConstants.DESTINATION_NAME, topic); values.put(MqttServiceConstants.PAYLOAD, payload); values.put(MqttServiceConstants.QOS, qos); values.put(MqttServiceConstants.RETAINED, retained); values.put(MqttServiceConstants.DUPLICATE, duplicate); values.put(MTIMESTAMP, System.currentTimeMillis()); try { db.insertOrThrow(ARRIVED_MESSAGE_TABLE_NAME, null, values); } catch (SQLException e) { traceHandler.traceException(TAG, "onUpgrade", e); throw e; } int count = getArrivedRowCount(clientHandle); traceHandler.traceDebug( TAG, "storeArrived: inserted message with id of {" + id + "} - Number of messages in database for this clientHandle = " + count); return id; }
ParcelableMqttMessage(MqttMessage original) { super(original.getPayload()); setQos(original.getQos()); setRetained(original.isRetained()); setDuplicate(original.isDuplicate()); }