ModuleClient Class

Definition

Public API for communicating from Edge Modules. A ModuleClient can be used to send messages from an Edge module to an EdgeHub or an IotHub. It can also send twin updates and listen for method calls from an EdgeHub or IotHub as well

public class ModuleClient extends InternalClient
Inheritance
java.lang.Object
ModuleClient

Inherited Members

InternalClient.close() InternalClient.closeNow() InternalClient.getConfig() InternalClient.getProductInfo() InternalClient.isMultiplexed() InternalClient.open() InternalClient.registerConnectionStatusChangeCallback(IotHubConnectionStatusChangeCallback callback, Object callbackContext) InternalClient.sendEventAsync(Message message, IotHubEventCallback callback, Object callbackContext) InternalClient.sendEventBatchAsync(List<Message> messages, IotHubEventCallback callback, Object callbackContext) InternalClient.sendReportedProperties(ReportedPropertiesParameters reportedPropertiesParameters) InternalClient.sendReportedProperties(Set<DeviceTwin.Property> reportedProperties) InternalClient.sendReportedProperties(Set<DeviceTwin.Property> reportedProperties, int version) InternalClient.sendReportedProperties(Set<DeviceTwin.Property> reportedProperties, Integer version, CorrelatingMessageCallback correlatingMessageCallback, Object correlatingMessageCallbackContext, IotHubEventCallback reportedPropertiesCallback, Object reportedPropertiesCallbackContext) InternalClient.setAsMultiplexed() InternalClient.setOperationTimeout(long timeout) InternalClient.setOption(String optionName, Object value) InternalClient.setProxySettings(ProxySettings proxySettings) InternalClient.setRetryPolicy(RetryPolicy retryPolicy) InternalClient.subscribeToDesiredProperties(Map<DeviceTwin.Property,DeviceTwin.Pair<DeviceTwin.PropertyCallBack<String,Object>,Object>> onDesiredPropertyChange) InternalClient.subscribeToTwinDesiredProperties(Map<DeviceTwin.Property,DeviceTwin.Pair<DeviceTwin.TwinPropertyCallBack,Object>> onDesiredPropertyChange) java.lang.Object.clone() java.lang.Object.equals(java.lang.Object) java.lang.Object.finalize() java.lang.Object.getClass() java.lang.Object.hashCode() java.lang.Object.notify() java.lang.Object.notifyAll() java.lang.Object.toString() java.lang.Object.wait() java.lang.Object.wait(long) java.lang.Object.wait(long,int)

Constructors

ModuleClient(String connectionString, IotHubClientProtocol protocol)

Constructor for a ModuleClient instance.

ModuleClient(String connectionString, IotHubClientProtocol protocol, ClientOptions clientOptions)

Constructor for a ModuleClient instance.

ModuleClient(String connectionString, IotHubClientProtocol protocol, String publicKeyCertificate, boolean isCertificatePath, String privateKey, boolean isPrivateKeyPath)

Create a module client instance that uses x509 authentication.

Note! Communication from a module to another EdgeHub using x509 authentication is not currently supported and the service will always return "UNAUTHORIZED"

Communication from a module directly to the IotHub does support x509 authentication, though.

ModuleClient(String connectionString, IotHubClientProtocol protocol, SSLContext sslContext)

Create a module client instance that uses the provided SSLContext for SSL negotiation.

ModuleClient(String hostName, String deviceId, String moduleId, SasTokenProvider sasTokenProvider, IotHubClientProtocol protocol)

Constructor that allows for the client's SAS token generation to be controlled by the user. Note that options in this client such as setting the SAS token expiry time will throw UnsupportedOperationException since the SDK no longer controls that when this constructor is used.

ModuleClient(String hostName, String deviceId, String moduleId, SasTokenProvider sasTokenProvider, IotHubClientProtocol protocol, ClientOptions clientOptions)

Constructor that allows for the client's SAS token generation to be controlled by the user. Note that options in this client such as setting the SAS token expiry time will throw UnsupportedOperationException since the SDK no longer controls that when this constructor is used.

Methods

<Type1,Type2>startTwin(IotHubEventCallback deviceTwinStatusCallback, Object deviceTwinStatusCallbackContext, DeviceTwin.PropertyCallBack<Type1,Type2> genericPropertyCallBack, Object genericPropertyCallBackContext)

