Skip to content

Feature request: publish to topic excluding specific client(s) #469

@jtalbourdet

Description

@jtalbourdet

Hi,

I'm currently using Mochi MQTT as an embedded broker and writing a custom hook to handle bulk messages.

In this hook, I intercept messages sent to the topic bulk and split them into separate messages, publishing them to sensor/... topics. Everything works fine, except for one missing feature: I would like to publish to a topic while excluding the client who sent the original message.

Here’s what I'm trying to do:

  1. Client A publishes to bulk with a JSON payload (e.g. { "temp": 22, "hum": 60 })
  2. My hook publishes:
    • sensor/temp22
    • sensor/hum60
  3. But I want to avoid sending those messages back to client A.

So far, I’ve tried:

  • Using srv.Publish(...): works, but always delivers to all subscribers, including the source.
  • Using InjectPacket(...) with a fake client, but it's difficult to construct a valid *mqtt.Client from outside the package (some fields are private, some required interfaces are internal).

Question:

Is there currently a supported way to publish a message to a topic and exclude one or more clients from receiving it?

If not, would you consider adding an API like:

server.PublishExclude(topic string, payload []byte, retain bool, qos byte, excludeIDs []string)

or perhaps allow InjectPacket() to accept a special internal "server" client that bypasses the sender?

Thanks a lot for the great work on this broker — it's lightweight, performant, and very developer-friendly 🙌

Best regards,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions