2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mqtt.discovery;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
19 * The {@link MQTTTopicDiscoveryService} service is responsible for subscribing to a topic on
20 * all currently available broker connections as well as later on appearing broker connections.
22 * @author David Graeff - Initial contribution
25 public interface MQTTTopicDiscoveryService {
27 * Subscribe to the given topic and get notified of messages on that topic via the listener.
28 * Subscribing happens on a best-effort strategy. Any errors on any connections are suppressed.
30 * @param listener A listener. Need to be a strong reference.
31 * @param topic The topic. Can contain wildcards.
33 void subscribe(MQTTTopicDiscoveryParticipant listener, String topic);
36 * Unsubscribe the given listener.
38 * @param listener A listener that has subscribed before.
40 void unsubscribe(MQTTTopicDiscoveryParticipant listener);
43 * Publish a message to all connected brokers
45 * @param topic The topic
46 * @param payload The message payload
47 * @param qos The quality of service for this message
48 * @param retain Set to true to retain the message on the broker
50 void publish(String topic, byte[] payload, int qos, boolean retain);