Base class for applications

A base class you should extend when writing applications.


class vumi.application.base.ApplicationConfig(config_data, static=False)

Base config definition for applications.

You should subclass this and add application-specific fields.

Configuration options:

  • amqp_prefetch_count (int) – The number of messages fetched concurrently from each AMQP queue by each worker instance.
  • transport_name (str) – The name this application instance will use to create its queues.
  • send_to (dict) – ‘send_to’ configuration dict.
class vumi.application.base.ApplicationWorker(options, config=None)

Base class for an application worker.

Handles vumi.message.TransportUserMessage and vumi.message.TransportEvent messages.

Application workers may send outgoing messages using reply_to() (for replies to incoming messages) or send_to() (for messages that are not replies).

send_to() can take either an endpoint parameter to specify the endpoint to send on (and optionally add additional message data from application configuration).

ALLOWED_ENDPOINTS lists the endpoints this application is allowed to send messages to using the send_to() method. If it is set to None, any endpoint is allowed.

Messages sent via send_to() pass optional additional data from configuration to the TransportUserMessage constructor, based on the endpoint parameter passed to send_to. This usually contains information useful for routing the message.

An example send_to() configuration might look like:

- send_to:
  - default:
    transport_name: sms_transport

NOTE: If you are using non-endpoint routing, ‘transport_name’ must be defined for each send_to section since dispatchers rely on this for routing outbound messages.

The available set of endpoints defaults to just the single endpoint named default. If applications wish to define their own set of available endpoints they should override ALLOWED_ENDPOINTS. Setting ALLOWED_ENDPOINTS to None allows the application to send on arbitrary endpoint names.


alias of ApplicationConfig

static check_endpoint(allowed_endpoints, endpoint)

Check that endpoint is in the list of allowed endpoints.

  • allowed_endpoints (list) – List (or set) of allowed endpoints. If allowed_endpoints is None, all endpoints are allowed.
  • endpoint (str) – Endpoint to check. The special value None is equivalent to default.

Close a session.

The .reply_to() method should not be called when the session is closed.


Handle an ack message.


Handle a delivery report.


Handle a nack message


Respond to user message.


Dispatch to event_type specific handlers.


Dispatch user messages to handler.


Respond to a new session.

Defaults to calling consume_user_message.


All application specific setup should happen in here.

Subclasses should override this method to perform extra setup.


Set up basic application worker stuff.

You shouldn’t have to override this in subclasses.


Clean-up of setup done in setup_application should happen here.