MultiplexingClient 类

定义

A client for creating multiplexed connections to IoT Hub. A multiplexed connection allows for multiple device clients to communicate to the service through a single AMQPS connection.

A given AMQPS connection requires a TLS connection, so multiplexing may be worthwhile if you want to limit the number of TLS connections needed to connect multiple device clients to IoT Hub.

A given multiplexing client also has a fixed amount of worker threads regardless of how many device clients are being multiplexed. Comparatively, every non-multiplexed device client instance has its own set of worker threads. Multiplexing may be worthwhile if you want fewer worker threads.

Only AMQPS and AMQPS_WS support multiplexing, and only symmetric key authenticated devices can be multiplexed.

ModuleClient instances cannot be multiplexed.

public class MultiplexingClient
继承
java.lang.Object
MultiplexingClient

构造函数

MultiplexingClient(String hostName, IotHubClientProtocol protocol)

Instantiate a new MultiplexingClient that will establish a multiplexed connection through a proxy.

MultiplexingClient(String hostName, IotHubClientProtocol protocol, MultiplexingClientOptions options)

Instantiate a new MultiplexingClient that will establish a multiplexed connection through a proxy.

字段

DEFAULT_RECEIVE_PERIOD_MILLIS
DEFAULT_SEND_PERIOD_MILLIS
MAX_MULTIPLEX_DEVICE_COUNT_AMQPS

The maximum number of devices that can be multiplexed together on a single multiplexed AMQPS connection

MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS

The maximum number of devices that can be multiplexed together on a single multiplexed AMQPS_WS connection

方法

close()

Close this multiplexing client. This will close all active device sessions as well as the AMQP connection.

If this client is already closed, then this method will do nothing.

Once closed, this client can be re-opened. It will preserve all previously registered device clients.

getRegisteredDeviceCount()

Get the number of currently registered devices on this multiplexing client.

isDeviceRegistered(String deviceId)

Returns if a device client for the provided device Id is already registered to this multiplexing client.

open()

Opens this multiplexing client. This may be done before or after registering any number of device clients.

This call behaves synchronously, so if it returns without throwing, then all registered device clients were successfully opened.

If this client is already open, then this method will do nothing.

registerConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext)

Registers a callback to be executed when the connection status of the multiplexed connection as a whole changes. The callback will be fired with a status and a reason why the multiplexed connection's status changed. When the callback is fired, the provided context will be provided alongside the status and reason.

Note that this callback will not be fired for device specific connection status changes. In order to be notified when a particular device's connection status changes, you will need to register a connection status change callback on that device client instance using registerConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext).

Note that the thread used to deliver this callback should not be used to call open()/closeNow() on the client that this callback belongs to. All open()/closeNow() operations should be done on a separate thread

registerDeviceClient(DeviceClient deviceClient)

Register a device client to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use registerDeviceClients(Iterable) for registering multiple devices as it has some performance improvements over repeatedly calling this method for individual device registrations. This method blocks on each registration, whereas registerDeviceClients(Iterable) blocks on all of the registrations after starting them all asynchronously.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

If the multiplexing client is already open, then this device client will automatically be opened, too. If the multiplexing client is not open yet, then this device client will not be opened until open() is called.

If the multiplexed connection is already open, then this call will add this device client to the multiplexed connection, and then will block until the registration has been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device client must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device client must use symmetric key based authentication.

The registered device client must belong to the same IoT Hub as all previously registered device clients.

If the provided device client is already registered to this multiplexing client, then then this method will do nothing.

Any subscriptions (twin, methods, cloud to device messages) set on this device client from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

registerDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds)

Register a device client to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use registerDeviceClients(Iterable) for registering multiple devices as it has some performance improvements over repeatedly calling this method for individual device registrations. This method blocks on each registration, whereas registerDeviceClients(Iterable) blocks on all of the registrations after starting them all asynchronously.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

If the multiplexing client is already open, then this device client will automatically be opened, too. If the multiplexing client is not open yet, then this device client will not be opened until open() is called.

If the multiplexed connection is already open, then this call will add this device client to the multiplexed connection, and then will block until the registration has been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device client must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device client must use symmetric key based authentication.

The registered device client must belong to the same IoT Hub as all previously registered device clients.

If the provided device client is already registered to this multiplexing client, then then this method will do nothing.

Any subscriptions (twin, methods, cloud to device messages) set on this device client from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

registerDeviceClients(Iterable<DeviceClient> deviceClients)

Register multiple device clients to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

If the multiplexing client is already open, then these device clients will automatically be opened, too. If the multiplexing client is not open yet, then these device clients will not be opened until open() is called.