Starts the module twin. This module client will receive a callback with the current state of the full twin, including reported properties and desired properties. After that callback is received, this module client will receive a callback each time a desired property is updated. That callback will either contain the full desired properties set, or only the updated desired property depending on how the desired property was changed. IoT Hub supports a PUT and a PATCH on the twin. The PUT will cause this module client to receive the full desired properties set, and the PATCH will cause this module client to only receive the updated desired properties. Similarly, the version of each desired property will be incremented from a PUT call, and only the actually updated desired property will have its version incremented from a PATCH call. The java service client library uses the PATCH call when updated desired properties, but it builds the patch such that all properties are included in the patch. As a result, the device side will receive full twin updates, not partial updates. See PUT and PATCH

createFromEnvironment()

Create a module client instance from your environment variables

createFromEnvironment(IotHubClientProtocol protocol)

Create a module client instance from your environment variables

createFromEnvironment(IotHubClientProtocol protocol, ClientOptions clientOptions)

Create a module client instance from your environment variables

getTwin()

Retrieves the twin's latest desired properties

invokeMethod(String deviceId, MethodRequest methodRequest)

Invoke a method on a device

invokeMethod(String deviceId, String moduleId, MethodRequest methodRequest)

Invoke a method on a module

sendEventAsync(Message message, IotHubEventCallback callback, Object callbackContext)

Asynchronously sends an event message to the IoT Hub.

sendEventAsync(Message message, IotHubEventCallback callback, Object callbackContext, String outputName)

Sends a message to a particular outputName asynchronously

setMessageCallback(MessageCallback callback, Object context)

Sets the message callback.

setMessageCallback(String inputName, MessageCallback callback, Object context)

Sets the message callback to be fired when a telemetry message arrives on the specified input channel. All other messages will trigger the default message callback in setMessageCallback(MessageCallback callback, Object context). Any message that triggers this callback will not also trigger the default callback.

startTwin(IotHubEventCallback deviceTwinStatusCallback, Object deviceTwinStatusCallbackContext, DeviceTwin.TwinPropertiesCallback genericPropertiesCallBack, Object genericPropertyCallBackContext)

Starts the module twin. This module client will receive a callback with the current state of the full twin, including reported properties and desired properties. After that callback is received, this module client will receive a callback each time a desired property is updated. That callback will either contain the full desired properties set, or only the updated desired property depending on how the desired property was changed. IoT Hub supports a PUT and a PATCH on the twin. The PUT will cause this module client to receive the full desired properties set, and the PATCH will cause this module client to only receive the updated desired properties. Similarly, the version of each desired property will be incremented from a PUT call, and only the actually updated desired property will have its version incremented from a PATCH call. The java service client library uses the PATCH call when updated desired properties, but it builds the patch such that all properties are included in the patch. As a result, the device side will receive full twin updates, not partial updates. See PUT and PATCH

startTwin(IotHubEventCallback deviceTwinStatusCallback, Object deviceTwinStatusCallbackContext, DeviceTwin.TwinPropertyCallBack genericPropertyCallBack, Object genericPropertyCallBackContext)

Starts the module twin. This module client will receive a callback with the current state of the full twin, including reported properties and desired properties. After that callback is received, this module client will receive a callback each time a desired property is updated. That callback will either contain the full desired properties set, or only the updated desired property depending on how the desired property was changed. IoT Hub supports a PUT and a PATCH on the twin. The PUT will cause this module client to receive the full desired properties set, and the PATCH will cause this module client to only receive the updated desired properties. Similarly, the version of each desired property will be incremented from a PUT call, and only the actually updated desired property will have its version incremented from a PATCH call. The java service client library uses the PATCH call when updated desired properties, but it builds the patch such that all properties are included in the patch. As a result, the device side will receive full twin updates, not partial updates. See PUT and PATCH

subscribeToMethod(DeviceTwin.DeviceMethodCallback methodCallback, Object methodCallbackContext, IotHubEventCallback methodStatusCallback, Object methodStatusCallbackContext)

Subscribes to method invocations on this module. This does not include method invocations on the device the module belongs to

Applies to