github mochi-mqtt/server v1.0.3

latest releases: v2.6.3, v2.6.2, v2.6.1...
2 years ago

Adds a new AllowClients field to the packet structure.

This field can be set during the OnMessage event hook, allowing an embedding server to selectively deliver messages to one or more clients within one or more topics based on their client id. For example:

// Add OnMessage Event Hook
server.Events.OnMessage = func(cl events.Client, pk events.Packet) (pkx events.Packet, err error) {
  pkx = pk
    
  // Example of using AllowClients to selectively deliver/drop messages.
  // Only a client with the id of `allowed-client` will received messages on the topic.
  if pkx.TopicName == "a/b/restricted" {
    pkx.AllowClients = []string{"allowed-client"} // slice of known client ids
  }

  return pkx, nil
}

If AllowClients is nil or not set, it is ignored and the message is delivered as normal.

All unit tests passing, paho compatibility tests passing

Includes small fixes for code clarity and test integrity:

  • Use .systemInfo instead of .system for clarity in internal/clients
  • Add setupServerClients to inherit existing server instance in server_test.go (previously new clients generated a new server object, so system stats were not shared - this change ensures all test clients use the same server).

What's Changed

Full Changelog: v1.0.2...v1.0.3

Don't miss a new server release

NewReleases is sending notifications on new releases.