Skip to main content

Message Dispatcher

Use the Message Dispatcher pattern to coordinate which performer receives each message when several equivalent performers can process the same request.

The pattern is implemented at the point where the integration receives a message and must choose one processing endpoint. Keep the dispatch state close to the entry point, update it before the outbound call, and send the message to the selected performer through a connector.

Stateful round-robin dispatch

Use stateful round-robin dispatch when each incoming message should be sent to the next processor in a fixed set. Store the current processor index in the service, update it with a lock, and call the selected processor through an HTTP client connection. The lock keeps the index update consistent when multiple requests arrive at the same time. For constructs that do not have a full visual representation, switch to pro-code through the Flow Diagram editor.

  1. Create an HTTP service for the dispatcher entry point.
  2. Add a GET resource, such as /process, and define a query parameter that carries the message reference, such as resourceUrl. See resource inputs.
  3. Add the outbound processor HTTP connection. Configure its base URL with a configurable variable.
  4. Add a service-level variable named nextProcessor with type int and default value 0.
  5. In the resource flow, add the processor selection logic as a Ballerina code block: read nextProcessor, advance it inside a lock, and store the selected processor ID.
  6. Add the HTTP connector call that includes the selected processor ID in the request path and passes the message reference as a query parameter.
  7. Return the processor response from the resource function.