Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Technical Question] Set the expiry of cloud to device message in Azure IoT hub using JAVA SDK 2.X.X #1787

Closed
arathod-eic opened this issue Jun 3, 2024 · 1 comment
Labels

Comments

@arathod-eic
Copy link

I am well aware of setting the message expiration time from the portal by configuring the Default TTL under Cloud to device Messaging of Iot Hub.

From the documentation(https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-c2d), we can override this property by setting the ExpiryTimeUtc property in the service(By using iot service SDK)

I am using Java language to develop the solution, and I am using the latest SDK: 2.1.7 of iot-service-client maven artifact. In the previous SDK(1.34.2), there was a method to set the expiration of the message: setExpiryTimeUtc(long milliseconds), but in this new sdk, this method is removed.

I have tried setting the Properties of the Message but still, the message is not getting expired by the desired time as configured. Please refer to the code below. The message should expire after 1 minute from now, but when I open the device client, the message is still there to recieve.

Java
//Added Properties to set the expiration time of the message
Map<String, String > properties = new HashMap<String, String>();
// Set the absolute expiry time (e.g., 1 hour from now)
Instant expiryTime = Instant.now().plus(1, ChronoUnit.MINUTES);
properties.put("absolute-expiry-time", String.valueOf(expiryTime.toEpochMilli()));
messageToSend.setProperties(properties);
messageToSend.setDeliveryAcknowledgement(DeliveryAcknowledgement.Full);

@timtay-microsoft
Copy link
Member

The service client SDK you are referencing is maintained in a separate repo by different maintainers these days. It looks like you already filed the issue over there, but I can poke the maintainers of that repo to take another look into this for you.

Azure/azure-iot-service-sdk-java#10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants