Skip to content

Commit

Permalink
Update brokerHostName before MqttClientOptionsBuilder uses it's value
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsuciu committed Oct 31, 2024
1 parent 3672ebe commit 4e8575e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Libraries/Opc.Ua.PubSub/Transport/MqttPubSubConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,17 @@ private MqttClientOptions GetMqttClientOptions()
return null;
}

// Setup data needed also in mqttClientOptionsBuilder
if ((connectionUri.Scheme == Utils.UriSchemeMqtt) || (connectionUri.Scheme == Utils.UriSchemeMqtts))
{
if (!String.IsNullOrEmpty(connectionUri.Host))
{
m_brokerHostName = connectionUri.Host;
m_brokerPort = (connectionUri.Port > 0) ? connectionUri.Port : ((connectionUri.Scheme == Utils.UriSchemeMqtt) ? 1883 : 8883);
m_urlScheme = connectionUri.Scheme;
}
}

ITransportProtocolConfiguration transportProtocolConfiguration =
new MqttClientProtocolConfiguration(PubSubConnectionConfiguration.ConnectionProperties);

Expand All @@ -728,6 +739,7 @@ private MqttClientOptions GetMqttClientOptions()
.ProtocolVersion;
// create uniques client id
string clientId = $"ClientId_{new Random().Next():D10}";

// MQTTS mqttConnection.
if (connectionUri.Scheme == Utils.UriSchemeMqtts)
{
Expand Down Expand Up @@ -794,6 +806,8 @@ private MqttClientOptions GetMqttClientOptions()
// Set user credentials.
if (mqttProtocolConfiguration.UseCredentials)
{
// Following Password usage in both cases is correct since it is the Password position
// to be taken into account for the UserName to be read properly
mqttClientOptionsBuilder.WithCredentials(
new System.Net.NetworkCredential(string.Empty, mqttProtocolConfiguration.UserName)
.Password,
Expand Down

0 comments on commit 4e8575e

Please sign in to comment.