Search in sources :

Example 1 with JobClientOptions

use of com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions in project azure-iot-sdk-java by Azure.

the class JobClientTest method testOptionsDefaults.

@Test
public void testOptionsDefaults() {
    JobClientOptions options = JobClientOptions.builder().build();
    assertEquals((int) Deencapsulation.getField(JobClientOptions.class, "DEFAULT_HTTP_READ_TIMEOUT_MS"), options.getHttpReadTimeout());
    assertEquals((int) Deencapsulation.getField(JobClientOptions.class, "DEFAULT_HTTP_CONNECT_TIMEOUT_MS"), options.getHttpConnectTimeout());
}
Also used : JobClientOptions(com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions) Test(org.junit.Test)

Example 2 with JobClientOptions

use of com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions in project azure-iot-sdk-java by Azure.

the class JobClientTests method buildJobClientWithAzureSasCredential.

private static JobClient buildJobClientWithAzureSasCredential() {
    IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
    IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
    AzureSasCredential azureSasCredential = new AzureSasCredential(serviceSasToken.toString());
    JobClientOptions options = JobClientOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build();
    return new JobClient(iotHubConnectionStringObj.getHostName(), azureSasCredential, options);
}
Also used : JobClientOptions(com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions) IotHubServiceSasToken(com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken) AzureSasCredential(com.azure.core.credential.AzureSasCredential) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient)

Example 3 with JobClientOptions

use of com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions in project azure-iot-sdk-java by Azure.

the class AzureSasCredentialSample method runJobClientSample.

private static void runJobClientSample(String iotHubHostName, AzureSasCredential credential) {
    // JobClient has some configurable options for HTTP read and connect timeouts, as well as for setting proxies.
    // For this sample, the default options will be used though.
    JobClientOptions options = JobClientOptions.builder().build();
    // This constructor takes in your implementation of AzureSasCredential which allows you to use symmetric key based
    // authentication without giving the client your connection string.
    JobClient jobClient = new JobClient(iotHubHostName, credential, options);
    try {
        System.out.println("Querying all active jobs for your IoT Hub");
        Query deviceJobQuery = jobClient.queryDeviceJob(SqlQuery.createSqlQuery("*", SqlQuery.FromType.JOBS, null, null).getQuery());
        int queriedJobCount = 0;
        while (jobClient.hasNextJob(deviceJobQuery)) {
            queriedJobCount++;
            JobResult job = jobClient.getNextJob(deviceJobQuery);
            System.out.println(String.format("Job %s of type %s has status %s", job.getJobId(), job.getJobType(), job.getJobStatus()));
        }
        if (queriedJobCount == 0) {
            System.out.println("No active jobs found for your IoT Hub");
        }
    } catch (IotHubException | IOException e) {
        System.err.println("Failed to query the jobs for your IoT Hub");
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : JobClientOptions(com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions) SqlQuery(com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery) Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) IOException(java.io.IOException) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 4 with JobClientOptions

use of com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions in project azure-iot-sdk-java by Azure.

the class RoleBasedAuthenticationSample method runJobClientSample.

private static void runJobClientSample(String iotHubHostName, TokenCredential credential) {
    // JobClient has some configurable options for HTTP read and connect timeouts, as well as for setting proxies.
    // For this sample, the default options will be used though.
    JobClientOptions options = JobClientOptions.builder().build();
    // This constructor takes in your implementation of TokenCredential which allows you to use RBAC authentication
    // rather than symmetric key based authentication that comes with constructors that take connection strings.
    JobClient jobClient = new JobClient(iotHubHostName, credential, options);
    try {
        System.out.println("Querying all active jobs for your IoT Hub");
        Query deviceJobQuery = jobClient.queryDeviceJob(SqlQuery.createSqlQuery("*", SqlQuery.FromType.JOBS, null, null).getQuery());
        int queriedJobCount = 0;
        while (jobClient.hasNextJob(deviceJobQuery)) {
            queriedJobCount++;
            JobResult job = jobClient.getNextJob(deviceJobQuery);
            System.out.println(String.format("Job %s of type %s has status %s", job.getJobId(), job.getJobType(), job.getJobStatus()));
        }
        if (queriedJobCount == 0) {
            System.out.println("No active jobs found for your IoT Hub");
        }
    } catch (IotHubException | IOException e) {
        System.err.println("Failed to query the jobs for your IoT Hub");
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : JobClientOptions(com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions) SqlQuery(com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery) Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) IOException(java.io.IOException) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Aggregations

JobClientOptions (com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions)4 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)3 Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)2 SqlQuery (com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery)2 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)2 JobResult (com.microsoft.azure.sdk.iot.service.jobs.JobResult)2 IOException (java.io.IOException)2 AzureSasCredential (com.azure.core.credential.AzureSasCredential)1 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)1 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)1 Test (org.junit.Test)1