fhmq / hmq

High performance mqtt broker
Apache License 2.0
1.33k stars 277 forks source link

Isolate separate brokers and prevent sharing messages between them #172

Closed elh closed 1 year ago

elh commented 2 years ago

Issue

Separately initialized brokers that use the same topics will share messages between them. The underlying topic and session management is not isolated on construction of new brokers.

I noticed this when building a service that runs multiple brokers with the same topic name but different ports. My (reasonable?) expectation was that these separate brokers would be isolated.

See repro of this issue in this gist. (I just wasn't sure how Github would handle a large text dump in a PR comment. Can add later if people prefer.)

Proposal

instantiate new TopicProvider and SessionsProvider on topics.NewManager() and sessions.NewManager() call

elh commented 1 year ago

Closing old PR. Perhaps this is hard to integrate back to source because it would be a breaking change to public interfaces. I do feel like having isolation across brokers is a reasonable expectation though.

For context, our use case is that we have a system that uses a single HMQ broker. In another use case, we virtualize that system as a cloud service with multiple instances running in the same process. In that use case, we need their individual HMQ brokers to be isolated from each other.