If the multiplexed connection is already open, then this call will asynchronously add each device client to the multiplexed connection, and then will block until all registrations have been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device clients must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device clients must use symmetric key based authentication.

The registered device clients must belong to the same IoT Hub as all previously registered device clients.

If any of these device clients are already registered to this multiplexing client, then then this method will not do anything to that particular device client. All other provided device clients will still be registered though.

Any subscriptions (twin, methods, cloud to device messages) set on these device clients from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

registerDeviceClients(Iterable<DeviceClient> deviceClients, long timeoutMilliseconds)

Register multiple device clients to this multiplexing client. This method may be called before or after opening the multiplexed connection.

Up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS devices can be registered on a multiplexed AMQPS connection, and up to MAX_MULTIPLEX_DEVICE_COUNT_AMQPS_WS devices can be registered on a multiplexed AMQPS_WS connection.

A device client can be unregistered using unregisterDeviceClient(DeviceClient deviceClient), unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds), unregisterDeviceClients(Iterable), or unregisterDeviceClients(Iterable, long). A device client will not be unregistered automatically if it encounters a non-retryable exception, so users are responsible for unregistering a device client when they no longer want it in this multiplexing client.

If the multiplexing client is already open, then these device clients will automatically be opened, too. If the multiplexing client is not open yet, then these device clients will not be opened until open() is called.

If the multiplexed connection is already open, then this call will asynchronously add each device client to the multiplexed connection, and then will block until all registrations have been completed.

Any proxy settings set to the provided device clients will be overwritten by the proxy settings of this multiplexing client.

The registered device clients must use the same transport protocol (AMQPS or AMQPS_WS) that this multiplexing client uses.

Each registered device client may have its own retry policy and its own SAS token expiry time, separate from every other registered device client.

The registered device clients must use symmetric key based authentication.

The registered device clients must belong to the same IoT Hub as all previously registered device clients.

If any of these device clients are already registered to this multiplexing client, then then this method will not do anything to that particular device client. All other provided device clients will still be registered though.

Any subscriptions (twin, methods, cloud to device messages) set on these device clients from when it was previously registered to any multiplexing client will need to be set again as subscriptions and their callbacks are not preserved.

setRetryPolicy(RetryPolicy retryPolicy)

Sets the given retry policy for the multiplexing client level connection management. See more details about the default retry policy and about using custom retry policies here

unregisterDeviceClient(DeviceClient deviceClient)

Unregister a device client from this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use unregisterDeviceClients(Iterable) for unregistering multiple devices as it has some performance improvements over repeatedly calling this method for individual device unregistrations. This method blocks on each unregistration, whereas registerDeviceClients(Iterable) blocks on all of the unregistrations after starting them all asynchronously.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device client, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios or used by the deprecated TransportClient.

Any subscriptions set on this device client for twin/methods/cloud to device messages will need to be set again after this device is re-registered.

unregisterDeviceClient(DeviceClient deviceClient, long timeoutMilliseconds)

Unregister a device client from this multiplexing client. This method may be called before or after opening the multiplexed connection.

Users should use unregisterDeviceClients(Iterable) for unregistering multiple devices as it has some performance improvements over repeatedly calling this method for individual device unregistrations. This method blocks on each unregistration, whereas registerDeviceClients(Iterable) blocks on all of the unregistrations after starting them all asynchronously.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device client, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios or used by the deprecated TransportClient.

Any subscriptions set on this device client for twin/methods/cloud to device messages will need to be set again after this device is re-registered.

unregisterDeviceClients(Iterable<DeviceClient> deviceClients)

Unregister multiple device clients from this multiplexing client. This method may be called before or after opening the multiplexed connection.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device clients, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios or used by the deprecated TransportClient.

Any subscriptions set on these device clients for twin/methods/cloud to device messages will need to be set again after these devices are re-registered.

unregisterDeviceClients(Iterable<DeviceClient> deviceClients, long timeoutMilliseconds)

Unregister multiple device clients from this multiplexing client. This method may be called before or after opening the multiplexed connection.

If the multiplexed connection is already open, then this call will close the AMQP device session associated with this device, but it will not close any other registered device sessions or the multiplexing client itself.

If the multiplexed connection is already open, and this call would unregister the last device clients, the multiplexed connection will remain open. The multiplexed connection can only be closed by calling close()

Once a device client is unregistered, it may be re-registered to this or any other multiplexing client. It cannot be used in non-multiplexing scenarios or used by the deprecated TransportClient.

Any subscriptions set on these device clients for twin/methods/cloud to device messages will need to be set again after these devices are re-registered.

适用于