Rejected Companion Library

This library contains a number of utility and helper classes that were embedded in consumers that I have written recently. They add useful functionality on top of rejected.


HTTP API Helpers

class vetoes.service.HTTPServiceMixin(*args, **kwargs)

Mix this in to add the call_http_service() method.

  • service_map (dict) – mapping from logical “function” to HTTP service.
  • args – these are passed to rejected.consumer.Consumer() as-is
  • kwargs – these are passed to rejected.consumer.Consumer() as-is

The primary use of this mix-in is to make sending HTTP requests easier and safer. The call_http_service() method uses the get_service_url() to build the request URL for a named semantic function, send the request to a specific HTTP service, and perform some “opinionated” processing on the response. The separation of semantic function and HTTP service may seem a bit confusing at first. They are used to provide concise logging and well-named metrics. The semantic function describes the action being performed and the service is the actor performing the action.

The mapping from semantic function to HTTP service is handled by the service_map passed into the initializer. The mapping value is the HTTP service which is passed into get_service_url() to construct the request URL.

HTTP client behavior is controlled via consumer level configuration under the vetoes key. The following options are available:

Key Description
max_clients The max # of simultaneous requests that can be made
connect_timeout Timeout for initial connection in seconds
request_time Timeout for entire request in seconds

Example Configuration:

      consumer: rejected.example.Consumer
        - name: rabbitmq1
      qty: 2
      queue: generated_messages
          max_clients: 10
          connect_timeout: 5.0
          request_timeout: 30.0

tornado.httputil.HTTPHeaders instance of headers that are included in every request. This set is empty.


tornado.httpclient.AsyncHTTPClient used to make requests. The initializer sets the connect_timeout and request_timeout in self.http.defaults.

call_http_service(function, method, *path, **kwargs)

Send a HTTP request to a service.

  • function (str) – the function to invoke. The service is determined based on the service_map established during initialization.
  • method (str) – HTTP method to invoke.
  • path – path elements to the HTTP resource.
  • headers (dict) – optional set of headers to include in the message. These are in addition to http_headers.
  • json (dict or list) – optional body to send in the message. If this keyword is included, then the value is JSON encoded before being used as the body.
  • raise_error (bool) – if this keyword is included and set to False, then HTTP errors will be returned instead of raised as exceptions.
  • url (str) – if this keyword is included then it is used as-is instead of doing a service lookup.
  • kwargs – additional keyword arguments are passed to tornado.httpclient.AsyncHTTPClient.fetch().

a tornado.httpclient.HTTPResponse instance

Return type:



tornado.httpclient.HTTPError if a HTTP error occurs


rejected.consumer.ProcessingException if a low-level socket error occurs or a retry-able HTTP result is returned

get_service_url(service, *path, **kwargs)

Build a request URL for a specific service.

  • service (str) – name of the service to invoke
  • path – resource path elements
  • query_args (dict or None) – optional query parameters to include in the URL

the request URL

Return type:



You are required to override this method in your consumer. The base implementation simply raises an exception.

Release History

0.4.0 (13-Apr-2017)

0.3.0 (04-Apr-2017)

0.1.1 (06-Jan-2017)

  • Replaced readthedocs with