in iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/AmqpsIotHubConnection.java [725:778]
public void onAuthenticationSessionOpened()
{
log.trace("Authentication session opened, counting down the authentication session opening latch");
this.authenticationSessionOpenedLatch.countDown();
if (this.authenticationType == ClientConfiguration.AuthType.SAS_TOKEN)
{
if (this.isWebsocketConnection)
{
// AMQPS_WS has an issue where the remote host kills the connection if 31+ multiplexed devices are all
// authenticated at once. To work around this, the authentications will be done at most 30 at a time.
// Once a given device's authentication finishes, it will trigger the next authentication
List<AmqpsSasTokenRenewalHandler> handlers = new ArrayList<>(sasTokenRenewalHandlers);
int maxInFlightAuthenticationMessages = 30;
for (int i = 0; i < handlers.size() - maxInFlightAuthenticationMessages; i++)
{
if (i + maxInFlightAuthenticationMessages < handlers.size())
{
handlers.get(i).setNextToAuthenticate(handlers.get(i + maxInFlightAuthenticationMessages));
}
}
int min = Math.min(maxInFlightAuthenticationMessages, handlers.size());
for (int i = 0; i < min; i++)
{
try
{
// Sending the first authentication message will eventually trigger sending the second, which will trigger the third, and so on.
handlers.get(i).sendAuthenticationMessage(this.connection.getReactor());
}
catch (TransportException e)
{
log.error("Failed to send CBS authentication message", e);
this.savedException = e;
}
}
}
else
{
for (AmqpsSasTokenRenewalHandler amqpsSasTokenRenewalHandler : sasTokenRenewalHandlers)
{
try
{
amqpsSasTokenRenewalHandler.sendAuthenticationMessage(this.connection.getReactor());
}
catch (TransportException e)
{
log.error("Failed to send CBS authentication message", e);
this.savedException = e;
}
}
}
}
}