Repository: incubator-edgent Updated Branches: refs/heads/master b33d2f58d -> 2907150c5
[Edgent-176] document MqttDevice's MQTT messsage format. Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/560e2fda Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/560e2fda Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/560e2fda Branch: refs/heads/master Commit: 560e2fda9901031b73b743c0470889225c86d1b7 Parents: ec6ccb2 Author: Dale LaBossiere <dlab...@us.ibm.com> Authored: Tue Feb 28 14:13:32 2017 -0500 Committer: Dale LaBossiere <dlab...@us.ibm.com> Committed: Tue Feb 28 14:13:32 2017 -0500 ---------------------------------------------------------------------- .../edgent/connectors/mqtt/iot/MqttDevice.java | 35 +++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/560e2fda/connectors/mqtt/src/main/java/org/apache/edgent/connectors/mqtt/iot/MqttDevice.java ---------------------------------------------------------------------- diff --git a/connectors/mqtt/src/main/java/org/apache/edgent/connectors/mqtt/iot/MqttDevice.java b/connectors/mqtt/src/main/java/org/apache/edgent/connectors/mqtt/iot/MqttDevice.java index f283607..24d26ba 100644 --- a/connectors/mqtt/src/main/java/org/apache/edgent/connectors/mqtt/iot/MqttDevice.java +++ b/connectors/mqtt/src/main/java/org/apache/edgent/connectors/mqtt/iot/MqttDevice.java @@ -43,9 +43,14 @@ import com.google.gson.JsonObject; * the {@link MqttStreams} connector. * <p> * The connector doesn't presume a particular pattern for - * Device MQTT "event" topic and "command" topics though default + * Device MQTT "event" and "command" topics though default * patterns are provided. * <p> + * The MQTT message content for device events and device messages must be JSON, + * but the contents of the JSON are under the control of the collaborating MQTT clients. + * See {@link #commands(String...)} and {@link #events(TStream, String, int) events()} + * for a description of how MQTT messages are converted to and from stream tuples. + * <p> * Connector configuration Properties fall into two categories: * <ul> * <li>MQTT Device abstraction properties</li> @@ -207,6 +212,15 @@ public class MqttDevice implements IotDevice { return mqttConfig; } + /** + * {@inheritDoc} + * + * <p>The event is published to the configured MQTT {@code mqttDevice.event.topic.pattern}, + * as described in the above class documentation, substituting the value returned + * by the {@code eventId} function for "{EVENTID}" in the pattern. + * The MQTT message's payload is the JSON representation + * of the JsonObject stream tuple. + */ @Override public TSink<JsonObject> events(TStream<JsonObject> stream, Function<JsonObject, String> eventId, UnaryOperator<JsonObject> payload, Function<JsonObject, Integer> qos) { @@ -218,11 +232,30 @@ public class MqttDevice implements IotDevice { return connector.publish(stream, topic, payloadFn, qos, jo -> retainEvents); } + /** + * {@inheritDoc} + * + * <p>The event is published to the configured MQTT {@code mqttDevice.event.topic.pattern}, + * as described in the above class documentation, substituting the {@code eventId} for + * "{EVENTID}" in the pattern. + * The MQTT message's payload is the JSON representation + * of the JsonObject stream tuple. + */ @Override public TSink<JsonObject> events(TStream<JsonObject> stream, String eventId, int qos) { return events(stream, jo -> eventId, jo -> jo, jo -> qos); } + /** + * {@inheritDoc} + * + * <p> + * Subscribes to the configured MQTT {@code mqttDevice.command.topic.pattern} + * as described in the above class documentation. + * The received MQTT message's payload is required to be JSON. + * The message's JSON payload is converted to a JsonObject and + * set as the {@code payload} key's value in the stream tuple JsonObject. + */ @Override public TStream<JsonObject> commands(String... commands) { TStream<JsonObject> all = allCommands();