ProvisioningServiceClient.runBulkEnrollmentOperation(BulkOperationMode bulkOperationMode, Collection<IndividualEnrollment> individualEnrollments) 方法

定义

Create, update or delete a set of individual Device Enrollments.

This API provide the means to do a single operation over multiple individualEnrollments. A valid operation is determined by BulkOperationMode, and can be 'create', 'update', 'updateIfMatchETag', or 'delete'.

To use the Device Provisioning Service API, you must include the follow package on your application.

// Include the following imports to use the Device Provisioning Service APIs.
    import com.microsoft.azure.sdk.iot.provisioning.service.*;
    

Sample:

The follow code will create two new enrollment that will provisioning the ContosoDevice1000 and ContosoDevice1001 to the ContosoHub.azure-devices.net using TPM attestation.

// IndividualEnrollment information.
    private static final String PROVISIONING_CONNECTION_STRING = "HostName=ContosoProvisioning.azure-devices-provisioning.net;" +
                                                                 "SharedAccessKeyName=contosoprovisioningserviceowner;" +
                                                                 "SharedAccessKey=0000000000000000000000000000000000000000000=";
    private static final String TPM_ENDORSEMENT_KEY = "tpm-endorsement-key";
    private static final String IOTHUB_HOST_NAME = "ContosoHub.azure-devices.net";
    
    private static final String REGISTRATION_ID_1 = "registrationId-1";
    private static final String DEVICE_ID_1 = "ContosoDevice1000";
    
    private static final String REGISTRATION_ID_2 = "registrationId-2";
    private static final String DEVICE_ID_2 = "ContosoDevice1001";
    
    public static void main(String[] args) throws IOException, URISyntaxException, ProvisioningServiceClientException
    {
        // Create a Device Provisioning Service Client.
        DeviceProvisioningServiceClient deviceProvisioningServiceClient =
            DeviceProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
    
        // Create two new individualEnrollment configurations.
        Attestation attestation = new TpmAttestation(TPM_ENDORSEMENT_KEY);
        IndividualEnrollment enrollment1 =
           new IndividualEnrollment(
                REGISTRATION_ID_1,
                attestation);
        enrollment1.setDeviceId(DEVICE_ID_1);
        enrollment1.setIotHubHostName(IOTHUB_HOST_NAME);
        enrollment1.setProvisioningStatus(ProvisioningStatus.DISABLED);
    
        IndividualEnrollment enrollment2 =
           new IndividualEnrollment(
                REGISTRATION_ID_2,
                attestation);
        enrollment2.setDeviceId(DEVICE_ID_2);
        enrollment2.setIotHubHostName(IOTHUB_HOST_NAME);
        enrollment2.setProvisioningStatus(ProvisioningStatus.DISABLED);
    
        // Add these 2 individualEnrollments to a list of individualEnrollments.
        List<IndividualEnrollment> individualEnrollments = new LinkedList<>();
        individualEnrollments.add(enrollment1);
        individualEnrollments.add(enrollment2);
    
        // Create these 2 new individualEnrollment using the bulk operation.
        BulkEnrollmentOperationResult bulkEnrollmentOperationResult =  provisioningServiceClient.runBulkEnrollmentOperation(BulkOperationMode.create, individualEnrollments);
    }
    

public BulkEnrollmentOperationResult runBulkEnrollmentOperation(BulkOperationMode bulkOperationMode, Collection<IndividualEnrollment> individualEnrollments)

参数

bulkOperationMode
BulkOperationMode

the BulkOperationMode that defines the single operation to do over the individualEnrollments. It cannot benull 

</code> . </p>
individualEnrollments
Collection<IndividualEnrollment>

the collection of IndividualEnrollment that contains the description of each individualEnrollment. It cannot benull 

</code> or empty. </p>

返回

A BulkEnrollmentOperationResult object with the result of operation for each enrollment.

例外

IllegalArgumentException

if the provided parameters are not correct.

ProvisioningServiceClientTransportException

if the SDK failed to send the request to the Device Provisioning Service.

ProvisioningServiceClientException

if the Device Provisioning Service was not able to execute the bulk operation.

适用于