ModuleClient Class
- java.
lang. Object - com.
microsoft. azure. sdk. iot. device. InternalClient - com.
microsoft. azure. sdk. iot. device. ModuleClient
- com.
- com.
public class ModuleClient
extends InternalClient
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
Constructor Summary
Constructor | Description |
---|---|
ModuleClient(String connectionString, IotHubClientProtocol protocol) |
Constructor for a Module |
ModuleClient(String connectionString, IotHubClientProtocol protocol, ClientOptions clientOptions) |
Constructor for a Module |
ModuleClient(String connectionString, IotHubClientProtocol protocol, String publicKeyCertificate, boolean isCertificatePath, String privateKey, boolean isPrivateKeyPath) |
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.
Create a module client instance that uses x509 authentication. |
ModuleClient(String connectionString, IotHubClientProtocol protocol, SSLContext sslContext) |
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.
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. |
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. |
Method Summary
Methods inherited from InternalClient
Methods inherited from java.lang.Object
Constructor Details
ModuleClient
public ModuleClient(String connectionString, IotHubClientProtocol protocol)
Constructor for a ModuleClient instance.
Parameters:
or
HostName=xxxx;DeviceId=xxxx;SharedAccessKey=
xxxx;moduleId=xxxx;HostNameGateway=xxxx
Throws:
ModuleClient
public ModuleClient(String connectionString, IotHubClientProtocol protocol, ClientOptions clientOptions)
Constructor for a ModuleClient instance.
Parameters:
or
HostName=xxxx;DeviceId=xxxx;SharedAccessKey=
xxxx;moduleId=xxxx;HostNameGateway=xxxx
Throws:
ModuleClient
public ModuleClient(String connectionString, IotHubClientProtocol protocol, String publicKeyCertificate, boolean isCertificatePath, String privateKey, boolean isPrivateKeyPath)
Deprecated
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.
Parameters:
or
HostName=xxxx;DeviceId=xxxx;SharedAccessKey=
xxxx;moduleId=xxxx;HostNameGateway=xxxx
Throws:
ModuleClient
public ModuleClient(String connectionString, IotHubClientProtocol protocol, SSLContext sslContext)
Deprecated
Create a module client instance that uses the provided SSLContext for SSL negotiation.
Parameters:
Throws:
ModuleClient
public 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.
Parameters:
ModuleClient
public 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.
Parameters:
Method Details
<Type1,Type2>startTwin
public void
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
Parameters:
null
.
null
.
null
.
null
.
Throws:
null
null
null
createFromEnvironment
public static ModuleClient createFromEnvironment()
Create a module client instance from your environment variables
Returns:
Throws:
createFromEnvironment
public static ModuleClient createFromEnvironment(IotHubClientProtocol protocol)
Create a module client instance from your environment variables
Parameters:
Returns:
Throws:
createFromEnvironment
public static ModuleClient createFromEnvironment(IotHubClientProtocol protocol, ClientOptions clientOptions)
Create a module client instance from your environment variables
Parameters:
Returns:
Throws:
getTwin
public void getTwin()
Retrieves the twin's latest desired properties
Throws:
invokeMethod
public MethodResult invokeMethod(String deviceId, MethodRequest methodRequest)
Invoke a method on a device
Parameters:
Returns:
Throws:
invokeMethod
public MethodResult invokeMethod(String deviceId, String moduleId, MethodRequest methodRequest)
Invoke a method on a module
Parameters:
Returns:
Throws:
sendEventAsync
public void sendEventAsync(Message message, IotHubEventCallback callback, Object callbackContext)
Asynchronously sends an event message to the IoT Hub.
Overrides:
ModuleClient.sendEventAsync(Message message, IotHubEventCallback callback, Object callbackContext)Parameters:
Throws:
sendEventAsync
public void sendEventAsync(Message message, IotHubEventCallback callback, Object callbackContext, String outputName)
Sends a message to a particular outputName asynchronously
Parameters:
Throws:
setMessageCallback
public ModuleClient setMessageCallback(MessageCallback callback, Object context)
Sets the message callback.
Parameters:
null
.
null
.
Returns:
setMessageCallback
public ModuleClient 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.
Parameters:
null
.
null
.
Returns:
startTwin
public void 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
Parameters:
null
.
null
.
null
.
null
.
Throws:
null
null
null
startTwin
public void 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
Parameters:
null
.
null
.
null
.
null
. *
Throws:
null
null
null
subscribeToMethod
public void 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
Parameters:
null
.
null
.
null
.
null
.
Throws:
Applies to
Azure SDK for Java