你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

ServiceClient Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.service.ServiceClient

public class ServiceClient

Extend the ServiceClient class and provide AMPQ specific implementation.

Constructor Summary

Modifier Constructor Description
protected ServiceClient(IotHubConnectionString iotHubConnectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol)

Initialize AMQP sender using given connection string

protected ServiceClient(IotHubConnectionString iotHubConnectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options)

Initialize AMQP sender using given connection string

ServiceClient(String hostName, AzureSasCredential azureSasCredential, IotHubServiceClientProtocol iotHubServiceClientProtocol)

Create a ServiceClient instance with an instance of AzureSasCredential.

ServiceClient(String hostName, AzureSasCredential azureSasCredential, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options)

Create a ServiceClient instance with an instance of AzureSasCredential.

ServiceClient(String hostName, TokenCredential credential, IotHubServiceClientProtocol iotHubServiceClientProtocol)

Create a ServiceClient instance with a custom TokenCredential to allow for finer grain control of authentication tokens used in the underlying connection.

ServiceClient(String hostName, TokenCredential credential, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options)

Create a ServiceClient instance with a custom TokenCredential to allow for finer grain control of authentication tokens used in the underlying connection.

ServiceClient(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol)

Create ServiceClient from the specified connection string

ServiceClient(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options)

Create ServiceClient from the specified connection string

Method Summary

Modifier and Type Method and Description
void close()

Close AMQP sender

java.util.concurrent.CompletableFuture<java.lang.Void> closeAsync()

Provide asynchronous access to close()

static ServiceClient createFromConnectionString(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol)

Deprecated

because this method declares a thrown IOException even though it never throws an IOException. Users are recommended to use ServiceClient(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol) instead since it does not declare this exception even though it constructs the same ServiceClient.

Create ServiceClient from the specified connection string

static ServiceClient createFromConnectionString(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options)

Deprecated

because this method declares a thrown IOException even though it never throws an IOException. Users are recommended to use ServiceClient(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options) instead since it does not declare this exception even though it constructs the same ServiceClient.

Create ServiceClient from the specified connection string

FeedbackReceiver getFeedbackReceiver()

Instantiate a new FeedbackReceiver object.

FeedbackReceiver getFeedbackReceiver(String deviceId)

Deprecated

As of release 1.1.15, replaced by getFeedbackReceiver()

Get FeedbackReceiver object.This API has been deprecated.

FileUploadNotificationReceiver getFileUploadNotificationReceiver()

Instantiate a new FileUploadNotificationReceiver object.

void open()

Open AMQP sender

java.util.concurrent.CompletableFuture<java.lang.Void> openAsync()

Provide asynchronous access to open()

void send(String deviceId, Message message)

Send a one-way message to the specified device.

void send(String deviceId, String moduleId, Message message)

Send a one-way message to the specified module.

java.util.concurrent.CompletableFuture<java.lang.Void> sendAsync(String deviceId, Message message)

Provide asynchronous access to send()

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals 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 java.lang.Object.wait

Constructor Details

ServiceClient

protected ServiceClient(IotHubConnectionString iotHubConnectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol)

Initialize AMQP sender using given connection string

Parameters:

iotHubConnectionString - The ConnectionString object for the IotHub
iotHubServiceClientProtocol - protocol to use

ServiceClient

protected ServiceClient(IotHubConnectionString iotHubConnectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options)

Initialize AMQP sender using given connection string

Parameters:

iotHubConnectionString - The ConnectionString object for the IotHub
iotHubServiceClientProtocol - protocol to use
options - options for proxy

ServiceClient

public ServiceClient(String hostName, AzureSasCredential azureSasCredential, IotHubServiceClientProtocol iotHubServiceClientProtocol)

Create a ServiceClient instance with an instance of AzureSasCredential.

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.
iotHubServiceClientProtocol - The protocol to open the connection with.

ServiceClient

public ServiceClient(String hostName, AzureSasCredential azureSasCredential, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options)

Create a ServiceClient instance with an instance of AzureSasCredential.

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.
iotHubServiceClientProtocol - The protocol to open the connection with.
options - The connection options to use when connecting to the service.

ServiceClient

public ServiceClient(String hostName, TokenCredential credential, IotHubServiceClientProtocol iotHubServiceClientProtocol)

Create a ServiceClient instance with a custom TokenCredential to allow for finer grain control of authentication tokens used in the underlying connection.

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.
iotHubServiceClientProtocol - The protocol to open the connection with.

ServiceClient

public ServiceClient(String hostName, TokenCredential credential, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options)

Create a ServiceClient instance with a custom TokenCredential to allow for finer grain control of authentication tokens used in the underlying connection.

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.
iotHubServiceClientProtocol - The protocol to open the connection with.
options - The connection options to use when connecting to the service.

ServiceClient

public ServiceClient(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol)

Create ServiceClient from the specified connection string

Parameters:

connectionString - The connection string for the IotHub
iotHubServiceClientProtocol - protocol to use

ServiceClient

public ServiceClient(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options)

Create ServiceClient from the specified connection string

Parameters:

connectionString - The connection string for the IotHub
iotHubServiceClientProtocol - protocol to use
options - The connection options to use when connecting to the service.

Method Details

close

public void close()

Close AMQP sender

Throws:

java.io.IOException - This exception is thrown if the AmqpSender object is not initialized

closeAsync

public CompletableFuture closeAsync()

Provide asynchronous access to close()

Returns:

The future object for the requested operation

createFromConnectionString


public static ServiceClient createFromConnectionString(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol)

Deprecated

because this method declares a thrown IOException even though it never throws an IOException. Users are recommended to use ServiceClient(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol) instead since it does not declare this exception even though it constructs the same ServiceClient.

Create ServiceClient from the specified connection string

Parameters:

connectionString - The connection string for the IotHub
iotHubServiceClientProtocol - protocol to use

Returns:

The created ServiceClient object

Throws:

java.io.IOException - This exception is thrown if the object creation failed

createFromConnectionString


public static ServiceClient createFromConnectionString(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options)

Deprecated

because this method declares a thrown IOException even though it never throws an IOException. Users are recommended to use ServiceClient(String connectionString, IotHubServiceClientProtocol iotHubServiceClientProtocol, ServiceClientOptions options) instead since it does not declare this exception even though it constructs the same ServiceClient.

Create ServiceClient from the specified connection string

Parameters:

connectionString - The connection string for the IotHub
iotHubServiceClientProtocol - protocol to use
options - The connection options to use when connecting to the service.

Returns:

The created ServiceClient object

Throws:

java.io.IOException - This exception is thrown if the object creation failed

getFeedbackReceiver

public FeedbackReceiver getFeedbackReceiver()

Instantiate a new FeedbackReceiver object.

Returns:

The instance of the FeedbackReceiver

getFeedbackReceiver


public FeedbackReceiver getFeedbackReceiver(String deviceId)

Deprecated

As of release 1.1.15, replaced by getFeedbackReceiver()

Get FeedbackReceiver object.This API has been deprecated. Use new API without deviceId as an input parameter.

Parameters:

deviceId - The device identifier for the target device

Returns:

The instance of the FeedbackReceiver

getFileUploadNotificationReceiver

public FileUploadNotificationReceiver getFileUploadNotificationReceiver()

Instantiate a new FileUploadNotificationReceiver object.

Returns:

The instance of the FileUploadNotificationReceiver

open

public void open()

Open AMQP sender

Throws:

java.io.IOException - This exception is thrown if the AmqpSender object is not initialized

openAsync

public CompletableFuture openAsync()

Provide asynchronous access to open()

Returns:

The future object for the requested operation

send

public void send(String deviceId, Message message)

Send a one-way message to the specified device. This function is synchronized internally so that only one send operation is allowed at a time. In order to do more send operations at a time, you will need to instantiate another service client instance.

Parameters:

deviceId - The device identifier for the target device
message - The message for the device

Throws:

java.io.IOException - This exception is thrown if the AmqpSender object is not initialized
IotHubException - This exception is thrown if the AmqpSender object is not initialized

send

public void send(String deviceId, String moduleId, Message message)

Send a one-way message to the specified module. This function is synchronized internally so that only one send operation is allowed at a time. In order to do more send operations at a time, you will need to instantiate another service client instance.

Parameters:

deviceId - The device identifier for the target device
moduleId - The module identifier for the target device
message - The message for the device

Throws:

java.io.IOException - This exception is thrown if the AmqpSender object is not initialized
IotHubException - This exception is thrown if the AmqpSender object is not initialized

sendAsync

public CompletableFuture sendAsync(String deviceId, Message message)

Provide asynchronous access to send()

Parameters:

deviceId - The device identifier for the target device
message - The message for the device

Returns:

The future object for the requested operation

Applies to