Class DigitalTwinsClient
DigitalTwinsClientBuilder
.
Code Samples
DigitalTwinsClient digitalTwinsSyncClient = new DigitalTwinsClientBuilder() .credential( new ClientSecretCredentialBuilder() .tenantId(tenantId) .clientId(clientId) .clientSecret(clientSecret) .build()) .endpoint(digitalTwinsEndpointUrl) .buildClient();
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 Summary
Modifier and TypeMethodDescriptioncreateModels
(Iterable<String> dtdlModels) Creates one or many models.createModelsWithResponse
(Iterable<String> dtdlModels, Context context) Creates one or many models.<T> T
createOrReplaceDigitalTwin
(String digitalTwinId, T digitalTwin, Class<T> clazz) Creates a digital twin.<T> Response<T>
createOrReplaceDigitalTwinWithResponse
(String digitalTwinId, T digitalTwin, Class<T> clazz, CreateOrReplaceDigitalTwinOptions options, Context context) Creates a digital twin.void
createOrReplaceEventRoute
(String eventRouteId, DigitalTwinsEventRoute eventRoute) Create an event route.createOrReplaceEventRouteWithResponse
(String eventRouteId, DigitalTwinsEventRoute eventRoute, Context context) Create an event route.<T> T
createOrReplaceRelationship
(String digitalTwinId, String relationshipId, T relationship, Class<T> clazz) Creates a relationship on a digital twin.<T> DigitalTwinsResponse<T>
createOrReplaceRelationshipWithResponse
(String digitalTwinId, String relationshipId, T relationship, Class<T> clazz, CreateOrReplaceRelationshipOptions options, Context context) Creates a relationship on a digital twin.void
decommissionModel
(String modelId) Decommissions a model.decommissionModelWithResponse
(String modelId, Context context) Decommissions a model.void
deleteDigitalTwin
(String digitalTwinId) Deletes a digital twin.deleteDigitalTwinWithResponse
(String digitalTwinId, DeleteDigitalTwinOptions options, Context context) Deletes a digital twin.void
deleteEventRoute
(String eventRouteId) Delete an event route.deleteEventRouteWithResponse
(String eventRouteId, Context context) Delete an event route.void
deleteModel
(String modelId) Deletes a model.deleteModelWithResponse
(String modelId, Context context) Deletes a model.void
deleteRelationship
(String digitalTwinId, String relationshipId) Deletes a relationship on a digital twin.deleteRelationshipWithResponse
(String digitalTwinId, String relationshipId, DeleteRelationshipOptions options, Context context) Deletes a relationship on a digital twin.<T> T
getComponent
(String digitalTwinId, String componentName, Class<T> clazz) Get a component of a digital twin.<T> DigitalTwinsResponse<T>
getComponentWithResponse
(String digitalTwinId, String componentName, Class<T> clazz, Context context) Get a component of a digital twin.<T> T
getDigitalTwin
(String digitalTwinId, Class<T> clazz) Gets a digital twin.<T> DigitalTwinsResponse<T>
getDigitalTwinWithResponse
(String digitalTwinId, Class<T> clazz, Context context) Gets a digital twin.getEventRoute
(String eventRouteId) Get an event route.getEventRouteWithResponse
(String eventRouteId, Context context) Get an event route.Gets a model, including the model metadata and the model definition.getModelWithResponse
(String modelId, Context context) Gets a model, including the model metadata and the model definition.<T> T
getRelationship
(String digitalTwinId, String relationshipId, Class<T> clazz) Gets a relationship on a digital twin.<T> DigitalTwinsResponse<T>
getRelationshipWithResponse
(String digitalTwinId, String relationshipId, Class<T> clazz, Context context) Gets a relationship on a digital twin.Gets the Azure Digital Twins service API version that this client is configured to use for all service requests.List all the event routes that exist in your digital twins instance.listEventRoutes
(ListDigitalTwinsEventRoutesOptions options, Context context) List all the event routes that exist in your digital twins instance.listIncomingRelationships
(String digitalTwinId) List the relationships that have a given digital twin as the target.listIncomingRelationships
(String digitalTwinId, Context context) List the relationships that have a given digital twin as the target.List all of the models in this digital twins instance.listModels
(ListModelsOptions options, Context context) List the models in this digital twins instance based on some options.<T> PagedIterable<T>
listRelationships
(String digitalTwinId, Class<T> clazz) List the relationships that have a given digital twin as the source.<T> PagedIterable<T>
listRelationships
(String digitalTwinId, String relationshipName, Class<T> clazz, Context context) List the relationships that have a given digital twin as the source and that have the given relationship name.void
publishComponentTelemetry
(String digitalTwinId, String componentName, String messageId, Object payload) Publishes telemetry from a digital twin's componentpublishComponentTelemetryWithResponse
(String digitalTwinId, String componentName, String messageId, Object payload, PublishComponentTelemetryOptions options, Context context) Publishes telemetry from a digital twin's componentvoid
publishTelemetry
(String digitalTwinId, String messageId, Object payload) Publishes telemetry from a digital twinpublishTelemetryWithResponse
(String digitalTwinId, String messageId, Object payload, PublishTelemetryOptions options, Context context) Publishes telemetry from a digital twin<T> PagedIterable<T>
Query digital twins.<T> PagedIterable<T>
query
(String query, Class<T> clazz, QueryOptions options, Context context) Query digital twins.void
updateComponent
(String digitalTwinId, String componentName, JsonPatchDocument jsonPatch) Patch a component on a digital twin.updateComponentWithResponse
(String digitalTwinId, String componentName, JsonPatchDocument jsonPatch, UpdateComponentOptions options, Context context) Patch a component on a digital twin.void
updateDigitalTwin
(String digitalTwinId, JsonPatchDocument jsonPatch) Updates a digital twin.updateDigitalTwinWithResponse
(String digitalTwinId, JsonPatchDocument jsonPatch, UpdateDigitalTwinOptions options, Context context) Updates a digital twin.void
updateRelationship
(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch) Updates the properties of a relationship on a digital twin.updateRelationshipWithResponse
(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch, UpdateRelationshipOptions options, Context context) Updates the properties of a relationship on a digital twin.
-
Method Details
-
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 throughDigitalTwinsClientBuilder.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
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
A strongly typed digital twin object such as
BasicDigitalTwin
can be provided as the input parameter:String modelId = "dtmi:com:samples:Building;1"; BasicDigitalTwin basicTwin = new BasicDigitalTwin("myDigitalTwinId") .setMetadata( new BasicDigitalTwinMetadata() .setModelId(modelId) ); BasicDigitalTwin createdTwin = digitalTwinsClient.createOrReplaceDigitalTwin( basicTwin.getId(), basicTwin, BasicDigitalTwin.class); System.out.println("Created digital twin with Id: " + createdTwin.getId());
Or alternatively String can be used as input and output type:
String stringResult = digitalTwinsClient.createOrReplaceDigitalTwin( "myDigitalTwinId", digitalTwinStringPayload, String.class); System.out.println("Created digital twin: " + stringResult);
- 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.clazz
- The model class to serialize the request with and deserialize the response with.digitalTwin
- The application/json object representing the digital twin to create.- Returns:
- The deserialized application/json object representing the digital twin created.
-
createOrReplaceDigitalTwinWithResponse
public <T> Response<T> createOrReplaceDigitalTwinWithResponse(String digitalTwinId, T digitalTwin, Class<T> clazz, CreateOrReplaceDigitalTwinOptions options, Context context) 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
A strongly typed digital twin object type such as
BasicDigitalTwin
can be provided as the input parameter:String modelId = "dtmi:com:samples:Building;1"; BasicDigitalTwin basicDigitalTwin = new BasicDigitalTwin("myDigitalTwinId") .setMetadata( new BasicDigitalTwinMetadata() .setModelId(modelId) ); Response<BasicDigitalTwin> resultWithResponse = digitalTwinsClient.createOrReplaceDigitalTwinWithResponse( basicDigitalTwin.getId(), basicDigitalTwin, BasicDigitalTwin.class, new CreateOrReplaceDigitalTwinOptions(), new Context("Key", "Value")); 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 type:
String stringResult = digitalTwinsClient.createOrReplaceDigitalTwin( "myDigitalTwinId", digitalTwinStringPayload, String.class); System.out.println("Created digital twin: " + stringResult);
- 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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
DigitalTwinsResponse
containing the deserialized application/json object representing the digital twin created.
-
getDigitalTwin
Gets a digital twin.Code Samples
A Strongly typed object type such as
BasicDigitalTwin
can be provided as an input parameter forclazz
to indicate what type is used to deserialize the response.BasicDigitalTwin basicTwinResult = digitalTwinsClient.getDigitalTwin( "myDigitalTwinId", BasicDigitalTwin.class); System.out.println("Retrieved digital twin with Id: " + basicTwinResult.getId());
Alternatively String can be used to get the response in a json string format.
String stringResult = digitalTwinsClient.getDigitalTwin("myDigitalTwinId", String.class); 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> DigitalTwinsResponse<T> getDigitalTwinWithResponse(String digitalTwinId, Class<T> clazz, Context context) Gets a digital twin.Code Samples
A Strongly typed object type such as
BasicDigitalTwin
can be provided as an input parameter forclazz
to indicate what type is used to deserialize the response.Response<BasicDigitalTwin> basicTwinResultWithResponse = digitalTwinsClient.getDigitalTwinWithResponse( "myDigitalTwinId", BasicDigitalTwin.class, new Context("key", "value")); System.out.println("Http status code: " + basicTwinResultWithResponse.getStatusCode()); System.out.println("Retrieved digital twin with Id: " + basicTwinResultWithResponse.getValue().getId());
Alternatively String can be used to get the response in a json string format.
Response<String> stringResultWithResponse = digitalTwinsClient.getDigitalTwinWithResponse( "myDigitalTwinId", String.class, new Context("key", "value")); System.out.println("Http response status: " + stringResultWithResponse.getStatusCode()); System.out.println("Retrieved digital twin: " + stringResultWithResponse.getValue());
- 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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
DigitalTwinsResponse
containing the deserialized application/json object representing the digital twin.
-
updateDigitalTwin
Updates a digital twin.Code Samples
Update digital twin by providing list of intended patch operations.
JsonPatchDocument jsonPatchDocument = new JsonPatchDocument(); jsonPatchDocument.appendReplace("Prop1", "newValue"); digitalTwinsClient.updateDigitalTwin( "myDigitalTwinId", jsonPatchDocument);
- 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 usingJsonPatchDocument
.
-
updateDigitalTwinWithResponse
public DigitalTwinsResponse<Void> updateDigitalTwinWithResponse(String digitalTwinId, JsonPatchDocument jsonPatch, UpdateDigitalTwinOptions options, Context context) Updates a digital twin.Code Samples
Update digital twin by providing list of intended patch operations.
JsonPatchDocument jsonPatchDocument = new JsonPatchDocument(); jsonPatchDocument.appendReplace("Prop1", "newValue"); Response<Void> response = digitalTwinsClient.updateDigitalTwinWithResponse( "myDigitalTwinId", jsonPatchDocument, new UpdateDigitalTwinOptions(), new Context("key", "value")); System.out.println("Update completed with HTTP status code: " + response.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 usingJsonPatchDocument
.options
- The optional parameters for this request. If null, the default option values will be used.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
DigitalTwinsResponse
. This response object includes an HTTP header that gives you the updated ETag for this resource.
-
deleteDigitalTwin
Deletes a digital twin. All relationships referencing the digital twin must already be deleted.Code Samples
digitalTwinsClient.deleteDigitalTwin("myDigitalTwinId");
- Parameters:
digitalTwinId
- The Id of the digital twin. The Id is unique within the service and case sensitive.
-
deleteDigitalTwinWithResponse
public Response<Void> deleteDigitalTwinWithResponse(String digitalTwinId, DeleteDigitalTwinOptions options, Context context) Deletes a digital twin. All relationships referencing the digital twin must already be deleted.Code Samples
Response<Void> response = digitalTwinsClient.deleteDigitalTwinWithResponse( "myDigitalTwinId", new DeleteDigitalTwinOptions(), new Context("key", "value")); System.out.println("Deleted digital twin HTTP response status code: " + response.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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The Http response.
-
createOrReplaceRelationship
public <T> 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); BasicRelationship createdRelationship = digitalTwinsSyncClient.createOrReplaceRelationship( "mySourceDigitalTwinId", "myRelationshipId", buildingToFloorBasicRelationship, BasicRelationship.class); 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(); String createdRelationshipString = digitalTwinsSyncClient.createOrReplaceRelationship( "mySourceDigitalTwinId", "myRelationshipId", relationshipPayload, String.class); System.out.println("Created relationship: " + createdRelationshipString);
- 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 application/json object representing the relationship to be created.clazz
- The model class of the relationship.- Returns:
- The relationship created.
-
createOrReplaceRelationshipWithResponse
public <T> DigitalTwinsResponse<T> createOrReplaceRelationshipWithResponse(String digitalTwinId, String relationshipId, T relationship, Class<T> clazz, CreateOrReplaceRelationshipOptions options, Context context) 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); Response<BasicRelationship> createdRelationshipWithResponse = digitalTwinsSyncClient.createOrReplaceRelationshipWithResponse( "mySourceDigitalTwinId", "myRelationshipId", buildingToFloorBasicRelationship, BasicRelationship.class, new CreateOrReplaceRelationshipOptions(), new Context("key", "value")); 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(); Response<String> createdRelationshipStringWithResponse = digitalTwinsSyncClient.createOrReplaceRelationshipWithResponse( "mySourceDigitalTwinId", "myRelationshipId", relationshipPayload, String.class, new CreateOrReplaceRelationshipOptions(), new Context("key", "value")); 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 application/json object representing 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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
DigitalTwinsResponse
containing the relationship created.
-
getRelationship
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.BasicRelationship retrievedRelationship = digitalTwinsSyncClient.getRelationship( "myDigitalTwinId", "myRelationshipName", BasicRelationship.class); 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:
String retrievedRelationshipString = digitalTwinsSyncClient.getRelationship( "myDigitalTwinId", "myRelationshipName", String.class); 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> DigitalTwinsResponse<T> getRelationshipWithResponse(String digitalTwinId, String relationshipId, Class<T> clazz, Context context) 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.Response<BasicRelationship> retrievedRelationshipWithResponse = digitalTwinsSyncClient.getRelationshipWithResponse( "myDigitalTwinId", "myRelationshipName", BasicRelationship.class, new Context("key", "value")); 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:
Response<String> retrievedRelationshipString = digitalTwinsSyncClient.getRelationshipWithResponse( "myDigitalTwinId", "myRelationshipName", String.class, new Context("key", "value")); System.out.println( "Retrieved relationship: " + retrievedRelationshipString + " HTTP status code: " + retrievedRelationshipString.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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
DigitalTwinsResponse
containing the deserialized relationship.
-
updateRelationship
public 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"); digitalTwinsSyncClient.updateRelationship( "myDigitalTwinId", "myRelationshipId", jsonPatchDocument);
- 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 usingJsonPatchDocument
.
-
updateRelationshipWithResponse
public DigitalTwinsResponse<Void> updateRelationshipWithResponse(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch, UpdateRelationshipOptions options, Context context) Updates the properties of a relationship on a digital twin.Code Samples
JsonPatchDocument jsonPatchDocument = new JsonPatchDocument(); jsonPatchDocument.appendReplace("/relationshipProperty1", "new property value"); Response<Void> updateResponse = digitalTwinsSyncClient.updateRelationshipWithResponse( "myDigitalTwinId", "myRelationshipId", jsonPatchDocument, new UpdateRelationshipOptions(), new Context("key", "value")); 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 usingJsonPatchDocument
.options
- The optional parameters for this request. If null, the default option values will be used.context
- Additional context that is passed through the Http pipeline during the service call.- 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
Deletes a relationship on a digital twin.Code Samples
digitalTwinsSyncClient.deleteRelationship("myDigitalTwinId", "myRelationshipId");
- Parameters:
digitalTwinId
- The Id of the source digital twin.relationshipId
- The Id of the relationship to delete.
-
deleteRelationshipWithResponse
public Response<Void> deleteRelationshipWithResponse(String digitalTwinId, String relationshipId, DeleteRelationshipOptions options, Context context) Deletes a relationship on a digital twin.Code Samples
Response<Void> deleteResponse = digitalTwinsSyncClient.deleteRelationshipWithResponse( "myDigitalTwinId", "myRelationshipId", new DeleteRelationshipOptions(), new Context("key", "value")); 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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
containing no parsed payload object.
-
listRelationships
List the relationships that have a given digital twin as the source.Code Samples
A strongly typed digital twin object such as
BasicRelationship
can be provided as the input parameter to deserialize the response into.PagedIterable<BasicRelationship> pagedRelationshipsByItem = digitalTwinsSyncClient.listRelationships( "myDigitalTwinId", BasicRelationship.class); for (BasicRelationship rel : pagedRelationshipsByItem) { System.out.println("Retrieved relationship with Id: " + rel.getId()); }
Or alternatively String can be used as input and output deserialization type:
PagedIterable<String> pagedRelationshipsStringByItem = digitalTwinsSyncClient.listRelationships( "myDigitalTwinId", String.class); for (String rel : pagedRelationshipsStringByItem) { System.out.println("Retrieved relationship: " + rel); }
- Type Parameters:
T
- The generic type to deserialize each relationship into.- Parameters:
digitalTwinId
- The Id of the source digital twin.clazz
- The model class to deserialize each relationship into. Since a digital twin might have relationships that conform to different models, it is advisable to convert them to a generic model likeBasicRelationship
.- Returns:
- A
PagedIterable
of relationships belonging to the specified digital twin.
-
listRelationships
public <T> PagedIterable<T> listRelationships(String digitalTwinId, String relationshipName, Class<T> clazz, Context context) List the relationships that have a given digital twin as the source and that have the given relationship name.Code Samples
A strongly typed digital twin object such as
BasicRelationship
can be provided as the input parameter to deserialize the response into.PagedIterable<BasicRelationship> pagedRelationshipByNameByItem = digitalTwinsSyncClient.listRelationships( "myDigitalTwinId", "myRelationshipName", BasicRelationship.class, new Context("Key", "value")); for (BasicRelationship rel : pagedRelationshipByNameByItem) { System.out.println("Retrieved relationship with Id: " + rel.getId()); }
Or alternatively String can be used as input and output deserialization type:
PagedIterable<String> pagedRelationshipsStringByNameByItem = digitalTwinsSyncClient.listRelationships( "myDigitalTwinId", "myRelationshipId", String.class, new Context("key", "value")); for (String rel : pagedRelationshipsStringByNameByItem) { System.out.println("Retrieved relationship: " + rel); }
- Type Parameters:
T
- The generic type to deserialize each relationship into.- Parameters:
digitalTwinId
- The Id of the source digital twin.relationshipName
- The name of a relationship to filter to.clazz
- The model class to deserialize each relationship into. Since a digital twin might have relationships that conform to different models, it is advisable to convert them to a generic model likeBasicRelationship
.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
PagedIterable
of relationships belonging to the specified digital twin.
-
listIncomingRelationships
List the relationships that have a given digital twin as the target.Code Samples
PagedIterable<IncomingRelationship> pagedIncomingRelationships = digitalTwinsSyncClient.listIncomingRelationships( "myDigitalTwinId", new Context("key", "value")); for (IncomingRelationship rel : pagedIncomingRelationships) { System.out.println( "Retrieved relationship with Id: " + rel.getRelationshipId() + " from: " + rel.getSourceId() + " to: myDigitalTwinId"); }
- Parameters:
digitalTwinId
- The Id of the target digital twin.- Returns:
- A
PagedIterable
of application/json strings representing the relationships directed towards the specified digital twin.
-
listIncomingRelationships
public PagedIterable<IncomingRelationship> listIncomingRelationships(String digitalTwinId, Context context) List the relationships that have a given digital twin as the target.Code Samples
PagedIterable<IncomingRelationship> pagedIncomingRelationshipsWithContext = digitalTwinsSyncClient.listIncomingRelationships( "myDigitalTwinId", new Context("key", "value")); for (IncomingRelationship rel : pagedIncomingRelationshipsWithContext) { System.out.println( "Retrieved relationship with Id: " + rel.getRelationshipId() + " from: " + rel.getSourceId() + " to: myDigitalTwinId"); }
- Parameters:
digitalTwinId
- The Id of the target digital twin.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
PagedIterable
of application/json strings representing the relationships directed towards the specified digital twin.
-
createModels
Creates one or many models.Code Samples
Iterable<DigitalTwinsModelData> createdModels = digitalTwinsSyncClient.createModels( Arrays.asList(model1, model2, model3)); 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 Response<Iterable<DigitalTwinsModelData>> createModelsWithResponse(Iterable<String> dtdlModels, Context context) Creates one or many models.Code Samples
Response<Iterable<DigitalTwinsModelData>> createdModels = digitalTwinsSyncClient.createModelsWithResponse( Arrays.asList(model1, model2, model3), new Context("key", "value")); System.out.println("Received HTTP response of " + 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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
containing the list of created models. EachDigitalTwinsModelData
instance in this list will contain metadata about the created model, but will not contain the model itself.
-
getModel
Gets a model, including the model metadata and the model definition.Code Samples
DigitalTwinsModelData model = digitalTwinsSyncClient.getModel("dtmi:com:samples:Building;1"); 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
Gets a model, including the model metadata and the model definition.Code Samples
Response<DigitalTwinsModelData> modelWithResponse = digitalTwinsSyncClient.getModelWithResponse( "dtmi:com:samples:Building;1", new Context("key", "value")); 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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
containing aDigitalTwinsModelData
instance that contains the model and its metadata.
-
listModels
List all of the models in this digital twins instance.Code Samples
PagedIterable<DigitalTwinsModelData> modelsListPagedIterable = digitalTwinsSyncClient.listModels(); modelsListPagedIterable.forEach(model -> System.out.println("Retrieved a model with Id: " + model.getModelId()));
- Returns:
- A
PagedFlux
ofDigitalTwinsModelData
that enumerates all the models.
-
listModels
List the models in this digital twins instance based on some options.Code Samples
PagedIterable<DigitalTwinsModelData> modelsListWithOptionsPagedIterable = digitalTwinsSyncClient.listModels( new ListModelsOptions() .setIncludeModelDefinition(true) .setMaxItemsPerPage(5), new Context("key", "value")); modelsListWithOptionsPagedIterable.forEach( model -> System.out.println("Retrieved a model with Id: " + model.getModelId()));
- Parameters:
options
- The optional parameters for this request. If null, the default option values will be used.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
PagedIterable
containing the retrievedDigitalTwinsModelData
instances.
-
deleteModel
Deletes a model.Code Samples
digitalTwinsSyncClient.deleteModel("dtmi:com:samples:Building;1");
- Parameters:
modelId
- The Id for the model. The Id is globally unique and case sensitive.
-
deleteModelWithResponse
Deletes a model.Code Samples
Response<Void> response = digitalTwinsSyncClient.deleteModelWithResponse( "dtmi:com:samples:Building;1", new Context("key", "value")); System.out.println("Received delete model operation HTTP response with status: " + response.getStatusCode());
- Parameters:
modelId
- The Id for the model. The Id is globally unique and case sensitive.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
with no parsed payload object.
-
decommissionModel
Decommissions a model.Code Samples
digitalTwinsSyncClient.decommissionModel("dtmi:com:samples:Building;1");
- Parameters:
modelId
- The Id of the model to decommission.
-
decommissionModelWithResponse
Decommissions a model.Code Samples
Response<Void> response = digitalTwinsSyncClient.decommissionModelWithResponse( "dtmi:com:samples:Building;1", new Context("key", "value")); System.out.println("Received decommission operation HTTP response with status: " + response.getStatusCode());
- Parameters:
modelId
- The Id of the model to decommission.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
with no parsed payload object.
-
getComponent
Get a component of a digital twin.Code Samples
String componentString = digitalTwinsSyncClient.getComponent( "myDigitalTwinId", "myComponentName", String.class); System.out.println("Retrieved component: " + componentString);
- 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:
- The deserialized application/json object representing the component of the digital twin.
-
getComponentWithResponse
public <T> DigitalTwinsResponse<T> getComponentWithResponse(String digitalTwinId, String componentName, Class<T> clazz, Context context) Get a component of a digital twin.Code Samples
Response<String> componentStringWithResponse = digitalTwinsSyncClient.getComponentWithResponse( "myDigitalTwinId", "myComponentName", String.class, new Context("key", "value")); System.out.println( "Received component get operation response with HTTP status code: " + componentStringWithResponse.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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
DigitalTwinsResponse
containing the deserialized application/json object representing the component of the digital twin.
-
updateComponent
public 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"); digitalTwinsSyncClient.updateComponent( "myDigitalTwinId", "myComponentName", jsonPatchDocument);
- 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 usingJsonPatchDocument
.
-
updateComponentWithResponse
public DigitalTwinsResponse<Void> updateComponentWithResponse(String digitalTwinId, String componentName, JsonPatchDocument jsonPatch, UpdateComponentOptions options, Context context) Patch a component on a digital twin.Code Samples
JsonPatchDocument jsonPatchDocument = new JsonPatchDocument(); jsonPatchDocument.appendReplace("/ComponentProp1", "Some new value"); Response<Void> updateResponse = digitalTwinsSyncClient.updateComponentWithResponse( "myDigitalTwinId", "myComponentName", jsonPatchDocument, new UpdateComponentOptions(), new Context("key", "value")); System.out.println( "Received update operation HTTP response with status: " + 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 usingJsonPatchDocument
.options
- The optional parameters for this request. If null, the default option values will be used.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
DigitalTwinsResponse
containing no parsed payload object. This response object includes an HTTP header that gives you the updated ETag for this resource.
-
query
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.PagedIterable<BasicDigitalTwin> queryResultBasicDigitalTwin = digitalTwinsSyncClient.query( "SELECT * FROM digitaltwins", BasicDigitalTwin.class); queryResultBasicDigitalTwin.forEach(basicTwin -> System.out.println( "Retrieved digitalTwin query result with Id: " + basicTwin.getId()));
Or alternatively String can be used as input and output deserialization type:
PagedIterable<String> queryResultString = digitalTwinsSyncClient.query( "SELECT * FROM digitaltwins", String.class); queryResultString.forEach( queryResult -> System.out.println("Retrieved digitalTwin query result: " + queryResult));
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 asBasicDigitalTwin
.- Returns:
- A
PagedIterable
of deserialized digital twins.
-
query
public <T> PagedIterable<T> query(String query, Class<T> clazz, QueryOptions options, Context context) 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.PagedIterable<BasicDigitalTwin> queryResultBasicDigitalTwinWithContext = digitalTwinsSyncClient.query( "SELECT * FROM digitaltwins", BasicDigitalTwin.class, new QueryOptions(), new Context("key", "value")); queryResultBasicDigitalTwinWithContext .forEach(basicTwin -> System.out.println("Retrieved digitalTwin query result with Id: " + basicTwin.getId()));
Or alternatively String can be used as input and output deserialization type:
PagedIterable<String> queryResultStringWithContext = digitalTwinsSyncClient.query( "SELECT * FROM digitaltwins", String.class, new QueryOptions(), new Context("key", "value")); queryResultStringWithContext .forEach(queryResult -> System.out.println("Retrieved digitalTwin query result: " + queryResult));
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 asBasicDigitalTwin
.options
- The optional parameters for this request. If null, the default option values will be used.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
PagedIterable
of deserialized digital twins.
-
createOrReplaceEventRoute
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); digitalTwinsSyncClient.createOrReplaceEventRoute("myEventRouteId", eventRoute);
- Parameters:
eventRouteId
- The id of the event route to create.eventRoute
- The event route to create.
-
createOrReplaceEventRouteWithResponse
public Response<Void> createOrReplaceEventRouteWithResponse(String eventRouteId, DigitalTwinsEventRoute eventRoute, Context context) 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); Response<Void> response = digitalTwinsSyncClient.createOrReplaceEventRouteWithResponse( "myEventRouteId", eventRoute, new Context("key", "value")); 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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
.
-
getEventRoute
Get an event route.Code Samples
DigitalTwinsEventRoute eventRoute = digitalTwinsSyncClient.getEventRoute("myEventRouteId"); 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 Response<DigitalTwinsEventRoute> getEventRouteWithResponse(String eventRouteId, Context context) Get an event route.Code Samples
Response<DigitalTwinsEventRoute> eventRouteWithResponse = digitalTwinsSyncClient.getEventRouteWithResponse( "myEventRouteId", new Context("key", "value")); 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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
containing the retrieved event route.
-
deleteEventRoute
Delete an event route.Code Samples
digitalTwinsSyncClient.deleteEventRoute("myEventRouteId");
- Parameters:
eventRouteId
- The Id of the event route to delete.
-
deleteEventRouteWithResponse
Delete an event route.Code Samples
Response<Void> deleteResponse = digitalTwinsSyncClient.deleteEventRouteWithResponse( "myEventRouteId", new Context("key", "value")); 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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
containing no parsed value.
-
listEventRoutes
List all the event routes that exist in your digital twins instance.Code Samples
PagedIterable<DigitalTwinsEventRoute> listResponse = digitalTwinsSyncClient.listEventRoutes(); listResponse.forEach( eventRoute -> System.out.println("Retrieved event route with Id: " + eventRoute.getEventRouteId()));
- Returns:
- A
PagedIterable
containing all the event routes that exist in your digital twins instance. This PagedIterable may take multiple service requests to iterate over all event routes.
-
listEventRoutes
public PagedIterable<DigitalTwinsEventRoute> listEventRoutes(ListDigitalTwinsEventRoutesOptions options, Context context) List all the event routes that exist in your digital twins instance.Code Samples
PagedIterable<DigitalTwinsEventRoute> listResponseWithOptions = digitalTwinsSyncClient.listEventRoutes( new ListDigitalTwinsEventRoutesOptions().setMaxItemsPerPage(5), new Context("key", "value")); listResponseWithOptions .forEach( eventRoute -> System.out.println("Retrieved event route with Id: " + eventRoute.getEventRouteId()));
- Parameters:
options
- The optional parameters for this request. If null, the default option values will be used.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
PagedIterable
containing all the event routes that exist in your digital twins instance. This PagedIterable may take multiple service requests to iterate over all event routes.
-
publishTelemetry
Publishes telemetry from a digital twinCode 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); digitalTwinsSyncClient.publishTelemetry( "myDigitalTwinId", UUID.randomUUID().toString(), telemetryPayload);
Or alternatively String can be used as input type to construct the json string telemetry payload:
digitalTwinsSyncClient.publishTelemetry( "myDigitalTwinId", UUID.randomUUID().toString(), "{\"Telemetry1\": 5}");
The result is then consumed by one or many destination endpoints (subscribers) defined underDigitalTwinsEventRoute
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.
-
publishTelemetryWithResponse
public Response<Void> publishTelemetryWithResponse(String digitalTwinId, String messageId, Object payload, PublishTelemetryOptions options, Context context) Publishes telemetry from a digital twinCode 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); Response<Void> responseObject = digitalTwinsSyncClient.publishTelemetryWithResponse( "myDigitalTwinId", UUID.randomUUID().toString(), telemetryPayload, new PublishTelemetryOptions().setTimestamp(OffsetDateTime.now(ZoneId.systemDefault())), new Context("key", "value")); 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:
Response<Void> responseString = digitalTwinsSyncClient.publishTelemetryWithResponse( "myDigitalTwinId", UUID.randomUUID().toString(), "{\"Telemetry1\": 5}", new PublishTelemetryOptions().setTimestamp(OffsetDateTime.now(ZoneId.systemDefault())), new Context("key", "value")); 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 underDigitalTwinsEventRoute
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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
.
-
publishComponentTelemetry
public void publishComponentTelemetry(String digitalTwinId, String componentName, String messageId, Object payload) Publishes telemetry from a digital twin's componentCode 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); digitalTwinsSyncClient.publishComponentTelemetry( "myDigitalTwinId", "myComponentName", UUID.randomUUID().toString(), telemetryPayload);
Or alternatively String can be used as input type to construct the json string telemetry payload:
digitalTwinsSyncClient.publishComponentTelemetry( "myDigitalTwinId", "myComponentName", UUID.randomUUID().toString(), "{\"Telemetry1\": 5}");
The result is then consumed by one or many destination endpoints (subscribers) defined underDigitalTwinsEventRoute
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.
-
publishComponentTelemetryWithResponse
public Response<Void> publishComponentTelemetryWithResponse(String digitalTwinId, String componentName, String messageId, Object payload, PublishComponentTelemetryOptions options, Context context) Publishes telemetry from a digital twin's componentCode 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); Response<Void> responseObject = digitalTwinsSyncClient.publishComponentTelemetryWithResponse( "myDigitalTwinId", "myComponentName", UUID.randomUUID().toString(), telemetryPayload, new PublishComponentTelemetryOptions().setTimestamp(OffsetDateTime.now(ZoneId.systemDefault())), new Context("key", "value")); 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:
Response<Void> responseString = digitalTwinsSyncClient.publishComponentTelemetryWithResponse( "myDigitalTwinId", "myComponentName", UUID.randomUUID().toString(), "{\"Telemetry1\": 5}", new PublishComponentTelemetryOptions().setTimestamp(OffsetDateTime.now(ZoneId.systemDefault())), new Context("key", "value")); 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 underDigitalTwinsEventRoute
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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
.
-