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 minutes from now, but when I open the device client, the message is still there to recieve.
//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);