Routers

Routers manage moving messages between transports and applications according to a specified set of rules.

To address router

vumi2.routers.ToAddressRouter

A to address router routes inbound messages from one or many transports according to the to address on the message. The address is matched against a list of patterns, and is sent to any applications whose configured pattern is matched against.

Outbound messages from applications are routed to the transport that the are in reply to. The transport_name field on the message is used to determine which transport to send the message to.

A good use for this router is on USSD, where for example you have a transport for the *1234# USSD code. Then you can route the base code *1234# to one application, and the *1234*1# to another.

Configuration

The following configuration options are available. See Base worker configuration for the additional configuration options available for all workers.

transport_names: list[str]

The names of the transports that we’re consuming inbound messages from, and routing outbound messages to.

to_address_mappings: dict[str, str]

The keys of this dictionary are the application names to send the inbound messages to, and the values are the regular expression patterns to match against

message_cache_class: str

The path to the class to use for caching messages. Defaults to vumi2.message_caches.MemoryMessageCache, a message cache that caches the messages in memory. This transport caches outbound messages in order to know where to route the events for those messages. See Memory Message Cache for more information

message_cache_config: dict

The config for the specified message cache.

For example:

transport_names:
    - ussd_transport
to_address_mappings:
    home_application: "^\\*1234#$"
    app2: "^\\*1234\\*1#$"