MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

Ability to set default Client ID for Server

Open Jeanot-Zubler opened this issue 3 years ago • 2 comments

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

  1. Allow publishing messages with ClientID == null (Behaviour of library V3)
  2. Require a non-null SenderClientId when creating an InjectedMqttApplicationMessage.

Additional context

Thinking about it, this might actually be a bug, after solving issue #1470

Jeanot-Zubler avatar Aug 09 '22 11:08 Jeanot-Zubler

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 😄

chkr1011 avatar Aug 13 '22 11:08 chkr1011

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?

Jeanot-Zubler avatar Sep 02 '22 13:09 Jeanot-Zubler

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.

chkr1011 avatar Sep 24 '22 07:09 chkr1011