ModuleClient Class
- java.
lang. Object - InternalClient
- com.
microsoft. azure. sdk. iot. device. ModuleClient
- 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 ModuleClient instance. or HostName=xxxx;DeviceId=xxxx;SharedAccessKey= xxxx;moduleId=xxxx;HostNameGateway=xxxx |
ModuleClient(String connectionString, IotHubClientProtocol protocol, ClientOptions clientOptions) |
Constructor for a ModuleClient instance. or HostName=xxxx;DeviceId=xxxx;SharedAccessKey= xxxx;moduleId=xxxx;HostNameGateway=xxxx |
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. |
Method Summary
Inherited Members
Constructor Details
ModuleClient
public ModuleClient(String connectionString, IotHubClientProtocol protocol)
Constructor for a ModuleClient instance. or
HostName=xxxx;DeviceId=xxxx;SharedAccessKey= xxxx;moduleId=xxxx;HostNameGateway=xxxx
Parameters:
Throws:
ModuleClient
public ModuleClient(String connectionString, IotHubClientProtocol protocol, ClientOptions clientOptions)
Constructor for a ModuleClient instance. or
HostName=xxxx;DeviceId=xxxx;SharedAccessKey= xxxx;moduleId=xxxx;HostNameGateway=xxxx
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
createFromEnvironment
public static ModuleClient createFromEnvironment(UnixDomainSocketChannel unixDomainSocketChannel)
Create a module client instance from your environment variables
Parameters:
Returns:
Throws:
createFromEnvironment
public static ModuleClient createFromEnvironment(UnixDomainSocketChannel unixDomainSocketChannel, IotHubClientProtocol protocol)
Create a module client instance from your environment variables
Parameters:
Returns:
Throws:
createFromEnvironment
public static ModuleClient createFromEnvironment(UnixDomainSocketChannel unixDomainSocketChannel, IotHubClientProtocol protocol, ClientOptions clientOptions)
Create a module client instance from your environment variables
Parameters:
Returns:
Throws:
invokeMethod
public DirectMethodResponse invokeMethod(String deviceId, DirectMethodRequest directMethodRequest)
Invoke a method on a device
Parameters:
Returns:
Throws:
invokeMethod
public DirectMethodResponse invokeMethod(String deviceId, String moduleId, DirectMethodRequest directMethodRequest)
Invoke a method on a module
Parameters:
Returns:
Throws:
sendEvent
public void sendEvent(Message message)
Parameters:
sendEvent
public void sendEvent(Message message, String outputName)
Synchronously sends a message to to a particular outputName.
Parameters:
Throws:
sendEvent
public void sendEvent(Message message, String outputName, int timeoutMilliseconds)
Synchronously sends a message to to a particular outputName.
Parameters:
Throws:
sendEventAsync
public void sendEventAsync(Message message, MessageSentCallback callback, Object callbackContext)
Parameters:
sendEventAsync
public void sendEventAsync(Message message, MessageSentCallback 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:
the message callback. Can benull
</code> . </p>
context
- the context to be passed to the callback. Can benull
</code> .</p>
Returns:
itself, for fluent setting.
Throws:
IllegalArgumentException
- if the callback isnull
</code> but a context is passed in. </p>
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:
inputName
- the input name channel to listen for.
callback
- the message callback. Can benull
</code> . </p>
context
- the context to be passed to the callback. Can benull
</code> .</p>
Returns:
this object, for fluent setting
Applies to
Azure SDK for Java