SendLocal clarification

I have a scenario where I can send 1000’s of commands in a loop
At the moment I am using SendLocal as they are processed on the same endpoint
On reading about concurrency and batching of sending messages, do I need to consider concurrencey with SendLocal? Does SendLocal send immediately or batch the sending?
Or am I better batching commands and Sending them immediately?

By default, all send operations (including SendLocal) are batched by the sending pipeline. That means if you have code like the following in your handler:

async Task Handle( MyMessage m, IMessageHandlerContext c )
   var outgoing = new List<Task>();
   for(i = 0; i < 1000; i++ )
      c.SendLocal(new LocalMessage());
   await Task.WhenAll(outgoing)

All 1000 messages will be delivered when completing the incoming message processing in a batch if the transport supports batching; otherwise, in a best-effort kind of approach, but always at the end.

You can use immediate dispatch to influence that behavior.

Thanks, I just hit the batching limits on Azure as your reply came
I see there is no way to sendlocal immediately so would need to use send
Is there any advantage of using SendLocal over Send?

Send requires routing information to be provided.
SendLocal does not.
Aside from that, both operation are identical.

thanks for the clarification. From what I can tell, there is no option to use sendlocal immediately though, correct?

You can provide SendOptions. See example.

Not that I can see with SendLocal

SendLocal is a shortcut for:

var options = new SendOptions();

context.Send( myMessage, options);

With that in mind, you can do:

var options = new SendOptions();

context.Send( myMessage, options);

To have an immediate send local dispatch. I wrote directly in the browser; do not trust my brain compiler :laughing:

1 Like