Class MqttPublisher
java.lang.Object
org.chenile.mqtt.pubsub.MqttPublisher
- All Implemented Interfaces:
ChenilePub
Used to publish MQTT messages. Defaults are picked up from application properties.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int(package private) org.slf4j.Logger(package private) PubSubInfoProviderprivate intprivate booleanprivate org.eclipse.paho.mqttv5.client.MqttAsyncClient -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidPublish to the topic with the specified Qos of the system (as configured in application.yml)voidPublish to the topic with the default Qos of the system (as configured in application.yml)voidpublishToOperation(String service, String operationName, String payload, Map<String, Object> properties) Send a message to a service and operation.voidsendAck(org.eclipse.paho.mqttv5.common.MqttMessage message) voidsetActionTimeout(int actionTimeout) voidsetQos(int qos) voidsetRetain(boolean retain) private static StringsubstituteProperties(String s, Map<String, Object> properties) Substitute the property in the place holder.
-
Field Details
-
logger
org.slf4j.Logger logger -
v5Client
-
actionTimeout
private int actionTimeout -
qos
private int qos -
pubSubInfoProvider
-
retain
private boolean retain
-
-
Constructor Details
-
MqttPublisher
public MqttPublisher()
-
-
Method Details
-
setActionTimeout
public void setActionTimeout(int actionTimeout) -
setQos
public void setQos(int qos) -
setRetain
public void setRetain(boolean retain) -
publishToOperation
public void publishToOperation(String service, String operationName, String payload, Map<String, Object> properties) Send a message to a service and operation. Topic and Qos are computed from MQTTConfig for the service and operation name. Topics might have placeholders that will be substituted from the properties.- Specified by:
publishToOperationin interfaceChenilePub- Parameters:
service- the service that will receive this messageoperationName- the operation within the service that will receive this messagepayload- the payload that needs to be sentproperties- the headers properties that need to be sent- Throws:
Exception- if there is an error in dispatching the message
-
substituteProperties
-
publish
Publish to the topic with the default Qos of the system (as configured in application.yml)- Specified by:
publishin interfaceChenilePub- Parameters:
topic- the topic to publish topayload- the payloadproperties- the user properties that need to be put into the message- Throws:
org.eclipse.paho.mqttv5.common.MqttPersistenceException- if there is a problem in persisting the message that needs to be sentorg.eclipse.paho.mqttv5.common.MqttException- if there is any other exception
-
asyncPublish
- Specified by:
asyncPublishin interfaceChenilePub
-
publish
Publish to the topic with the specified Qos of the system (as configured in application.yml)- Parameters:
topic- the topic to publish togivenQos- the Qos that needs to be sent. In case this is -1 then system default will be used.payload- the payloadproperties- the user properties that need to be put into the message- Throws:
org.eclipse.paho.mqttv5.common.MqttPersistenceException- if there is a problem in persisting the message that needs to be sentorg.eclipse.paho.mqttv5.common.MqttException- if there is any other exception
-
sendAck
-