Table of Contents

Receive Messages

The MessageReceived method is called whenever a message arrives at your module. This is where you implement your module's core logic.

Tip

Required namespaces:

  • Crosser.EdgeNode.Flows.Models.Abstractions.Models
  • Crosser.EdgeNode.Flows
  • System.Threading.Tasks

Implementation

For our random number module, we'll generate a random value and add it to the message:

public class RandomNumberModule : FlowModule<RandomNumberModuleSettings>
{
    public override string UserFriendlyName => "Random Number";

    private readonly Random random = new();

    public RandomNumberModule() : base(FlowModuleType.Function) { }
    
    protected override Task MessageReceived(IFlowMessage message)
    {
        // Generate random value based on settings
        var randomValue = this.random.Next(
            this.Settings.TargetMin, 
            this.Settings.TargetMax);

        // Add value to message using the configured property name
        message.Set(this.Settings.TargetName, randomValue);

        // For now we just return null...
        return null;
    }
}

What we do with the value passed into the MessageReceived method is very specific for each module. This module is simple, we just add a new random value to a property decided by the settings.

>> Send Messages