Class DigitalTwinsAsyncClient

java.lang.Object
com.azure.digitaltwins.core.DigitalTwinsAsyncClient

public final class DigitalTwinsAsyncClient extends Object
This class provides a client for interacting asynchronously with an Azure Digital Twins instance. This client is instantiated through DigitalTwinsClientBuilder.

Code Samples

 DigitalTwinsAsyncClient digitalTwinsAsyncClient = new DigitalTwinsClientBuilder()
     .credential(
         new ClientSecretCredentialBuilder()
             .tenantId(tenantId)
             .clientId(clientId)
             .clientSecret(clientSecret)
             .build())
     .endpoint(digitalTwinsEndpointUrl)
     .buildAsyncClient();
 

This client allows for management of digital twins, their components, and their relationships. It also allows for managing the digital twin models and event routes tied to your Azure Digital Twins instance.

  • Method Details

    • getServiceVersion

      public DigitalTwinsServiceVersion getServiceVersion()
      Gets the Azure Digital Twins service API version that this client is configured to use for all service requests. Unless configured while building this client through DigitalTwinsClientBuilder.serviceVersion(DigitalTwinsServiceVersion), this value will be equal to the latest service API version supported by this client.
      Returns:
      The Azure Digital Twins service API version.
    • createOrReplaceDigitalTwin

      public <T> Mono<T> createOrReplaceDigitalTwin(String digitalTwinId, T digitalTwin, Class<T> clazz)
      Creates a digital twin. If the provided digital twin Id is already in use, then this will attempt to replace the existing digital twin with the provided digital twin.

      Code Samples

      You can provide a strongly typed digital twin object such as BasicDigitalTwin as the input parameter:

       String modelId = "dtmi:com:samples:Building;1";
      
       BasicDigitalTwin basicTwin = new BasicDigitalTwin("myDigitalTwinId")
           .setMetadata(
               new BasicDigitalTwinMetadata()
                   .setModelId(modelId)
           );
      
       digitalTwinsAsyncClient.createOrReplaceDigitalTwin(basicTwin.getId(), basicTwin, BasicDigitalTwin.class)
           .subscribe(response -> System.out.println("Created digital twin Id: " + response.getId()));
       

      Or alternatively String can be used as input and output deserialization type:

       digitalTwinsAsyncClient.createOrReplaceDigitalTwin("myDigitalTwinId", digitalTwinStringPayload, String.class)
           .subscribe(stringResponse -> System.out.println("Created digital twin: " + stringResponse));
       
      Type Parameters:
      T - The generic type to serialize the request with and deserialize the response with.
      Parameters:
      digitalTwinId - The Id of the digital twin. The Id is unique within the service and case sensitive.
      digitalTwin - The application/json object representing the digital twin to create.
      clazz - The model class to serialize the request with and deserialize the response with.
      Returns:
      The deserialized application/json object representing the digital twin created.
    • createOrReplaceDigitalTwinWithResponse

      public <T> Mono<DigitalTwinsResponse<T>> createOrReplaceDigitalTwinWithResponse(String digitalTwinId, T digitalTwin, Class<T> clazz, CreateOrReplaceDigitalTwinOptions options)
      Creates a digital twin. If the provided digital twin Id is already in use, then this will attempt to replace the existing digital twin with the provided digital twin.

      Code Samples

      You can provide a strongly typed digital twin object such as BasicDigitalTwin as the input parameter:

       String modelId = "dtmi:com:samples:Building;1";
      
       BasicDigitalTwin basicDigitalTwin = new BasicDigitalTwin("myDigitalTwinId")
           .setMetadata(
               new BasicDigitalTwinMetadata()
                   .setModelId(modelId)
           );
      
       digitalTwinsAsyncClient.createOrReplaceDigitalTwinWithResponse(
           basicDigitalTwin.getId(),
           basicDigitalTwin,
           BasicDigitalTwin.class,
           new CreateOrReplaceDigitalTwinOptions())
           .subscribe(resultWithResponse ->
               System.out.println(
                   "Response http status: "
                   + resultWithResponse.getStatusCode()
                   + " created digital twin Id: "
                   + resultWithResponse.getValue().getId()));
       

      Or alternatively String can be used as input and output deserialization type:

       digitalTwinsAsyncClient.createOrReplaceDigitalTwinWithResponse(
           basicDigitalTwin.getId(),
           stringPayload,
           String.class,
           new CreateOrReplaceDigitalTwinOptions())
           .subscribe(stringWithResponse ->
               System.out.println(
                   "Response http status: "
                   + stringWithResponse.getStatusCode()
                   + " created digital twin: "
                   + stringWithResponse.getValue()));
       
      Type Parameters:
      T - The generic type to serialize the request with and deserialize the response with.
      Parameters:
      digitalTwinId - The Id of the digital twin. The Id is unique within the service and case sensitive.
      digitalTwin - The application/json object representing the digital twin to create.
      clazz - The model class to serialize the request with and deserialize the response with.
      options - The optional parameters for this request. If null, the default option values will be used.
      Returns:
      A DigitalTwinsResponse containing the deserialized application/json object representing the digital twin created.
    • getDigitalTwin

      public <T> Mono<T> getDigitalTwin(String digitalTwinId, Class<T> clazz)
      Gets a digital twin.

      Code Samples

      A Strongly typed object type such as BasicDigitalTwin can be provided as an input parameter for clazz to indicate what type is used to deserialize the response.

       digitalTwinsAsyncClient.getDigitalTwin("myDigitalTwinId", BasicDigitalTwin.class)
           .subscribe(
               basicDigitalTwin -> System.out.println("Retrieved digital twin with Id: " + basicDigitalTwin.getId()));
       

      Or alternatively String can be used as input and output deserialization type:

       digitalTwinsAsyncClient.getDigitalTwin("myDigitalTwinId", String.class)
           .subscribe(stringResult -> System.out.println("Retrieved digital twin: " + stringResult));
       
      Type Parameters:
      T - The generic type to deserialize the digital twin with.
      Parameters:
      digitalTwinId - The Id of the digital twin. The Id is unique within the service and case sensitive.
      clazz - The model class to deserialize the response with.
      Returns:
      The deserialized application/json object representing the digital twin
    • getDigitalTwinWithResponse

      public <T> Mono<DigitalTwinsResponse<T>> getDigitalTwinWithResponse(String digitalTwinId, Class<T> clazz)
      Gets a digital twin.

      Code Samples

      A Strongly typed object type such as BasicDigitalTwin can be provided as an input parameter for clazz to indicate what type is used to deserialize the response.

       digitalTwinsAsyncClient.getDigitalTwinWithResponse(
           "myDigitalTwinId",
           BasicDigitalTwin.class)
           .subscribe(
               basicDigitalTwinWithResponse -> System.out.println(
                   "Retrieved digital twin with Id: " + basicDigitalTwinWithResponse.getValue().getId()
                   + " Http Status Code: " + basicDigitalTwinWithResponse.getStatusCode()));
       

      Or alternatively String can be used as input and output deserialization type:

       digitalTwinsAsyncClient.getDigitalTwinWithResponse(
           "myDigitalTwinId",
           String.class)
           .subscribe(
               basicDigitalTwinWithResponse -> System.out.println(
                   "Retrieved digital twin: " + basicDigitalTwinWithResponse.getValue()
                   + " Http Status Code: " + basicDigitalTwinWithResponse.getStatusCode()));
       
      Type Parameters:
      T - The generic type to deserialize the digital twin with.
      Parameters:
      digitalTwinId - The Id of the digital twin. The Id is unique within the service and case sensitive.
      clazz - The model class to deserialize the response with.
      Returns:
      A DigitalTwinsResponse containing the deserialized application/json object representing the digital twin.
    • updateDigitalTwin

      public Mono<Void> updateDigitalTwin(String digitalTwinId, JsonPatchDocument jsonPatch)
      Updates a digital twin.

      Code Samples

      Update digital twin by providing list of intended patch operations.

       JsonPatchDocument jsonPatchDocument = new JsonPatchDocument();
       jsonPatchDocument.appendReplace("Prop1", "newValue");
      
       digitalTwinsAsyncClient.updateDigitalTwin(
           "myDigitalTwinId",
           jsonPatchDocument)
           .subscribe();
       
      Parameters:
      digitalTwinId - The Id of the digital twin. The Id is unique within the service and case sensitive.
      jsonPatch - The JSON patch to apply to the specified digital twin. This argument can be created using JsonPatchDocument.
      Returns:
      An empty Mono
    • updateDigitalTwinWithResponse

      public Mono<DigitalTwinsResponse<Void>> updateDigitalTwinWithResponse(String digitalTwinId, JsonPatchDocument jsonPatch, UpdateDigitalTwinOptions options)
      Updates a digital twin.

      Code Samples

      Update digital twin by providing list of intended patch operations.

       JsonPatchDocument jsonPatchDocument = new JsonPatchDocument();
       jsonPatchDocument.appendReplace("Prop1", "newValue");
      
       digitalTwinsAsyncClient.updateDigitalTwinWithResponse(
           "myDigitalTwinId",
           jsonPatchDocument,
           new UpdateDigitalTwinOptions())
           .subscribe(updateResponse ->
               System.out.println("Update completed with HTTP status code: " + updateResponse.getStatusCode()));
       
      Parameters:
      digitalTwinId - The Id of the digital twin. The Id is unique within the service and case sensitive.
      jsonPatch - The JSON patch to apply to the specified digital twin. This argument can be created using JsonPatchDocument.
      options - The optional parameters for this request. If null, the default option values will be used.
      Returns:
      A DigitalTwinsResponse. This response object includes an HTTP header that gives you the updated ETag for this resource.
    • deleteDigitalTwin

      public Mono<Void> deleteDigitalTwin(String digitalTwinId)
      Deletes a digital twin. All relationships referencing the digital twin must already be deleted.

      Code Samples

       digitalTwinsAsyncClient.deleteDigitalTwin("myDigitalTwinId")
           .subscribe();
       
      Parameters:
      digitalTwinId - The Id of the digital twin. The Id is unique within the service and case sensitive.
      Returns:
      An empty Mono
    • deleteDigitalTwinWithResponse

      public Mono<Response<Void>> deleteDigitalTwinWithResponse(String digitalTwinId, DeleteDigitalTwinOptions options)
      Deletes a digital twin. All relationships referencing the digital twin must already be deleted.

      Code Samples

       digitalTwinsAsyncClient.deleteDigitalTwinWithResponse(
           "myDigitalTwinId",
           new DeleteDigitalTwinOptions())
           .subscribe(deleteResponse ->
               System.out.println("Deleted digital twin. HTTP response status code: " + deleteResponse.getStatusCode()));
       
      Parameters:
      digitalTwinId - The Id of the digital twin. The Id is unique within the service and case sensitive.
      options - The optional parameters for this request. If null, the default option values will be used.
      Returns:
      The Http response
    • createOrReplaceRelationship

      public <T> Mono<T> createOrReplaceRelationship(String digitalTwinId, String relationshipId, T relationship, Class<T> clazz)
      Creates a relationship on a digital twin. If the provided relationship Id is already in use, then this will attempt to replace the existing relationship with the provided relationship.

      Code Samples

      A strongly typed digital twin object such as BasicRelationship can be provided as the input parameter to deserialize the response into.

       BasicRelationship buildingToFloorBasicRelationship = new BasicRelationship(
               "myRelationshipId",
               "mySourceDigitalTwinId",
               "myTargetDigitalTwinId",
               "contains")
           .addProperty("Prop1", "Prop1 value")
           .addProperty("Prop2", 6);
      
       digitalTwinsAsyncClient.createOrReplaceRelationship(
           "mySourceDigitalTwinId",
           "myRelationshipId",
           buildingToFloorBasicRelationship,
           BasicRelationship.class)
           .subscribe(createdRelationship -> System.out.println(
               "Created relationship with Id: "
               + createdRelationship.getId()
               + " from: " + createdRelationship.getSourceId()
               + " to: " + createdRelationship.getTargetId()));
       

      Or alternatively String can be used as input and output deserialization type:

       String relationshipPayload = getRelationshipPayload();
      
       digitalTwinsAsyncClient.createOrReplaceRelationship(
           "mySourceDigitalTwinId",
           "myRelationshipId",
           relationshipPayload,
           String.class)
           .subscribe(createRelationshipString ->
               System.out.println("Created relationship: " + createRelationshipString));
       
      Type Parameters:
      T - The generic type of the relationship.
      Parameters:
      digitalTwinId - The Id of the source digital twin.
      relationshipId - The Id of the relationship to be created.
      relationship - The relationship to be created.
      clazz - The model class of the relationship.
      Returns:
      The relationship created.
    • createOrReplaceRelationshipWithResponse

      public <T> Mono<DigitalTwinsResponse<T>> createOrReplaceRelationshipWithResponse(String digitalTwinId, String relationshipId, T relationship, Class<T> clazz, CreateOrReplaceRelationshipOptions options)
      Creates a relationship on a digital twin. If the provided relationship Id is already in use, then this will attempt to replace the existing relationship with the provided relationship.

      Code Samples

      A strongly typed digital twin object such as BasicRelationship can be provided as the input parameter to deserialize the response into.

       BasicRelationship buildingToFloorBasicRelationship = new BasicRelationship(
               "myRelationshipId",
               "mySourceDigitalTwinId",
               "myTargetDigitalTwinId",
               "contains")
           .addProperty("Prop1", "Prop1 value")
           .addProperty("Prop2", 6);
      
       digitalTwinsAsyncClient.createOrReplaceRelationshipWithResponse(
           "mySourceDigitalTwinId",
           "myRelationshipId",
           buildingToFloorBasicRelationship,
           BasicRelationship.class,
           new CreateOrReplaceRelationshipOptions())
           .subscribe(createdRelationshipWithResponse -> System.out.println(
               "Created relationship with Id: "
               + createdRelationshipWithResponse.getValue().getId()
               + " from: " + createdRelationshipWithResponse.getValue().getSourceId()
               + " to: " + createdRelationshipWithResponse.getValue().getTargetId()
               + " Http status code: "
               + createdRelationshipWithResponse.getStatusCode()));
       

      Or alternatively String can be used as input and output deserialization type:

       String relationshipPayload = getRelationshipPayload();
      
       digitalTwinsAsyncClient.createOrReplaceRelationshipWithResponse(
           "mySourceDigitalTwinId",
           "myRelationshipId",
           relationshipPayload,
           String.class,
           new CreateOrReplaceRelationshipOptions())
           .subscribe(createdRelationshipStringWithResponse -> System.out.println(
               "Created relationship: "
               + createdRelationshipStringWithResponse
               + " With HTTP status code: "
               + createdRelationshipStringWithResponse.getStatusCode()));
       
      Type Parameters:
      T - The generic type of the relationship.
      Parameters:
      digitalTwinId - The Id of the source digital twin.
      relationshipId - The Id of the relationship to be created.
      relationship - The relationship to be created.
      clazz - The model class of the relationship.
      options - The optional parameters for this request. If null, the default option values will be used.
      Returns:
      A DigitalTwinsResponse containing the relationship created.
    • getRelationship

      public <T> Mono<T> getRelationship(String digitalTwinId, String relationshipId, Class<T> clazz)
      Gets a relationship on a digital twin.

      Code Samples

      A strongly typed digital twin object such as BasicRelationship can be provided as the input parameter to deserialize the response into.

       digitalTwinsAsyncClient.getRelationship(
           "myDigitalTwinId",
           "myRelationshipName",
           BasicRelationship.class)
           .subscribe(retrievedRelationship -> System.out.println(
               "Retrieved relationship with Id: "
               + retrievedRelationship.getId()
               + " from: "
               + retrievedRelationship.getSourceId()
               + " to: " + retrievedRelationship.getTargetId()));
       

      Or alternatively String can be used as input and output deserialization type:

       digitalTwinsAsyncClient.getRelationship(
           "myDigitalTwinId",
           "myRelationshipName",
           String.class)
           .subscribe(retrievedRelationshipString ->
               System.out.println("Retrieved relationship: " + retrievedRelationshipString));
       
      Type Parameters:
      T - The generic type to deserialize the relationship into.
      Parameters:
      digitalTwinId - The Id of the source digital twin.
      relationshipId - The Id of the relationship to retrieve.
      clazz - The model class to deserialize the relationship into.
      Returns:
      The deserialized relationship.
    • getRelationshipWithResponse

      public <T> Mono<DigitalTwinsResponse<T>> getRelationshipWithResponse(String digitalTwinId, String relationshipId, Class<T> clazz)
      Gets a relationship on a digital twin.

      Code Samples

      A strongly typed digital twin object such as BasicRelationship can be provided as the input parameter to deserialize the response into.

       digitalTwinsAsyncClient.getRelationshipWithResponse(
           "myDigitalTwinId",
           "myRelationshipName",
           BasicRelationship.class)
           .subscribe(retrievedRelationshipWithResponse -> System.out.println(
               "Retrieved relationship with Id: "
                   + retrievedRelationshipWithResponse.getValue().getId()
                   + " from: "
                   + retrievedRelationshipWithResponse.getValue().getSourceId()
                   + " to: " + retrievedRelationshipWithResponse.getValue().getTargetId()
                   + "HTTP status code: " + retrievedRelationshipWithResponse.getStatusCode()));
       

      Or alternatively String can be used as input and output deserialization type:

       digitalTwinsAsyncClient.getRelationshipWithResponse(
           "myDigitalTwinId",
           "myRelationshipName",
           String.class)
           .subscribe(retrievedRelationshipStringWithResponse -> System.out.println(
               "Retrieved relationship: "
               + retrievedRelationshipStringWithResponse
               + " HTTP status code: "
               + retrievedRelationshipStringWithResponse.getStatusCode()));
       
      Type Parameters:
      T - The generic type to deserialize the relationship into.
      Parameters:
      digitalTwinId - The Id of the source digital twin.
      relationshipId - The Id of the relationship to retrieve.
      clazz - The model class to deserialize the relationship into.
      Returns:
      A DigitalTwinsResponse containing the deserialized relationship.
    • updateRelationship

      public Mono<Void> updateRelationship(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch)
      Updates the properties of a relationship on a digital twin.

      Code Samples

       JsonPatchDocument jsonPatchDocument = new JsonPatchDocument();
       jsonPatchDocument.appendReplace("/relationshipProperty1", "new property value");
      
       digitalTwinsAsyncClient.updateRelationship(
           "myDigitalTwinId",
           "myRelationshipId",
           jsonPatchDocument)
           .subscribe();
       
      Parameters:
      digitalTwinId - The Id of the source digital twin.
      relationshipId - The Id of the relationship to be updated.
      jsonPatch - The JSON patch to apply to the specified digital twin's relationship. This argument can be created using JsonPatchDocument.
      Returns:
      An empty Mono.
    • updateRelationshipWithResponse

      public Mono<DigitalTwinsResponse<Void>> updateRelationshipWithResponse(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch, UpdateRelationshipOptions options)
      Updates the properties of a relationship on a digital twin.

      Code Samples

       JsonPatchDocument jsonPatchDocument = new JsonPatchDocument();
       jsonPatchDocument.appendReplace("/relationshipProperty1", "new property value");
      
       digitalTwinsAsyncClient.updateRelationshipWithResponse(
           "myDigitalTwinId",
           "myRelationshipId",
           jsonPatchDocument,
           new UpdateRelationshipOptions())
           .subscribe(updateResponse ->
               System.out.println(
                   "Relationship updated with status code: "
                   + updateResponse.getStatusCode()));
       
      Parameters:
      digitalTwinId - The Id of the source digital twin.
      relationshipId - The Id of the relationship to be updated.
      jsonPatch - The JSON patch to apply to the specified digital twin's relationship. This argument can be created using JsonPatchDocument.
      options - The optional parameters for this request. If null, the default option values will be used.
      Returns:
      A DigitalTwinsResponse containing no parsed payload object. This response object includes an HTTP header that gives you the updated ETag for this resource.
    • deleteRelationship

      public Mono<Void> deleteRelationship(String digitalTwinId, String relationshipId)
      Deletes a relationship on a digital twin.

      Code Samples

       digitalTwinsAsyncClient.deleteRelationship("myDigitalTwinId", "myRelationshipId")
           .subscribe();
       
      Parameters:
      digitalTwinId - The Id of the source digital twin.
      relationshipId - The Id of the relationship to delete.
      Returns:
      An empty Mono.
    • deleteRelationshipWithResponse

      public Mono<Response<Void>> deleteRelationshipWithResponse(String digitalTwinId, String relationshipId, DeleteRelationshipOptions options)
      Deletes a relationship on a digital twin.

      Code Samples

       digitalTwinsAsyncClient.deleteRelationshipWithResponse(
           "myDigitalTwinId",
           "myRelationshipId",
           new DeleteRelationshipOptions())
           .subscribe(deleteResponse ->
               System.out.println(
                   "Deleted relationship with HTTP status code: "
                   + deleteResponse.getStatusCode()));
       
      Parameters:
      digitalTwinId - The Id of the source digital twin.
      relationshipId - The Id of the relationship to delete.
      options - The optional parameters for this request. If null, the default option values will be used.
      Returns:
      A Response containing no parsed payload object.
    • listRelationships

      public <T> PagedFlux<T> listRelationships(String digitalTwinId, Class<T> clazz)
      Gets all the relationships on a digital twin by iterating through a collection.

      A strongly typed digital twin object such as BasicRelationship can be provided as the input parameter to deserialize the response into.

       digitalTwinsAsyncClient.listRelationships("myDigitalTwinId", BasicRelationship.class)
           .doOnNext(basicRel -> System.out.println("Retrieved relationship with Id: " + basicRel.getId()));
       

      Or alternatively String can be used as input and output deserialization type:

       digitalTwinsAsyncClient.listRelationships("myDigitalTwinId", String.class)
           .doOnNext(rel -> System.out.println("Retrieved relationship: " + rel));
       
      Type Parameters:
      T - The generic type to convert the relationship to.
      Parameters:
      digitalTwinId - The Id of the source digital twin.
      clazz - The model class to convert the relationship to. Since a digital twin might have relationships conforming to different models, it is advisable to convert them to a generic model like BasicRelationship.
      Returns:
      A PagedFlux of relationships belonging to the specified digital twin and the http response.
    • listRelationships

      public <T> PagedFlux<T> listRelationships(String digitalTwinId, String relationshipName, Class<T> clazz)
      Gets all the relationships on a digital twin filtered by the relationship name, by iterating through a collection.

      A strongly typed digital twin object such as BasicRelationship can be provided as the input parameter to deserialize the response into.

       digitalTwinsAsyncClient.listRelationships(
           "myDigitalTwinId",
           "myRelationshipName",
           BasicRelationship.class)
           .doOnNext(rel -> System.out.println("Retrieved relationship with Id: " + rel.getId()));
       

      Or alternatively String can be used as input and output deserialization type:

       digitalTwinsAsyncClient.listRelationships(
           "myDigitalTwinId",
           "myRelationshipId",
           String.class)
           .doOnNext(rel -> System.out.println("Retrieved relationship: " + rel));
       
      Type Parameters:
      T - The generic type to convert the relationship to.
      Parameters:
      digitalTwinId - The Id of the source digital twin.
      relationshipName - The name of a relationship to filter to.
      clazz - The model class to convert the relationship to.
      Returns:
      A PagedFlux of relationships belonging to the specified digital twin and the http response.
    • listIncomingRelationships

      public PagedFlux<IncomingRelationship> listIncomingRelationships(String digitalTwinId)
      Gets all the relationships referencing a digital twin as a target by iterating through a collection.

      Code Samples

       digitalTwinsAsyncClient.listIncomingRelationships("myDigitalTwinId")
           .doOnNext(incomingRel -> System.out.println(
               "Retrieved relationship with Id: "
                   + incomingRel.getRelationshipId()
                   + " from: " + incomingRel.getSourceId()
                   + " to: myDigitalTwinId"))
           .subscribe();
       
      Parameters:
      digitalTwinId - The Id of the target digital twin.
      Returns:
      A PagedFlux of relationships directed towards the specified digital twin and the http response.
    • createModels

      public Mono<Iterable<DigitalTwinsModelData>> createModels(Iterable<String> dtdlModels)
      Creates one or many models.

      Code Samples

       digitalTwinsAsyncClient.createModels(Arrays.asList(model1, model2, model3))
           .subscribe(createdModels -> createdModels.forEach(model ->
               System.out.println("Retrieved model with Id: " + model.getModelId())));
       
      Parameters:
      dtdlModels - The list of models to create. Each string corresponds to exactly one model.
      Returns:
      A List of created models. Each DigitalTwinsModelData instance in this list will contain metadata about the created model, but will not contain the model itself.
    • createModelsWithResponse

      public Mono<Response<Iterable<DigitalTwinsModelData>>> createModelsWithResponse(Iterable<String> dtdlModels)
      Creates one or many models.

      Code Samples

       digitalTwinsAsyncClient.createModelsWithResponse(
           Arrays.asList(model1, model2, model3))
           .subscribe(createdModels -> {
               System.out.println("Received a response with HTTP status code: " + createdModels.getStatusCode());
               createdModels.getValue().forEach(
                   model -> System.out.println("Retrieved model with Id: " + model.getModelId()));
           });
       
      Parameters:
      dtdlModels - The list of models to create. Each string corresponds to exactly one model.
      Returns:
      A Response containing the list of created models. Each DigitalTwinsModelData instance in this list will contain metadata about the created model, but will not contain the model itself.
    • getModel

      public Mono<DigitalTwinsModelData> getModel(String modelId)
      Gets a model, including the model metadata and the model definition.

      Code Samples

       digitalTwinsAsyncClient.getModel("dtmi:com:samples:Building;1")
           .subscribe(model -> System.out.println("Retrieved model with Id: " + model.getModelId()));
       
      Parameters:
      modelId - The Id of the model.
      Returns:
      A DigitalTwinsModelData instance that contains the model and its metadata.
    • getModelWithResponse

      public Mono<Response<DigitalTwinsModelData>> getModelWithResponse(String modelId)
      Gets a model, including the model metadata and the model definition.

      Code Samples

       digitalTwinsAsyncClient.getModelWithResponse(
           "dtmi:com:samples:Building;1")
           .subscribe(modelWithResponse -> {
               System.out.println("Received HTTP response with status code: " + modelWithResponse.getStatusCode());
               System.out.println("Retrieved model with Id: " + modelWithResponse.getValue().getModelId());
           });
       
      Parameters:
      modelId - The Id of the model.
      Returns:
      A Response containing a DigitalTwinsModelData instance that contains the model and its metadata.
    • listModels

      public PagedFlux<DigitalTwinsModelData> listModels()
      List all of the models in this digital twins instance.

      Code Samples

       digitalTwinsAsyncClient.listModels()
           .doOnNext(model -> System.out.println("Retrieved model with Id: " + model.getModelId()))
           .subscribe();
       
      Returns:
      A PagedFlux of DigitalTwinsModelData that enumerates all the models.
    • listModels

      public PagedFlux<DigitalTwinsModelData> listModels(ListModelsOptions options)
      List the models in this digital twins instance based on some options.

      Code Samples

       digitalTwinsAsyncClient.listModels(
           new ListModelsOptions()
               .setMaxItemsPerPage(5)
               .setIncludeModelDefinition(true))
           .doOnNext(model -> System.out.println("Retrieved model with Id: " + model.getModelId()))
           .subscribe();
       
      Parameters:
      options - The optional parameters for this request. If null, the default option values will be used.
      Returns:
      A PagedFlux containing the retrieved DigitalTwinsModelData instances.
    • deleteModel

      public Mono<Void> deleteModel(String modelId)
      Deletes a model.

      Code Samples

       digitalTwinsAsyncClient.deleteModel("dtmi:com:samples:Building;1")
           .subscribe();
       
      Parameters:
      modelId - The Id for the model. The Id is globally unique and case sensitive.
      Returns:
      An empty Mono
    • deleteModelWithResponse

      public Mono<Response<Void>> deleteModelWithResponse(String modelId)
      Deletes a model.

      Code Samples

       digitalTwinsAsyncClient.deleteModelWithResponse(
           "dtmi:com:samples:Building;1")
           .subscribe(response ->
               System.out.println(
                   "Received delete model operation response with HTTP status code:"
                   + response.getStatusCode()));
       
      Parameters:
      modelId - The Id for the model. The Id is globally unique and case sensitive.
      Returns:
      A Response with no parsed payload object.
    • decommissionModel

      public Mono<Void> decommissionModel(String modelId)
      Decommissions a model.

      Code Samples

       digitalTwinsAsyncClient.decommissionModel("dtmi:com:samples:Building;1")
           .subscribe();
       
      Parameters:
      modelId - The Id of the model to decommission.
      Returns:
      an empty Mono
    • decommissionModelWithResponse

      public Mono<Response<Void>> decommissionModelWithResponse(String modelId)
      Decommissions a model.

      Code Samples

       digitalTwinsAsyncClient.decommissionModelWithResponse(
           "dtmi:com:samples:Building;1")
           .subscribe(response ->
               System.out.println(
                   "Received decommission model HTTP response with status:"
                   + response.getStatusCode()));
       
      Parameters:
      modelId - The Id of the model to decommission.
      Returns:
      A Response with no parsed payload object.
    • getComponent

      public <T> Mono<T> getComponent(String digitalTwinId, String componentName, Class<T> clazz)
      Get a component of a digital twin.

      Code Samples

       digitalTwinsAsyncClient.getComponent(
           "myDigitalTwinId",
           "myComponentName",
           String.class)
           .subscribe();
       
      Type Parameters:
      T - The generic type to deserialize application/json the component into.
      Parameters:
      digitalTwinId - The Id of the digital twin to get the component from.
      componentName - The name of the component on the digital twin to retrieve.
      clazz - The class to deserialize the application/json component into.
      Returns:
      The deserialized application/json object representing the component of the digital twin.
    • getComponentWithResponse

      public <T> Mono<DigitalTwinsResponse<T>> getComponentWithResponse(String digitalTwinId, String componentName, Class<T> clazz)
      Get a component of a digital twin.

      Code Samples

       digitalTwinsAsyncClient.getComponentWithResponse(
           "myDigitalTwinId",
           "myComponentName",
           String.class)
           .subscribe(response ->
               System.out.println(
                   "Received component get operation response with HTTP status code: "
                   + response.getStatusCode()));
       
      Type Parameters:
      T - The generic type to deserialize the application/json component into.
      Parameters:
      digitalTwinId - The Id of the digital twin to get the component from.
      componentName - The name of the component on the digital twin to retrieve.
      clazz - The class to deserialize the application/json component into.
      Returns:
      A DigitalTwinsResponse containing the deserialized application/json object representing the component of the digital twin.
    • updateComponent

      public Mono<Void> updateComponent(String digitalTwinId, String componentName, JsonPatchDocument jsonPatch)
      Patch a component on a digital twin.

      Code Samples

       JsonPatchDocument jsonPatchDocument = new JsonPatchDocument();
       jsonPatchDocument.appendReplace("/ComponentProp1", "Some new value");
      
       digitalTwinsAsyncClient.updateComponent(
           "myDigitalTwinId",
           "myComponentName",
           jsonPatchDocument)
           .subscribe();
       
      Parameters:
      digitalTwinId - The Id of the digital twin that has the component to patch.
      componentName - The name of the component on the digital twin.
      jsonPatch - The JSON patch to apply to the specified digital twin's relationship. This argument can be created using JsonPatchDocument.
      Returns:
      An empty Mono.
    • updateComponentWithResponse

      public Mono<DigitalTwinsResponse<Void>> updateComponentWithResponse(String digitalTwinId, String componentName, JsonPatchDocument jsonPatch, UpdateComponentOptions options)
      Patch a component on a digital twin.

      Code Samples

       JsonPatchDocument jsonPatchDocument = new JsonPatchDocument();
       jsonPatchDocument.appendReplace("/ComponentProp1", "Some new value");
      
       digitalTwinsAsyncClient.updateComponentWithResponse(
           "myDigitalTwinId",
           "myComponentName",
           jsonPatchDocument,
           new UpdateComponentOptions().setIfMatch("*"))
           .subscribe(updateResponse ->
               System.out.println(
                   "Received update operation response with HTTP status code: "
                   + updateResponse.getStatusCode()));
       
      Parameters:
      digitalTwinId - The Id of the digital twin that has the component to patch.
      componentName - The name of the component on the digital twin.
      jsonPatch - The JSON patch to apply to the specified digital twin's relationship. This argument can be created using JsonPatchDocument.
      options - The optional parameters for this request. If null, the default option values will be used.
      Returns:
      A DigitalTwinsResponse containing an empty Mono. This response object includes an HTTP header that gives you the updated ETag for this resource.
    • query

      public <T> PagedFlux<T> query(String query, Class<T> clazz)
      Query digital twins.

      Code Samples

      A strongly typed digital twin object such as BasicDigitalTwin can be provided as the input parameter to deserialize the response into.

       digitalTwinsAsyncClient.query(
           "SELECT * FROM digitaltwins",
           BasicDigitalTwin.class)
           .doOnNext(
               basicTwin -> System.out.println("Retrieved digitalTwin query result with Id: " + basicTwin.getId()))
           .subscribe();
       

      Or alternatively String can be used as input and output deserialization type:

       digitalTwinsAsyncClient.query(
           "SELECT * FROM digitaltwins",
           String.class)
           .doOnNext(twinString -> System.out.println("Retrieved digitalTwin query result with Id: " + twinString))
           .subscribe();
       
      Note that there may be a delay between before changes in your instance are reflected in queries. For more details on query limitations, see Query limitations
      Type Parameters:
      T - The generic type to deserialize each queried digital twin into.
      Parameters:
      query - The query string, in SQL-like syntax.
      clazz - The model class to deserialize each queried digital twin into. Since the queried twins may not all have the same model class, it is recommended to use a common denominator class such as BasicDigitalTwin.
      Returns:
      A PagedFlux of deserialized digital twins.
    • query

      public <T> PagedFlux<T> query(String query, Class<T> clazz, QueryOptions options)
      Query digital twins.

      Code Samples

      A strongly typed digital twin object such as BasicDigitalTwin can be provided as the input parameter to deserialize the response into.

       digitalTwinsAsyncClient.query(
           "SELECT * FROM digitaltwins",
           BasicDigitalTwin.class,
           new QueryOptions().setMaxItemsPerPage(5))
           .doOnNext(
               basicTwin -> System.out.println("Retrieved digitalTwin query result with Id: " + basicTwin.getId()))
           .subscribe();
       

      Or alternatively String can be used as input and output deserialization type:

       digitalTwinsAsyncClient.query(
           "SELECT * FROM digitaltwins",
           String.class,
           new QueryOptions().setMaxItemsPerPage(5))
           .doOnNext(twinString -> System.out.println("Retrieved digitalTwin query result with Id: " + twinString))
           .subscribe();
       
      Note that there may be a delay between before changes in your instance are reflected in queries. For more details on query limitations, see Query limitations
      Type Parameters:
      T - The generic type to deserialize each queried digital twin into.
      Parameters:
      query - The query string, in SQL-like syntax.
      clazz - The model class to deserialize each queried digital twin into. Since the queried twins may not all have the same model class, it is recommended to use a common denominator class such as BasicDigitalTwin.
      options - The optional parameters for this request. If null, the default option values will be used.
      Returns:
      A PagedFlux of deserialized digital twins.
    • createOrReplaceEventRoute

      public Mono<Void> createOrReplaceEventRoute(String eventRouteId, DigitalTwinsEventRoute eventRoute)
      Create an event route. If the provided eventRouteId is already in use, then this will attempt to replace the existing event route with the provided event route.

      Code Samples

       String filter =
           "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'";
      
       DigitalTwinsEventRoute eventRoute = new DigitalTwinsEventRoute("myEndpointName").setFilter(filter);
       digitalTwinsAsyncClient.createOrReplaceEventRoute("myEventRouteId", eventRoute).subscribe();
       
      Parameters:
      eventRouteId - The Id of the event route to create.
      eventRoute - The event route to create.
      Returns:
      An empty mono.
    • createOrReplaceEventRouteWithResponse

      public Mono<Response<Void>> createOrReplaceEventRouteWithResponse(String eventRouteId, DigitalTwinsEventRoute eventRoute)
      Create an event route. If the provided eventRouteId is already in use, then this will attempt to replace the existing event route with the provided event route.

      Code Samples

       String filter =
           "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'";
      
       DigitalTwinsEventRoute eventRoute = new DigitalTwinsEventRoute("myEndpointName").setFilter(filter);
       digitalTwinsAsyncClient.createOrReplaceEventRouteWithResponse(
           "myEventRouteId",
           eventRoute)
           .subscribe(response ->
               System.out.println("Created an event rout with HTTP status code: " + response.getStatusCode()));
       
      Parameters:
      eventRouteId - The Id of the event route to create.
      eventRoute - The event route to create.
      Returns:
      A Response containing an empty mono.
    • getEventRoute

      public Mono<DigitalTwinsEventRoute> getEventRoute(String eventRouteId)
      Get an event route.

      Code Samples

       digitalTwinsAsyncClient.getEventRoute("myEventRouteId")
           .subscribe(eventRoute -> System.out.println("Retrieved event route with Id: " + eventRoute.getEventRouteId()));
       
      Parameters:
      eventRouteId - The Id of the event route to get.
      Returns:
      The retrieved event route.
    • getEventRouteWithResponse

      public Mono<Response<DigitalTwinsEventRoute>> getEventRouteWithResponse(String eventRouteId)
      Get an event route.

      Code Samples

       digitalTwinsAsyncClient.getEventRouteWithResponse(
           "myEventRouteId")
           .subscribe(eventRouteWithResponse -> {
               System.out.println(
                   "Received get event route operation response with HTTP status code: "
                   + eventRouteWithResponse.getStatusCode());
               System.out.println(
                   "Retrieved event route with Id: "
                   + eventRouteWithResponse.getValue().getEventRouteId());
           });
       
      Parameters:
      eventRouteId - The Id of the event route to get.
      Returns:
      A Response containing the retrieved event route.
    • deleteEventRoute

      public Mono<Void> deleteEventRoute(String eventRouteId)
      Delete an event route.

      Code Samples

       digitalTwinsAsyncClient.deleteEventRoute("myEventRouteId")
           .subscribe();
       
      Parameters:
      eventRouteId - The Id of the event route to delete.
      Returns:
      An empty mono.
    • deleteEventRouteWithResponse

      public Mono<Response<Void>> deleteEventRouteWithResponse(String eventRouteId)
      Delete an event route.

      Code Samples

       digitalTwinsAsyncClient.deleteEventRouteWithResponse(
           "myEventRouteId")
           .subscribe(deleteResponse ->
               System.out.println(
                   "Received delete event route operation response with HTTP status code: "
                   + deleteResponse.getStatusCode()));
       
      Parameters:
      eventRouteId - The Id of the event route to delete.
      Returns:
      A Response containing an empty mono.
    • listEventRoutes

      public PagedFlux<DigitalTwinsEventRoute> listEventRoutes()
      List all the event routes that exist in your digital twins instance.

      Code Samples

       digitalTwinsAsyncClient.listEventRoutes()
           .doOnNext(eventRoute -> System.out.println("Retrieved event route with Id: " + eventRoute.getEventRouteId()))
           .subscribe();
       
      Returns:
      A PagedFlux that contains all the event routes that exist in your digital twins instance. This PagedFlux may take multiple service requests to iterate over all event routes.
    • listEventRoutes

      List all the event routes that exist in your digital twins instance.

      Code Samples

       digitalTwinsAsyncClient.listEventRoutes(new ListDigitalTwinsEventRoutesOptions().setMaxItemsPerPage(5))
           .doOnNext(eventRoute -> System.out.println("Retrieved event route with Id: " + eventRoute.getEventRouteId()))
           .subscribe();
       
      Parameters:
      options - The optional parameters to use when listing event routes. See ListDigitalTwinsEventRoutesOptions for more details on what optional parameters can be set.
      Returns:
      A PagedFlux that contains all the event routes that exist in your digital twins instance. This PagedFlux may take multiple service requests to iterate over all event routes.
    • publishTelemetry

      public Mono<Void> publishTelemetry(String digitalTwinId, String messageId, Object payload)
      Publishes telemetry from a digital twin

      Code Samples

      A strongly typed object such as Hashtable can be provided as the input parameter for the telemetry payload.

       Dictionary<String, Integer> telemetryPayload = new Hashtable<>();
       telemetryPayload.put("Telemetry1", 5);
      
       digitalTwinsAsyncClient.publishTelemetry(
           "myDigitalTwinId",
           UUID.randomUUID().toString(),
           telemetryPayload)
           .subscribe();
       

      Or alternatively String can be used as input type to construct the json string telemetry payload:

       digitalTwinsAsyncClient.publishTelemetry(
           "myDigitalTwinId",
           UUID.randomUUID().toString(),
           "{\"Telemetry1\": 5}")
           .subscribe();
       
      The result is then consumed by one or many destination endpoints (subscribers) defined under DigitalTwinsEventRoute These event routes need to be set before publishing a telemetry message, in order for the telemetry message to be consumed.
      Parameters:
      digitalTwinId - The Id of the digital twin.
      messageId - A unique message identifier (within the scope of the digital twin id) that is commonly used for de-duplicating messages. Defaults to a random UUID if argument is null.
      payload - The application/json telemetry payload to be sent. payload can be a raw json string or a strongly typed object like a Dictionary.
      Returns:
      An empty mono.
    • publishTelemetryWithResponse

      public Mono<Response<Void>> publishTelemetryWithResponse(String digitalTwinId, String messageId, Object payload, PublishTelemetryOptions options)
      Publishes telemetry from a digital twin

      Code Samples

      A strongly typed object such as Hashtable can be provided as the input parameter for the telemetry payload.

       Dictionary<String, Integer> telemetryPayload = new Hashtable<>();
       telemetryPayload.put("Telemetry1", 5);
      
       digitalTwinsAsyncClient.publishTelemetryWithResponse(
           "myDigitalTwinId",
           UUID.randomUUID().toString(),
           telemetryPayload,
           new PublishTelemetryOptions().setTimestamp(OffsetDateTime.now(ZoneId.systemDefault())))
           .subscribe(responseObject ->
               System.out.println(
                   "Received publish telemetry operation response with HTTP status code: "
                   + responseObject.getStatusCode()));
       

      Or alternatively String can be used as input type to construct the json string telemetry payload:

       digitalTwinsAsyncClient.publishTelemetryWithResponse(
           "myDigitalTwinId",
           UUID.randomUUID().toString(),
           "{\"Telemetry1\": 5}",
           new PublishTelemetryOptions().setTimestamp(OffsetDateTime.now(ZoneId.systemDefault())))
           .subscribe(responseString ->
               System.out.println(
                   "Received publish telemetry operation response with HTTP status code: "
                   + responseString.getStatusCode()));
       
      The result is then consumed by one or many destination endpoints (subscribers) defined under DigitalTwinsEventRoute These event routes need to be set before publishing a telemetry message, in order for the telemetry message to be consumed.
      Parameters:
      digitalTwinId - The Id of the digital twin.
      messageId - A unique message identifier (within the scope of the digital twin id) that is commonly used for de-duplicating messages. Defaults to a random UUID if argument is null.
      payload - The application/json telemetry payload to be sent. payload can be a raw json string or a strongly typed object like a Dictionary.
      options - The optional parameters for this request. If null, the default option values will be used.
      Returns:
      A Response containing an empty mono.
    • publishComponentTelemetry

      public Mono<Void> publishComponentTelemetry(String digitalTwinId, String componentName, String messageId, Object payload)
      Publishes telemetry from a digital twin's component

      Code Samples

      A strongly typed object such as Hashtable can be provided as the input parameter for the telemetry payload.

       Dictionary<String, Integer> telemetryPayload = new Hashtable<>();
       telemetryPayload.put("Telemetry1", 5);
      
       digitalTwinsAsyncClient.publishComponentTelemetry(
           "myDigitalTwinId",
           "myComponentName",
           UUID.randomUUID().toString(),
           telemetryPayload)
           .subscribe();
       

      Or alternatively String can be used as input type to construct the json string telemetry payload:

       digitalTwinsAsyncClient.publishComponentTelemetry(
           "myDigitalTwinId",
           "myComponentName",
           UUID.randomUUID().toString(),
           "{\"Telemetry1\": 5}")
           .subscribe();
       
      The result is then consumed by one or many destination endpoints (subscribers) defined under DigitalTwinsEventRoute These event routes need to be set before publishing a telemetry message, in order for the telemetry message to be consumed.
      Parameters:
      digitalTwinId - The Id of the digital twin.
      componentName - The name of the DTDL component.
      messageId - A unique message identifier (within the scope of the digital twin id) that is commonly used for de-duplicating messages. Defaults to a random UUID if argument is null.
      payload - The application/json telemetry payload to be sent. payload can be a raw json string or a strongly typed object like a Dictionary.
      Returns:
      An empty mono.
    • publishComponentTelemetryWithResponse

      public Mono<Response<Void>> publishComponentTelemetryWithResponse(String digitalTwinId, String componentName, String messageId, Object payload, PublishComponentTelemetryOptions options)
      Publishes telemetry from a digital twin's component

      Code Samples

      A strongly typed object such as Hashtable can be provided as the input parameter for the telemetry payload.

       Dictionary<String, Integer> telemetryPayload = new Hashtable<>();
       telemetryPayload.put("Telemetry1", 5);
      
       digitalTwinsAsyncClient.publishComponentTelemetryWithResponse(
           "myDigitalTwinId",
           "myComponentName",
           UUID.randomUUID().toString(),
           telemetryPayload,
           new PublishComponentTelemetryOptions().setTimestamp(OffsetDateTime.now(ZoneId.systemDefault())))
           .subscribe(responseObject ->
               System.out.println(
                   "Received publish component telemetry operation response with HTTP status code: "
                   + responseObject.getStatusCode()));
       

      Or alternatively String can be used as input type to construct the json string telemetry payload:

       digitalTwinsAsyncClient.publishComponentTelemetryWithResponse(
           "myDigitalTwinId",
           "myComponentName",
           UUID.randomUUID().toString(),
           "{\"Telemetry1\": 5}",
           new PublishComponentTelemetryOptions().setTimestamp(OffsetDateTime.now(ZoneId.systemDefault())))
           .subscribe(responseString ->
               System.out.println(
                   "Received publish component telemetry operation response with HTTP status code: "
                   + responseString.getStatusCode()));
       
      The result is then consumed by one or many destination endpoints (subscribers) defined under DigitalTwinsEventRoute These event routes need to be set before publishing a telemetry message, in order for the telemetry message to be consumed.
      Parameters:
      digitalTwinId - The Id of the digital twin.
      componentName - The name of the DTDL component.
      messageId - A unique message identifier (within the scope of the digital twin id) that is commonly used for de-duplicating messages. Defaults to a random UUID if argument is null.
      payload - The application/json telemetry payload to be sent. payload can be a raw json string or a strongly typed object like a Dictionary.
      options - The optional parameters for this request. If null, the default option values will be used.
      Returns:
      A Response containing an empty mono.