DeviceClient 构造函数

定义

重载

DeviceClient()
DeviceClient(String connString, IotHubClientProtocol protocol)

Constructor that takes a connection string as an argument.

DeviceClient(String connString, IotHubClientProtocol protocol, ClientOptions clientOptions)

Constructor that takes a connection string as an argument.

DeviceClient(String connString, IotHubClientProtocol protocol, SSLContext sslContext)

Creates a device client that uses the provided SSLContext for SSL negotiation

DeviceClient(String connString, IotHubClientProtocol protocol, String publicKeyCertificate, boolean isCertificatePath, String privateKey, boolean isPrivateKeyPath)

Constructor that uses x509 authentication for communicating with IotHub

<xreftitle>Deprecated</xreftitle>

<xrefdescription>

  <p>For x509 authentication, use <xref uid="com.microsoft.azure.sdk.iot.device.DeviceClient.DeviceClient(String,IotHubClientProtocol,ClientOptions)" data-throw-if-not-resolved="false" data-raw-source="DeviceClient(String, IotHubClientProtocol, ClientOptions)"></xref> and provide an SSLContext instance in the <xref uid="com.microsoft.azure.sdk.iot.device.ClientOptions" data-throw-if-not-resolved="false" data-raw-source="ClientOptions"></xref> instance. For a sample on how to build this SSLContext, see <a href="https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-samples/send-event-x509/src/main/java/samples/com/microsoft/azure/sdk/iot/SendEventX509.java">this code</a> 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 <a href="https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-samples/send-event-x509/pom.xml">this pom.xml</a> for an example of how to do this. </p>

</xrefdescription>

DeviceClient(String connString, TransportClient transportClient)

Constructor that takes a connection string and a transport client as an argument.

<xreftitle>Deprecated</xreftitle>

<xrefdescription>

  <p>

    <xref uid="com.microsoft.azure.sdk.iot.device.MultiplexingClient" data-throw-if-not-resolved="false" data-raw-source="MultiplexingClient"></xref> should be used instead of <xref uid="com.microsoft.azure.sdk.iot.device.TransportClient" data-throw-if-not-resolved="false" data-raw-source="TransportClient"></xref> for creating all multiplexed connections. </p>

</xrefdescription>

