Builtin middleware

Vumi ships with a small set of generically useful middleware:

AddressTranslationMiddleware

Overwrites to_addr and from_addr values based on a simple mapping. Useful for debugging and testing.

class vumi.middleware.address_translator.AddressTranslationMiddleware(name, config, worker)

Address translation middleware.

Used for mapping a set of to_addr values in outbound messages to new values. Inbound messages have the inverse mapping applied to their from_addr values.. This is useful during debugging, testing and development.

For example, you might want to make your Gmail address look like an MSISDN to an application to test SMS address handling, for instance. Or you might want to have an outgoing SMS end up at your Gmail account.

Configuration options:

Parameters:outbound_map (dict) – Mapping of old to_addr values to new to_addr values for outbound messages. Inbound messages have the inverse mapping applied to from_addr values. Addresses not in this dictionary are not affected.

LoggingMiddleware

Logs messages, events and failures as they enter or leave a transport.

class vumi.middleware.logging.LoggingMiddleware(name, config, worker)

Middleware for logging messages published and consumed by transports and applications.

Optional configuration:

Parameters:
  • log_level (string) – Log level from vumi.log to log inbound and outbound messages and events at. Default is info.
  • failure_log_level (string) – Log level from vumi.log to log failure messages at. Default is error.

TaggingMiddleware

class vumi.middleware.tagger.TaggingMiddleware(name, config, worker)

Transport middleware for adding tag names to inbound messages and for adding additional parameters to outbound messages based on their tag.

Transports that wish to eventually have incoming messages associated with an existing message batch by vumi.application.MessageStore or via vumi.middleware.StoringMiddleware need to ensure that incoming messages are provided with a tag by this or some other middleware.

Configuration options:

Parameters:
  • incoming (dict) –
    • addr_pattern (string): Regular expression matching the to_addr of incoming messages. Incoming messages with to_addr values that don’t match the pattern are not modified.
    • tagpool_template (string): Template for producing tag pool from successful matches of addr_pattern. The string is expanded using match.expand(tagpool_template).
    • tagname_template (string): Template for producing tag name from successful matches of addr_pattern. The string is expanded using match.expand(tagname_template).
  • outgoing (dict) –
    • tagname_pattern (string): Regular expression matching the tag name of outgoing messages. Outgoing messages with tag names that don’t match the pattern are not modified. Note: The tag pool the tag belongs to is not examined.
    • msg_template (dict): A dictionary of additional key-value pairs to add to the outgoing message payloads whose tag matches tag_pattern. Values which are strings are expanded using match.expand(value). Values which are dicts are recursed into. Values which are neither are left as is.

StoringMiddleware

class vumi.middleware.message_storing.StoringMiddleware(name, config, worker)

Middleware for storing inbound and outbound messages and events.

Failures are not stored currently because these are typically stored by vumi.transports.FailureWorker instances.

Messages are always stored. However, in order for messages to be associated with a particular batch_id ( see vumi.application.MessageStore) a batch needs to be created in the message store (typically by an application worker that initiates sending outbound messages) and messages need to be tagged with a tag associated with the batch (typically by an application worker or middleware such as vumi.middleware.TaggingMiddleware).

Configuration options:

Parameters:
  • store_prefix (string) – Prefix for message store keys in key-value store. Default is ‘message_store’.
  • redis_manager (dict) – Redis configuration parameters.
  • riak_manager (dict) – Riak configuration parameters. Must contain at least a bucket_prefix key.
  • store_on_consume (bool) – True to store consumed messages as well as published ones, False to store only published messages. Default is True.