HTTP RPC

Base class for constructing HTTP-based transports.

HTTP RPC base class

class vumi.transports.httprpc.httprpc.HttpRpcTransport(options, config=None)

Bases: vumi.transports.base.Transport

Base class for synchronous HTTP transports.

Because a reply from an application worker is needed before the HTTP response can be completed, a reply needs to be returned to the same transport worker that generated the inbound message. This means that currently there many only be one transport worker for each instance of this transport of a given name.

CONFIG_CLASS

alias of HttpRpcTransportConfig

add_status(**kw)

Publishes a status if it is not a repeat of the previously published status.

get_clock()

For easier stubbing in tests

get_transport_url(suffix='')

Get the URL for the HTTP resource. Requires the worker to be started.

This is mostly useful in tests, and probably shouldn’t be used in non-test code, because the API might live behind a load balancer or proxy.

on_degraded_response_time(message_id, time)

Can be overridden by subclasses to do something when the response time is high enough for the transport to be considered running in a degraded state.

on_down_response_time(message_id, time)

Can be overridden by subclasses to do something when the response time is high enough for the transport to be considered non-functioning.

on_good_response_time(message_id, time)

Can be overridden by subclasses to do something when the response time is low enough for the transport to be considered running normally.

on_timeout(message_id, time)

Can be overridden by subclasses to do something when the response times out.

set_request_end(message_id)

Checks the saved timestamp to see the response time. If the starting timestamp for the message cannot be found, nothing is done. If the time is more than response_time_down, a down status event is sent. If the time more than response_time_degraded, a degraded status event is sent. If the time is less than response_time_degraded, an ok status event is sent.

class vumi.transports.httprpc.httprpc.HttpRpcTransportConfig(config_data, static=False)

Bases: vumi.transports.base.TransportConfig

Base config definition for transports.

You should subclass this and add transport-specific fields.

Configuration options:

Parameters:
  • amqp_prefetch_count (int) – The number of messages fetched concurrently from each AMQP queue by each worker instance.
  • transport_name (str) – The name this transport instance will use to create its queues.
  • publish_status (bool) – Whether status messages should be published by the transport
  • web_path (str) – The path to listen for requests on.
  • web_port (int) – The port to listen for requests on, defaults to 0.
  • web_username (str) – The username to require callers to authenticate with. If None then no authentication is required. Currently only HTTP Basic authentication is supported.
  • web_password (str) – The password to go with web_username. Must be None if and only if web_username is None.
  • web_auth_domain (str) – The name of authentication domain.
  • health_path (str) – The path to listen for downstream health checks on (useful with HAProxy)
  • request_cleanup_interval (int) – How often should we actively look for old connections that should manually be timed out. Anything less than 1 disables the request cleanup meaning that all request objects will be kept in memory until the server is restarted, regardless if the remote side has dropped the connection or not. Defaults to 5 seconds.
  • request_timeout (int) – How long should we wait for the remote side generating the response for this synchronous operation to come back. Any connection that has waited longer than request_timeout seconds will manually be closed. Defaults to 4 minutes.
  • request_timeout_status_code (int) – What HTTP status code should be generated when a timeout occurs. Defaults to 504 Gateway Timeout.
  • request_timeout_body (str) – What HTTP body should be returned when a timeout occurs. Defaults to ‘’.
  • noisy (bool) – Defaults to False set to True to make this transport log verbosely.
  • validation_mode (str) – The mode to operate in. Can be ‘strict’ or ‘permissive’. If ‘strict’ then any parameter received that is not listed in EXPECTED_FIELDS nor in IGNORED_FIELDS will raise an error. If ‘permissive’ then no error is raised as long as all the EXPECTED_FIELDS are present.
  • response_time_down (float) – The maximum time allowed for a response before the service is considered down
  • response_time_degraded (float) – The maximum time allowed for a response before the service is considered degraded