public void RemoveAmqpUnit(AmqpUnit amqpUnit) { if (Logging.IsEnabled) { Logging.Enter(this, amqpUnit, $"{nameof(RemoveAmqpUnit)}"); } DeviceIdentity deviceIdentity = amqpUnit.GetDeviceIdentity(); if (deviceIdentity.IsPooling()) { AmqpConnectionHolder amqpConnectionHolder; lock (_lock) { AmqpConnectionHolder[] amqpConnectionHolders = ResolveConnectionGroup(deviceIdentity); amqpConnectionHolder = ResolveConnectionByHashing(amqpConnectionHolders, deviceIdentity); } amqpConnectionHolder.RemoveAmqpUnit(amqpUnit); } if (Logging.IsEnabled) { Logging.Exit(this, amqpUnit, $"{nameof(RemoveAmqpUnit)}"); } }
public AmqpUnit CreateAmqpUnit( DeviceIdentity deviceIdentity, Func <MethodRequestInternal, Task> methodHandler, Action <Twin, string, TwinCollection> twinMessageListener, Func <string, Message, Task> eventListener, Action onUnitDisconnected) { if (Logging.IsEnabled) { Logging.Enter(this, deviceIdentity, $"{nameof(CreateAmqpUnit)}"); } if (deviceIdentity.IsPooling()) { AmqpConnectionHolder amqpConnectionHolder; lock (_lock) { AmqpConnectionHolder[] amqpConnectionHolders = ResolveConnectionGroup(deviceIdentity); amqpConnectionHolder = ResolveConnectionByHashing(amqpConnectionHolders, deviceIdentity); } if (Logging.IsEnabled) { Logging.Exit(this, deviceIdentity, $"{nameof(CreateAmqpUnit)}"); } return(amqpConnectionHolder.CreateAmqpUnit(deviceIdentity, methodHandler, twinMessageListener, eventListener, onUnitDisconnected)); } else { if (Logging.IsEnabled) { Logging.Exit(this, deviceIdentity, $"{nameof(CreateAmqpUnit)}"); } return(new AmqpConnectionHolder(deviceIdentity).CreateAmqpUnit(deviceIdentity, methodHandler, twinMessageListener, eventListener, onUnitDisconnected)); } }
public AmqpUnit CreateAmqpUnit( DeviceIdentity deviceIdentity, Func <MethodRequestInternal, Task> onMethodCallback, Action <Twin, string, TwinCollection, IotHubException> twinMessageListener, Func <string, Message, Task> onModuleMessageReceivedCallback, Func <Message, Task> onDeviceMessageReceivedCallback, Action onUnitDisconnected) { if (Logging.IsEnabled) { Logging.Enter(this, deviceIdentity, nameof(CreateAmqpUnit)); } if (deviceIdentity.IsPooling()) { AmqpConnectionHolder amqpConnectionHolder; lock (_lock) { AmqpConnectionHolder[] amqpConnectionHolders = ResolveConnectionGroup(deviceIdentity); amqpConnectionHolder = ResolveConnectionByHashing(amqpConnectionHolders, deviceIdentity); } if (Logging.IsEnabled) { Logging.Exit(this, deviceIdentity, nameof(CreateAmqpUnit)); } return(amqpConnectionHolder.CreateAmqpUnit( deviceIdentity, onMethodCallback, twinMessageListener, onModuleMessageReceivedCallback, onDeviceMessageReceivedCallback, onUnitDisconnected)); } else { if (Logging.IsEnabled) { Logging.Exit(this, deviceIdentity, nameof(CreateAmqpUnit)); } return(new AmqpConnectionHolder(deviceIdentity) .CreateAmqpUnit( deviceIdentity, onMethodCallback, twinMessageListener, onModuleMessageReceivedCallback, onDeviceMessageReceivedCallback, onUnitDisconnected)); } }
public AmqpUnit CreateAmqpUnit( DeviceIdentity deviceIdentity, Func <MethodRequestInternal, Task> onMethodCallback, Action <Twin, string, TwinCollection, IotHubException> twinMessageListener, Func <string, Message, Task> onModuleMessageReceivedCallback, Func <Message, Task> onDeviceMessageReceivedCallback, Action onUnitDisconnected) { if (Logging.IsEnabled) { Logging.Enter(this, deviceIdentity, nameof(CreateAmqpUnit)); } if (deviceIdentity.IsPooling()) { AmqpConnectionHolder amqpConnectionHolder; lock (_lock) { AmqpConnectionHolder[] amqpConnectionHolders = ResolveConnectionGroup(deviceIdentity); amqpConnectionHolder = ResolveConnectionByHashing(amqpConnectionHolders, deviceIdentity); // For group sas token authenticated devices over a multiplexed connection, the TokenRefresher // of the first client connecting will be used for generating the group sas tokens // and will be associated with the connection itself. // For this reason, if the device identity of the client is not the one associated with the // connection, the associated TokenRefresher can be safely disposed. // Note - This does not cause any identity related issues since the group sas tokens are generated // against the hub host as the intended audience (without the "device Id"). if (deviceIdentity.AuthenticationModel == AuthenticationModel.SasGrouped && !ReferenceEquals(amqpConnectionHolder.GetDeviceIdentityOfAuthenticationProvider(), deviceIdentity) && deviceIdentity.IotHubConnectionString?.TokenRefresher != null && deviceIdentity.IotHubConnectionString.TokenRefresher.DisposalWithClient) { deviceIdentity.IotHubConnectionString.TokenRefresher.Dispose(); } } if (Logging.IsEnabled) { Logging.Exit(this, deviceIdentity, nameof(CreateAmqpUnit)); } return(amqpConnectionHolder.CreateAmqpUnit( deviceIdentity, onMethodCallback, twinMessageListener, onModuleMessageReceivedCallback, onDeviceMessageReceivedCallback, onUnitDisconnected)); } else { if (Logging.IsEnabled) { Logging.Exit(this, deviceIdentity, nameof(CreateAmqpUnit)); } return(new AmqpConnectionHolder(deviceIdentity) .CreateAmqpUnit( deviceIdentity, onMethodCallback, twinMessageListener, onModuleMessageReceivedCallback, onDeviceMessageReceivedCallback, onUnitDisconnected)); } }