ModuleClient Class
Definition
- java.lang.Object
- InternalClient
- com.microsoft.azure.sdk.iot.device.ModuleClient
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
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. Deprecated. For x509 authentication, use ModuleClient(String connectionString, IotHubClientProtocol protocol, ClientOptions clientOptions) and provide an SSLContext instance in the ClientOptions instance. For a sample on how to build this SSLContext, see this code which references a helper class for building SSLContext objects for x509 authentication as well as for SAS based authentication. When not using this deprecated constructor, you can safely exclude the Bouncycastle dependencies that this library declares. See this pom.xml for an example of how to do this. |
| ModuleClient(String connectionString, IotHubClientProtocol protocol, SSLContext sslContext) |
Create a module client instance that uses the provided SSLContext for SSL negotiation. Deprecated. For x509 authentication, use ModuleClient(String connectionString, IotHubClientProtocol protocol, ClientOptions clientOptions) and provide an SSLContext instance in the ClientOptions instance. For a sample on how to build this SSLContext, see this code which references a helper class for building SSLContext objects for x509 authentication as well as for SAS based authentication. When not using this deprecated constructor, you can safely exclude the Bouncycastle dependencies that this library declares. See this pom.xml for an example of how to do this. |
| 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 |