-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
MQTT Device is auto rejecting Cloud to Device messages for first time #98930
Comments
Thanks for your feedback! We will investigate and update as appropriate. |
@RamanathanChinnappan-MSFT thanks for the response, do you have any idea or guess as to when you'll have more information? We're trying to get these new cloud to device message features released for our projects, however this issue arising is going to limit/prevent us being able to do that and I'm going to need to be able to provide some idea on timeline. Thanks! |
Can you please add more info on the issue?
|
@AshokPeddakotla-MSFT Hello, I've updated the original issue w/ Additional Details Please let me know what else I can provide. |
@willyt150 We are checking this issue internally with our team. Please stay tuned for further updates. Appreciate your time and patience. |
@willyt150 Below is the response from our team. Do let us know if that helps. We have not heard similar issue before, but it will be helpful if you can confirm
|
@AshokPeddakotla-MSFT Thanks for the response.
I'll keep you posted on my progress/findings |
@willyt150 Any update/progress on this? |
@AshokPeddakotla-MSFT unfortunately, I've been given higher priority items than trying to reproduce the issue with raw MQTT (which I'll have to learn/guess at). At this point I do not have an ETA on when I'll be able to get to it. I was however able to document the exact flow with the .Net C# SDK that results in the issue. (Not sure if anyone on the MS side could attempt the same flow with an already setup raw MQTT system)
The moment the ReceiveAsync call has been made, any C2D messages sent after all work. |
@willyt150 We have not observed such issues. Please file a support request @ https://aka.ms/azsupt? If you do not have access to a support plan, please reach out @ [email protected] with a link to this Issue as well as your subscription ID and we can help get the support ticket opened for this issue. Thread URL: # Please let me know once you have done the same. Also, for further Technical help, please post to Microsoft Q&A We will now proceed to close this thread. If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue. |
I've faced with the same issue. I use MQTT and .NET SDK previews/v2 branch. I receive Rejected on backend side. |
We ended up just building a workaround in our server side code to resend "Rejected" C2D messages up to a configured amount (e.g. 3). After the first rejection, it doesn't auto-reject again. We keep track of the resend count of the message id ourselves. It still appears to happen only the very first time for a brand new IoT Device. If we delete an existing IoT device that has been interacting with C2D messages and recreate it, everything works just fine and it's never rejected. |
I use Azure IoT SDK .NET previews/v2 and communicate through MQTT. Steps for reproduce:
X509Certificate2 x509Certificate = Helper.LoadProvisioningCertificate();
var security = new AuthenticationProviderX509(x509Certificate);
var registrationId = security.GetRegistrationId();
IAuthenticationMethod auth = new ClientAuthenticationWithX509Certificate(x509Certificate, registrationId);
var deviceClient = new IotHubDeviceClient(Helper.IotHubHostName, auth, new IotHubClientOptions(new IotHubClientMqttSettings()));
deviceClient.ConnectionStatusChangeCallback = (info) =>
{
Console.WriteLine($"Device Status {info.Status}; Change reason: {info.ChangeReason}; Recommended action {info.RecommendedAction}.");
};
await deviceClient!.OpenAsync(CancellationToken.None);
await Task.Delay(-1);
async static Task Main(string[] args)
{
var iotHub = ConfigurationManager.AppSettings["IoTHubConnectionString"];
_serviceClient = new IotHubServiceClient(iotHub);
await ReceiveMessageFeedbacksAsync(CancellationToken.None);
await Console.Out.WriteLineAsync("feedback listener started");
await Task.Delay(-1);
}
private static async Task ReceiveMessageFeedbacksAsync(CancellationToken token)
{
_serviceClient.MessageFeedback.MessageFeedbackProcessor =
(FeedbackBatch batch) =>
{
Console.WriteLine("New Feedback received:");
Console.WriteLine(JsonConvert.SerializeObject(
new
{
batch.EnqueuedOnUtc,
batch.Records
}, Formatting.Indented));
return Task.FromResult(AcknowledgementType.Complete);
};
await _serviceClient.MessageFeedback.OpenAsync(token);
}
async static Task Main(string[] args)
{
_serviceClient = new IotHubServiceClient(ConfigurationManager.AppSettings["IoTHubConnectionString"]);
while (true)
{
await Console.Out.WriteLineAsync("Send message: ");
Console.ReadKey();
await SendC2dMessagesAsync(CancellationToken.None);
}
}
private static async Task SendC2dMessagesAsync(CancellationToken cancellationToken)
{
var messageId = Guid.NewGuid().ToString("D");
var correlationId = Guid.NewGuid().ToString("D");
await Console.Out.WriteLineAsync($"MessageId: {messageId};");
var message = new OutgoingMessage("test message")
{
MessageId = messageId,
CorrelationId = correlationId,
// An acknowledgment is sent on delivery success or failure.
Ack = DeliveryAcknowledgement.Full
};
message.Properties.Add("custom-prop-device-id", Helper.DeviceId);
Console.WriteLine($"Sending C2D message with Id {message.MessageId} to {Helper.DeviceId}.");
await _serviceClient.Messages.OpenAsync();
await _serviceClient.Messages.SendAsync(Helper.DeviceId, message, CancellationToken.None);
Console.WriteLine($"Sent message with Id {message.MessageId} to {Helper.DeviceId}.");
}
Result:I have 4 Azure IoT Hubs:
|
I am unable to reopen the issue, I think it would need to be @AshokPeddakotla-MSFT, @RamanathanChinnappan-MSFT or another collaborator |
Hello,
This document specifically calls out that MQTT device communication cannot
Reject
a Cloud to Device message, and I can confirm that when I try to call the "RejectAsync" method on my DeviceClient, with MQTT, it throws an exception saying it's not supported.However, we are experiencing for every brand new IoT Device, the first time we send a Cloud to Device message to it, that when the device code connects and attempts to receive the messages, those messages are auto rejected and never received.
Why's it doing that? Is this expected behavior or a bug?
This is occurring on multiple IoT Hub instances
Thanks
Additional Details
Microsoft.Azure.Devices.Client v1.41.2.0 NuGet Package
DeviceClient.Create
withTransportType.Mqtt
deviceClient.ReceiveAsync(TimeSpan.FromSeconds(5))
there isn't any error, I just receive a null Message.Ack
value toDeliveryAcknowledgement.Full
, so once the C# code attempts the ReceiveAsync call, we then receive feedback that it was Rejected. FeedbackRecord object containsFeedbackStatusCode.Rejected
Message rejected
Once the first message has been auto rejected, every following message is received by the C# client.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: