Open survivant opened 2 years ago
I'm using Azure IOT explorer
here my I did :
I created a device and I changed a desired property value and click SAVE. The value was [newtest2345] and changed to [newtest23456] in the tab Network (developer tools) I have this (I replaced some text with )
the request DataPlane:
{"apiVersion":"2020-06-30-preview","body":"{\"deviceId\":\"derniertest\",\"etag\":\"AAAAAAAAABo=\",\"deviceEtag\":\"ODQ4NDk5Mzk=\",\"status\":\"enabled\",\"statusUpdateTime\":\"2022-10-11T12:33:31.5369789Z\",\"connectionState\":\"Disconnected\",\"lastActivityTime\":\"2022-10-18T19:49:51.1552214Z\",\"cloudToDeviceMessageCount\":0,\"authenticationType\":\"sas\",\"x509Thumbprint\":{\"primaryThumbprint\":null,\"secondaryThumbprint\":null},\"modelId\":\"\",\"version\":27,\"properties\":{\"desired\":{\"test\":\"newtest23456\",\"$metadata\":{\"$lastUpdated\":\"2022-10-19T12:10:35.7728649Z\",\"$lastUpdatedVersion\":26,\"test\":{\"$lastUpdated\":\"2022-10-19T12:10:35.7728649Z\",\"$lastUpdatedVersion\":26}},\"$version\":26},\"reported\":{\"$metadata\":{\"$lastUpdated\":\"2022-09-30T19:29:03.6006968Z\"},\"$version\":1}},\"capabilities\":{\"iotEdge\":false}}","hostName":"<hidden>.azure-devices.net","httpMethod":"PATCH","path":"twins/derniertest","sharedAccessSignature":"SharedAccessSignature sr=<hidden>.azure-devices.net&sig=ZjONPDFufMG1<hidden>%3D&se=1666182004&skn=iothubowner"}
the response
{"body":{"deviceId":"derniertest","etag":"AAAAAAAAABs=","deviceEtag":"ODQ4NDk5Mzk=","status":"enabled","statusUpdateTime":"2022-10-11T12:33:31.5369789Z","connectionState":"Disconnected","lastActivityTime":"2022-10-18T19:49:51.1552214Z","cloudToDeviceMessageCount":0,"authenticationType":"sas","x509Thumbprint":{"primaryThumbprint":null,"secondaryThumbprint":null},"modelId":"","version":28,"properties":{"desired":{"test":"newtest23456","$metadata":{"$lastUpdated":"2022-10-19T12:15:03.7924736Z","$lastUpdatedVersion":27,"test":{"$lastUpdated":"2022-10-19T12:15:03.7924736Z","$lastUpdatedVersion":27}},"$version":27},"reported":{"$metadata":{"$lastUpdated":"2022-09-30T19:29:03.6006968Z"},"$version":1}},"capabilities":{"iotEdge":false}},"headers":{"content-length":"729","content-type":"application/json; charset=utf-8","vary":"Origin","server":"Microsoft-HTTPAPI/2.0","x-ms-request-id":"85863b67-69af-4742-94a7-01cb3e2b7eb5","date":"Wed, 19 Oct 2022 12:15:05 GMT","connection":"close"}}
The workflow is :
IOT Explorer -> IotHub -> routing to Eventhub endpoint -> application using Azure Java SDK.
in my listener in Java, I received these headers
{"azure_eventhubs_sequence_number":25,"operationTimestamp":"2022-10-19T12:15:03.7924736Z","content-encoding":"utf-8","correlation-id":"362f012e4089","user-id":"aW90aHViLXBvYy1zZGlvbm5l","opType":"updateTwin","azure_raw_partition_id":"2","iothub-enqueuedtime":"2022-10-19T12:15:03.802+00:00","absolute-expiry-time":"utf-8","deviceId":"derniertest","x-opt-enqueued-time":"2022-10-19T12:15:03.957Z","iothub-message-schema":"twinChangeNotification","x-opt-sequence-number":25,"iothub-connection-device-id":"derniertest","iothub-message-source":"twinChangeEvents","azure_eventhubs_enqueued_time":"2022-10-19T12:15:03.957Z","hubName":"iothub-poc-sdionne","content-type":"application/json","x-opt-offset":8589937216,"id":"ac7b5f6c-65b0-3680-1829-909206e28eec","contentType":{"type":"application","subtype":"json","parameters":{},"charset":null,"concrete":true,"wildcardType":false,"wildcardSubtype":false,"subtypeSuffix":null},"azure_eventhubs_offset":8589937216,"timestamp":1666182096792}
I don't know what should be the value, but utf-8 is certainly wrong absolute-expiry-time":"utf-8"
here a screenshot of the data received
here my pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.3</version> <relativePath/> </parent> <groupId>com.comact</groupId> <artifactId>poc-iothub-to-dax</artifactId> <version>0.0.1-SNAPSHOT</version> <name>poc-iothub</name> <description>Demo project for Spring Boot</description> <properties> <java.version>11</java.version> <spring-cloud-azure.version>4.4.0</spring-cloud-azure.version> <springdoc.version>1.6.11</springdoc.version> </properties> <dependencies> <!-- https://mvnrepository.com/artifact/com.microsoft.azure.sdk.iot/iot-device-client --> <dependency> <groupId>com.microsoft.azure.sdk.iot</groupId> <artifactId>iot-device-client</artifactId> <version>2.1.2</version> </dependency> <dependency> <groupId>com.microsoft.azure.iothub-java-client</groupId> <artifactId>iothub-java-service-client</artifactId> <version>1.0.11</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-starter</artifactId> </dependency> <dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-starter-actuator</artifactId> </dependency> <dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-stream-binder-eventhubs</artifactId> <version>4.4.0</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-webflux-ui</artifactId> <version>${springdoc.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-dependencies</artifactId> <version>${spring-cloud-azure.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <finalName>poc-iothub-to-dax</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-maven-plugin</artifactId> <version>1.4</version> </plugin> </plugins> </build> </project>
here the java class
package com.example.demo.consumer; import com.example.demo.model.TestModel; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.Message; import java.util.function.Consumer; @Configuration public class TwinChangeEventsConsumer { private static final Logger LOGGER = LoggerFactory.getLogger(TwinChangeEventsConsumer.class); @Autowired ObjectMapper objectMapper; @Bean Consumer<Message<String>> twinchangeevents() { return message -> { LOGGER.info("Consumed a twinchangeevents [{}] headers [{}]", message.getPayload(), message.getHeaders()); try { String headers = objectMapper.writeValueAsString(message.getHeaders()); TestModel model = objectMapper.readValue(headers, TestModel.class); model.setRaw(message.getPayload()); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }; } }
I'm using Azure IOT explorer
here my I did :
I created a device and I changed a desired property value and click SAVE. The value was [newtest2345] and changed to [newtest23456] in the tab Network (developer tools) I have this (I replaced some text with)
the request DataPlane:
the response
The workflow is :
IOT Explorer -> IotHub -> routing to Eventhub endpoint -> application using Azure Java SDK.
in my listener in Java, I received these headers
I don't know what should be the value, but utf-8 is certainly wrong absolute-expiry-time":"utf-8"
here a screenshot of the data received
here my pom.xml
here the java class