/** * Subscribe to the MQTT topic(s) and create a {@code TStream<String>}. * <p> * A convenience function. * Each message's payload is expected/required to be a UTF-8 encoded string. * Only the converted payload is present the generated tuple. * * @param <T> Tuple type * @param topicFilter the topic(s) to subscribe to. * @param qos the maximum Quality of Service to use. * @return {@code TStream<String>} * @see #publish(TStream, String, int, boolean) */ public <T> TStream<String> subscribe(String topicFilter, int qos) { addSubscribe(); return topology().events(new MqttSubscriber<String>(connector, topicFilter, qos, (topic, payload) -> new String(payload, StandardCharsets.UTF_8))); }
/** * Subscribe to the MQTT topic(s) and create a stream of tuples of type {@code T}. * @param <T> Tuple type * @param topicFilter the topic(s) to subscribe to. * @param qos the maximum Quality of Service to use. * @param message2Tuple function to convert {@code (topic, payload)} to * a tuple of type {@code T} * @return {@code TStream<T>} */ public <T> TStream<T> subscribe(String topicFilter, int qos, BiFunction<String, byte[], T> message2Tuple) { addSubscribe(); return topology().events(new MqttSubscriber<T>(connector, topicFilter, qos, message2Tuple)); }