@Override public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception { try { String msgText = mqttMessage.toString(); if (log.isDebugEnabled()) { log.debug(msgText); } PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId); if (log.isDebugEnabled()) { log.debug("Event received in MQTT Event Adapter - " + msgText); } if (contentValidator != null && contentTransformer != null) { ContentInfo contentInfo; Map<String, Object> dynamicProperties = new HashMap<>(); dynamicProperties.put(MQTTEventAdapterConstants.TOPIC, topic); msgText = (String) contentTransformer.transform(msgText, dynamicProperties); contentInfo = contentValidator.validate(msgText, dynamicProperties); if (contentInfo != null && contentInfo.isValidContent()) { eventAdapterListener.onEvent(contentInfo.getMessage()); } } else { eventAdapterListener.onEvent(msgText); } } finally { PrivilegedCarbonContext.endTenantFlow(); } }