DigitalTwinsAsyncClient Class
- java.
lang. Object - com.
azure. digitaltwins. core. DigitalTwinsAsyncClient
- com.
public final class DigitalTwinsAsyncClient
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 Summary
Methods inherited from java.lang.Object
Method Details
createOrReplaceDigitalTwin
public Mono
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));
Parameters:
Returns:
createOrReplaceDigitalTwinWithResponse
public Mono<>
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()));
Parameters:
Returns:
createOrReplaceRelationship
public Mono
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));
Parameters:
Returns:
createOrReplaceRelationshipWithResponse
public Mono<>
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()));
Parameters:
Returns:
getComponent
public Mono
Get a component of a digital twin.
Code Samples
digitalTwinsAsyncClient.getComponent(
"myDigitalTwinId",
"myComponentName",
String.class)
.subscribe();
Parameters:
Returns:
getComponentWithResponse
public Mono<>
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()));
Parameters:
Returns:
getDigitalTwin
public Mono
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));
Parameters:
Returns:
getDigitalTwinWithResponse
public Mono<>
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()));
Parameters:
Returns:
getRelationship
public Mono
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));
Parameters:
Returns:
getRelationshipWithResponse
public Mono<>
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()));
Parameters:
Returns:
listRelationships
public PagedFlux
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));
Parameters:
Returns:
listRelationships
public PagedFlux
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));
Parameters:
Returns:
query
public PagedFlux
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
Parameters:
Returns:
query
public PagedFlux
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
Parameters:
Returns:
createModels
public Mono<>
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:
Returns:
createModelsWithResponse
public Mono<><>
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:
Returns:
createOrReplaceEventRoute
public Mono
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:
Returns:
createOrReplaceEventRouteWithResponse
public Mono<>
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:
Returns:
decommissionModel
public Mono
Decommissions a model.
Code Samples
digitalTwinsAsyncClient.decommissionModel("dtmi:com:samples:Building;1")
.subscribe();
Parameters:
Returns:
decommissionModelWithResponse
public Mono<>
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:
Returns:
deleteDigitalTwin
public Mono
Deletes a digital twin. All relationships referencing the digital twin must already be deleted.
Code Samples
digitalTwinsAsyncClient.deleteDigitalTwin("myDigitalTwinId")
.subscribe();
Parameters:
Returns:
deleteDigitalTwinWithResponse
public Mono<>
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:
Returns:
deleteEventRoute
public Mono
Delete an event route.
Code Samples
digitalTwinsAsyncClient.deleteEventRoute("myEventRouteId")
.subscribe();
Parameters:
Returns:
deleteEventRouteWithResponse
public Mono<>
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:
Returns:
deleteModel
public Mono
Deletes a model.
Code Samples
digitalTwinsAsyncClient.deleteModel("dtmi:com:samples:Building;1")
.subscribe();
Parameters:
Returns:
deleteModelWithResponse
public Mono<>
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:
Returns:
deleteRelationship
public Mono
Deletes a relationship on a digital twin.
Code Samples
digitalTwinsAsyncClient.deleteRelationship("myDigitalTwinId", "myRelationshipId")
.subscribe();
Parameters:
Returns:
deleteRelationshipWithResponse
public Mono<>
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:
Returns:
getEventRoute
public Mono
Get an event route.
Code Samples
digitalTwinsAsyncClient.getEventRoute("myEventRouteId")
.subscribe(eventRoute -> System.out.println("Retrieved event route with Id: " + eventRoute.getEventRouteId()));
Parameters:
Returns:
getEventRouteWithResponse
public Mono<>
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:
Returns:
getModel
public Mono
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:
Returns:
getModelWithResponse
public Mono<>
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:
Returns:
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 serviceVersion(DigitalTwinsServiceVersion serviceVersion), this value will be equal to the latest service API version supported by this client.
Returns:
listEventRoutes
public PagedFlux
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:
listEventRoutes
public PagedFlux
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:
Returns:
listIncomingRelationships
public PagedFlux
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:
Returns:
listModels
public PagedFlux
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:
listModels
public PagedFlux
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:
Returns:
publishComponentTelemetry
public Mono
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:
Returns:
publishComponentTelemetryWithResponse
public Mono<>
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:
Returns:
publishTelemetry
public Mono
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:
Returns:
publishTelemetryWithResponse
public Mono<>
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:
Returns:
updateComponent
public Mono
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:
Returns:
updateComponentWithResponse
public Mono<>
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:
Returns:
updateDigitalTwin
public Mono
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:
Returns:
updateDigitalTwinWithResponse
public Mono<>
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:
Returns:
updateRelationship
public Mono
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:
Returns:
updateRelationshipWithResponse
public Mono<>
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:
Returns:
Applies to
Azure SDK for Java
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for