Skip to main content
Routing functions allow you to dynamically direct messages to different destinations based on the content of the message. This is useful for:
  • Interacting with REST APIs which assign each record its own resource path
  • Using different HTTP methods based on the change action
  • Implementing custom routing logic based on record contents
  • Customizing message routing for various messaging systems

How routing functions work

When you create a routing function, you define an Elixir function that returns routing information. Sequin will use this information to determine the destination for each message. For each message, your routing function receives the same parameters as a transform function and must return a map containing the sink-specific routing information:
In general, some details of how the message is processed will be static and fixed by the sink. Routing functions enable you to customize the behavior of a sink, but they are not intended to replace the idea of multiple sinks where necessary. For example, for the HTTP Webhook sink, the base URL is a static property - this improves batching and enables other performance optimizations such as connection pooling and request pipelining.

Sinks

Each sink type has different fields that can be routed:

Kafka sink

For Kafka, your routing function must return a map with these keys:

HTTP Webhook sink

For HTTP webhooks, your routing function must return a map with these keys: The endpoint_path you specify will be appended to the base URL of your webhook endpoint. For example, if your webhook endpoint is https://api.example.com and your routing function returns endpoint_path: "/users/123", the message will be sent to https://api.example.com/users/123.

Redis String sink

For Redis String, your routing function must return a map with these keys: The key is used to determine the key in Redis where the message will be stored in the SET operation:

Redis Stream sink

For Redis Stream, your routing function must return a map with these keys:

NATS sink

For NATS, your routing function must return a map with these keys:

GCP PubSub sink

For GCP PubSub, your routing function must return a map with these keys:

Elasticsearch sink

For Elasticsearch, your routing function must return a map with these keys:

Typesense sink

For Typesense, your routing function must return a map with these keys:

Meilisearch sink

For Meilisearch, your routing function must return a map with these keys:

AWS SQS sink

For AWS SQS, your routing function must return a map with these keys:

AWS Kinesis sink

For AWS Kinesis, your routing function must return a map with these keys:

S2 sink

For S2, your routing function must return a map with these keys:

RabbitMQ sink

For RabbitMQ, your routing function must return a map with these keys:

Azure Event Hub sink

For Azure Event Hubs, your routing function must return a map with these keys:

Common routing patterns

Routing to REST APIs

Route messages to RESTful endpoints based on record ID and action:

Content-based routing

Route messages based on their content:

Testing routing functions

When creating or editing a routing function, you can test it with real data from your database. Sequin will capture recent events and show you the effective routing parameters for each message. “Effective” means that Sequin will show the routing parameters that will actually be used downstream, inclusive of any defaulting or validation which happens after your routing function runs.

Limitations and considerations

  • Routing can impact batching if your routing function generates different destinations for each message.

Function Transforms

Learn about function transforms and how to use them to modify your message content.

Messages reference

Learn about the different fields you can use in routing functions.

Sequin YAML config

Learn about configuring functions in your sequin.yaml file.

HTTP Webhooks

Learn more about configuring HTTP webhook destinations.