Azure / Azure/azure-iot-sdk-csharp

[Bug Report] [v2] [IoTSDK] ModuleClient.SendMessageToRoute() not firing IncomingMessageCallback when routing M2M

Open
#3,392 0 comments 1 reaction 0 assignees View on GitHub
bug IoTSDK
Dominant language
C#
Stars
477
Forks
492
Avg merge
9h 55m
Merged PRs (30d)
2

Description

# Context

- **OS, version, SKU and CPU architecture used:** Ubuntu 20.04.2 LTS
- **Application's .NET Target Framework :** .NET8.0-rc1
- **Device:** PC
- **SDK version used:** 2.0.0-preview007

## Description of the issue
As a simplified version, we have created 2 bare-bones modules that are simply to send messages on an output and to receive messages on an input. When calling The SendMessageToRoute() method on the ModuleClient class, it seemingly succeeds without exception at sending the message, however the IotEdgeModule2.OnMessageReceivedAsync callback is never fired. We have verified that the routing is setup correctly between the modules. Using the pre-migrated methods in v1 of the SDK, this works fine. Following the sample code provided here: [EdgeModuleMessageSample](https://github.com/Azure/azure-iot-sdk-csharp/tree/previews/v2/iothub/device/samples/getting%20started/EdgeModuleMessageSample) it seems very similar to what I've outlined below. Any insight would be greatly appreciated

## Code sample exhibiting the issue
IotEdgeModule1 -> Responsible for periodically sending a message on output1

```
public sealed class IotEdgeModule1: BackgroundService
{
private IotHubModuleClient _client;
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
{
var connectionString = "removed";

_client = new IotHubModuleClient(connectionString);

await _client.OpenAsync(cancellationToken);

var sleep = TimeSpan.FromSeconds(15);
while (!cancellationToken.IsCancellationRequested)
{
var message = new TelemetryMessage(Encoding.ASCII.GetBytes("Sample message"));
await _client.SendMessageToRouteAsync("output1", message);
await Task.Delay(sleep, cancellationToken);
}
}
```
IotEdgeModule2 -> Responsible for logging the messages it receives from output1 of IotEdgeModule1

```
public sealed class IotEdgeModule2 : BackgroundService
{
private IotHubModuleClient _client;
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
{
var connectionString = "removed";

_client = new IotHubModuleClient(connectionString);

await _client.OpenAsync(cancellationToken);

await _client.SetIncomingMessageCallbackAsync(OnMessageReceivedAsync);

var sleep = TimeSpan.FromSeconds(15);
while (!cancellationToken.IsCancellationRequested)
{
await Task.Delay(sleep, cancellationToken);
}
}

private async Task OnMessageReceivedAsync(IncomingMessage receivedMessage)
{
Console.WriteLine("Received message on {Input} input.", receivedMessage.InputName);

return await Task.FromResult(MessageAcknowledgement.Complete);
}
}
```
Routing:
`FROM /messages/modules/IotEdgeModule1/outputs/output1 INTO BrokeredEndpoint("/modules/IotEdgeModule2/inputs/input1")`

Contributor guide

Open the contributing guide

Research direction

Start with the previews/v2/iothub/device/samples/getting started/EdgeModuleMessageSample referenced in the report, then trace ModuleClient.SendMessageToRouteAsync and SetIncomingMessageCallbackAsync. Reproduce the two-module route using the supplied output1-to-input1 configuration and compare it with the v1 behavior. Done means the receiving module's callback fires for the routed message.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.