DeviceClient(String hostName, String deviceId, 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.

DeviceClient(String hostName, String deviceId, 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.

DeviceClient()

protected DeviceClient()

DeviceClient(String connString, IotHubClientProtocol protocol)

Constructor that takes a connection string as an argument.

public DeviceClient(String connString, IotHubClientProtocol protocol)

参数

connString
String

the connection string. The connection string is a set of key-value pairs that are separated by ';', with the keys and values separated by '='. It should contain values for the following keys: HostName 

</code> ,<code>DeviceId 

</code> , and<code>SharedAccessKey 

</code> . </p>
protocol
IotHubClientProtocol

the communication protocol used (i.e. HTTPS).

例外

IllegalArgumentException

if any ofconnString 

</code> or <code>protocol 

</code> are<code>null 

</code> ; or if<code>connString 

</code> is missing one of the following attributes:<code>HostName 

</code> ,<code>DeviceId 

</code> , or <code>SharedAccessKey 

</code> or if the IoT hub hostname does not conform to RFC 3986 or if the provided<code>connString 

</code> is for an x509 authenticated device </p>
URISyntaxException

if the hostname in the connection string is not a valid URI

DeviceClient(String connString, IotHubClientProtocol protocol, ClientOptions clientOptions)

Constructor that takes a connection string as an argument.

public DeviceClient(String connString, IotHubClientProtocol protocol, ClientOptions clientOptions)

参数

connString
String

the connection string. The connection string is a set of key-value pairs that are separated by ';', with the keys and values separated by '='. It should contain values for the following keys: HostName 

</code> ,<code>DeviceId 

</code> , and<code>SharedAccessKey 

</code> . </p>
protocol
IotHubClientProtocol

the communication protocol used (i.e. HTTPS)

clientOptions
ClientOptions

The options that allow configuration of the device client instance during initialization

例外

IllegalArgumentException

if any ofconnString 

</code> or <code>protocol 

</code> are<code>null 

</code> ; or if<code>connString 

</code> is missing one of the following attributes:<code>HostName 

</code> ,<code>DeviceId 

</code> , or <code>SharedAccessKey 

</code> or if the IoT hub hostname does not conform to RFC 3986 or if the provided<code>connString 

</code> is for an x509 authenticated device </p>
URISyntaxException

if the hostname in the connection string is not a valid URI

DeviceClient(String connString, IotHubClientProtocol protocol, SSLContext sslContext)

Creates a device client that uses the provided SSLContext for SSL negotiation

public DeviceClient(String connString, IotHubClientProtocol protocol, SSLContext sslContext)

参数

connString
String

the connection string for the device. May be an x509 connection string (format: "HostName=...;DeviceId=...;x509=true") and it may be a SAS connection string (format: "HostName=...;DeviceId=...;SharedAccessKey=..."). If this connection string is an x509 connection string, the client will use the provided SSLContext for authentication.

protocol
IotHubClientProtocol

the protocol to use when communicating with IotHub

sslContext
SSLContext

the ssl context that will be used during authentication. If the provided connection string does not contain SAS based credentials, then the sslContext will be used for x509 authentication. If the provided connection string does contain SAS based credentials, the sslContext will still be used during SSL negotiation.

例外

URISyntaxException

if the hostname in the connection string is not a valid URI

URISyntaxException

if the hostname in the connection string is not a valid URI

DeviceClient(String connString, IotHubClientProtocol protocol, String publicKeyCertificate, boolean isCertificatePath, String privateKey, boolean isPrivateKeyPath)

Constructor that uses x509 authentication for communicating with IotHub

<xreftitle>Deprecated</xreftitle>

<xrefdescription>

  <p>For x509 authentication, use <xref uid="com.microsoft.azure.sdk.iot.device.DeviceClient.DeviceClient(String,IotHubClientProtocol,ClientOptions)" data-throw-if-not-resolved="false" data-raw-source="DeviceClient(String, IotHubClientProtocol, ClientOptions)"></xref> and provide an SSLContext instance in the <xref uid="com.microsoft.azure.sdk.iot.device.ClientOptions" data-throw-if-not-resolved="false" data-raw-source="ClientOptions"></xref> instance. For a sample on how to build this SSLContext, see <a href="https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-samples/send-event-x509/src/main/java/samples/com/microsoft/azure/sdk/iot/SendEventX509.java">this code</a> 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 <a href="https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-samples/send-event-x509/pom.xml">this pom.xml</a> for an example of how to do this. </p>

</xrefdescription>

public DeviceClient(String connString, IotHubClientProtocol protocol, String publicKeyCertificate, boolean isCertificatePath, String privateKey, boolean isPrivateKeyPath)

参数

connString
String

the connection string for the x509 device to connect as (format: "HostName=...;DeviceId=...;x509=true")

protocol
IotHubClientProtocol

the protocol to use when communicating with IotHub

publicKeyCertificate
String

the PEM formatted public key certificate or the path to a PEM formatted public key certificate file. Append if there is any intermediate or chained certificates to the end of the public certificate file in the following format: BEGIN CERTIFICATE (Primary SSL certificate) END CERTIFICATE-BEGIN CERTIFICATE (Intermediate certificate) END CERTIFICATEBEGIN CERTIFICATE (Root certificate) END CERTIFICATE

isCertificatePath
boolean

if the provided publicKeyCertificate is a path to a file containing the PEM formatted public key certificate

privateKey
String

the PEM formatted private key or the path to a PEM formatted private key file

isPrivateKeyPath
boolean

if the provided privateKey is a path to a file containing the PEM formatted private key

例外

URISyntaxException

if the hostname in the connection string is not a valid URI

DeviceClient(String connString, TransportClient transportClient)

Constructor that takes a connection string and a transport client as an argument.

<xreftitle>Deprecated</xreftitle>

<xrefdescription>

  <p>

    <xref uid="com.microsoft.azure.sdk.iot.device.MultiplexingClient" data-throw-if-not-resolved="false" data-raw-source="MultiplexingClient"></xref> should be used instead of <xref uid="com.microsoft.azure.sdk.iot.device.TransportClient" data-throw-if-not-resolved="false" data-raw-source="TransportClient"></xref> for creating all multiplexed connections. </p>

</xrefdescription>

public DeviceClient(String connString, TransportClient transportClient)

参数

connString
String

the connection string. The connection string is a set of key-value pairs that are separated by ';', with the keys and values separated by '='. It should contain values for the following keys: HostName 

</code> ,<code>DeviceId 

</code> , and<code>SharedAccessKey 

</code> .</p>
transportClient
TransportClient

the transport client to use by the device client.

例外

IllegalArgumentException

ifconnString 

</code> or if<code>connString 

</code> is missing one of the following attributes:<code>HostName 

</code> ,<code>DeviceId 

</code> , or <code>SharedAccessKey 

</code> or if the IoT hub hostname does not conform to RFC 3986 or if the provided<code>connString 

</code> is for an x509 authenticated device </p>
URISyntaxException

if the hostname in the connection string is not a valid URI

UnsupportedOperationException

if the connection string belongs to a module rather than a device

DeviceClient(String hostName, String deviceId, 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.

public DeviceClient(String hostName, String deviceId, SasTokenProvider sasTokenProvider, IotHubClientProtocol protocol)

参数

hostName
String

The host name of the IoT Hub that this client will connect to.

deviceId
String

The Id of the device that the connection will identify as.

sasTokenProvider
SasTokenProvider

The provider of all SAS tokens that are used during authentication.

protocol
IotHubClientProtocol

The protocol that the client will connect over.

DeviceClient(String hostName, String deviceId, 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.

public DeviceClient(String hostName, String deviceId, SasTokenProvider sasTokenProvider, IotHubClientProtocol protocol, ClientOptions clientOptions)

参数

hostName
String

The host name of the IoT Hub that this client will connect to.

deviceId
String

The Id of the device that the connection will identify as.

sasTokenProvider
SasTokenProvider

The provider of all SAS tokens that are used during authentication.

protocol
IotHubClientProtocol

The protocol that the client will connect over.

clientOptions
ClientOptions

The options that allow configuration of the device client instance during initialization.

适用于