MQTTnet
MQTTnet copied to clipboard
Ability to set default Client ID for Server
Describe the feature request
The API of injecting messages from the server is not really consistent with itself:
When creating a new InjectedMqttApplicationMessage(MqttApplicationMessage applicationMessage) the ClientID does not have to be set. However, for being able to actually inject this message, SenderClientId must not be null.
In Version 3, when publishing from the Server, the ClientID was always null.
Which project is your feature request related to?
- Server
Describe the solution you'd like
For me, the ideal solution would be to be able to assign a ClientID-like string to the server, that is used by default when injecting messages. This could then be overridden by the SenderClientIdproperty of the InjectedMqtttApplicationMessage.
Describe alternatives you've considered
- Allow publishing messages with
ClientID == null(Behaviour of library V3) - Require a non-null
SenderClientIdwhen creating anInjectedMqttApplicationMessage.
Additional context
Thinking about it, this might actually be a bug, after solving issue #1470
I agree that it is better to enforce a client id for any injected application message. I will not yet change this to avoid breaking changes.
Since version 4 the client id is mandatory due to several new features so there is no way back 😄
If the server had a property (for example ServerID) which would by default be used by default as the Client ID, that would not be a breaking change, or would it?
Not when it comes to compiling but from business logic perspective. I recommend that you create an extension method in your project which always uses the same client ID internally. Another option is to encapsulate the server and provide your own (customized) API.