DirectMethodsClient Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.service.methods.DirectMethodsClient

public class DirectMethodsClient

The client to directly invoke direct methods on devices and modules in IoT hub.

Constructor Summary

Constructor Description
DirectMethodsClient(String connectionString)

Create a DirectMethodsClient instance from the information in the connection string.

DirectMethodsClient(String hostName, AzureSasCredential azureSasCredential)

Create a new DirectMethodsClient instance.

DirectMethodsClient(String hostName, AzureSasCredential azureSasCredential, DirectMethodsClientOptions options)

Create a new DirectMethodsClient instance.

DirectMethodsClient(String connectionString, DirectMethodsClientOptions options)

Create a DirectMethodsClient instance from the information in the connection string.

DirectMethodsClient(String hostName, TokenCredential credential)

Create a new DirectMethodsClient instance.

DirectMethodsClient(String hostName, TokenCredential credential, DirectMethodsClientOptions options)

Create a new DirectMethodsClient instance.

Method Summary

Modifier and Type Method and Description
DirectMethodResponse invoke(String deviceId, String methodName)

Directly invokes a method on the device and return its result.

DirectMethodResponse invoke(String deviceId, String methodName, DirectMethodRequestOptions options)

Directly invokes a method on the device and return its result.

DirectMethodResponse invoke(String deviceId, String moduleId, String methodName)

Directly invokes a method on the module and return its result.

DirectMethodResponse invoke(String deviceId, String moduleId, String methodName, DirectMethodRequestOptions options)

Directly invokes a method on the module and return its result.

Constructor Details

DirectMethodsClient

public DirectMethodsClient(String connectionString)

Create a DirectMethodsClient instance from the information in the connection string.

Parameters:

connectionString - is the IoTHub connection string.

DirectMethodsClient

public DirectMethodsClient(String hostName, AzureSasCredential azureSasCredential)

Create a new DirectMethodsClient instance.

Parameters:

hostName - The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
azureSasCredential - The SAS token provider that will be used for authentication.

DirectMethodsClient

public DirectMethodsClient(String hostName, AzureSasCredential azureSasCredential, DirectMethodsClientOptions options)

Create a new DirectMethodsClient instance.

Parameters:

hostName - The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
azureSasCredential - The SAS token provider that will be used for authentication.
options - The connection options to use when connecting to the service.

DirectMethodsClient

public DirectMethodsClient(String connectionString, DirectMethodsClientOptions options)

Create a DirectMethodsClient instance from the information in the connection string.

Parameters:

connectionString - is the IoTHub connection string.
options - the configurable options for each operation on this client. May not be null.

DirectMethodsClient

public DirectMethodsClient(String hostName, TokenCredential credential)

Create a new DirectMethodsClient instance.

Parameters:

hostName - The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
credential - The custom TokenCredential that will provide authentication tokens to this library when they are needed. The provided tokens must be Json Web Tokens.

DirectMethodsClient

public DirectMethodsClient(String hostName, TokenCredential credential, DirectMethodsClientOptions options)

Create a new DirectMethodsClient instance.

Parameters:

hostName - The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
credential - The custom TokenCredential that will provide authentication tokens to this library when they are needed. The provided tokens must be Json Web Tokens.
options - The connection options to use when connecting to the service.

Method Details

invoke

public DirectMethodResponse invoke(String deviceId, String methodName)

Directly invokes a method on the device and return its result.

Parameters:

deviceId - is the device where the sendHttpRequest is send to.
methodName - is the name of the method that shall be invoked on the device.

Returns:

the status and payload resulted from the method invoke.

Throws:

IotHubException - This exception is thrown if the response verification failed.
IOException - This exception is thrown if the IO operation failed.

invoke

public DirectMethodResponse invoke(String deviceId, String methodName, DirectMethodRequestOptions options)

Directly invokes a method on the device and return its result.

Parameters:

deviceId - is the device where the sendHttpRequest is send to.
methodName - is the name of the method that shall be invoked on the device.
options - the optional parameters for this request, including the method's payload. May not be null.

Returns:

the status and payload resulted from the method invoke.

Throws:

IotHubException - This exception is thrown if the response verification failed.
IOException - This exception is thrown if the IO operation failed.

invoke

public DirectMethodResponse invoke(String deviceId, String moduleId, String methodName)

Directly invokes a method on the module and return its result.

Parameters:

deviceId - is the device where the module is related to.
moduleId - is the module where the sendHttpRequest is sent to.
methodName - is the name of the method that shall be invoked on the device.

Returns:

the status and payload resulted from the method invoke.

Throws:

IotHubException - This exception is thrown if the response verification failed.
IOException - This exception is thrown if the IO operation failed.

invoke

public DirectMethodResponse invoke(String deviceId, String moduleId, String methodName, DirectMethodRequestOptions options)

Directly invokes a method on the module and return its result.

Parameters:

deviceId - is the device where the module is related to.
moduleId - is the module where the sendHttpRequest is sent to.
methodName - is the name of the method that shall be invoked on the device.
options - the optional parameters for this request, including the method's payload. May not be null.

Returns:

the status and payload resulted from the method invoke.

Throws:

IotHubException - This exception is thrown if the response verification failed.
IOException - This exception is thrown if the IO operation failed.

Applies to