Message bus

Message bus is the transport layer abstraction mechanism. Frontera provides interface and several implementations. Only one message bus can be used in crawler at the time, and it’s selected with MESSAGE_BUS setting.

Spiders process can use

class frontera.contrib.backends.remote.messagebus.MessageBusBackend(manager)

to communicate using message bus.

Built-in message bus reference


It’s the default option, implemented using lightweight ZeroMQ library in

and can be configured using ZeroMQ message bus settings.

ZeroMQ message bus requires installed ZeroMQ library and running broker process, see Start cluster.

Overall ZeroMQ message bus is designed to get a working PoC quickly and smaller deployments. Mainly because it’s prone to message loss when data flow of components isn’t properly adjusted or during startup. Here’s the recommended order of components startup to avoid message loss:

  1. db worker
  2. strategy worker
  3. :term:`spider`s
Unfortunately, it’s not possible to avoid message loss when stopping running crawler with unfinished crawl. We recommend
to use Kafka message bus if your crawler application is sensitive to small message loss.
WARNING! ZeroMQ message bus doesn’t support yet multiple SW and DB workers, only one instance of each worker type is allowed.


Can be selected with

and configured using Kafka message bus settings.

Requires running Kafka service and more suitable for large-scale web crawling.


Depending on stream Frontera is using several message types to code it’s messages. Every message is a python native object serialized using msgpack or JSON. The codec module can be selected using MESSAGE_BUS_CODEC, and it’s required to export Encoder and Decoder classes.

Here are the classes needed to subclass to implement own codec:

class frontera.core.codec.BaseEncoder

Encodes a page_crawled message

Parameters:response (object) – A frontier Response object
Returns:bytes encoded message
encode_request_error(request, error)

Encodes a request_error message

  • request (object) – A frontier Request object
  • error (string) – Error description

bytes encoded message


Encodes requests for spider feed stream.

Parameters:request (object) – Frontera Request object
Returns:bytes encoded message
encode_update_score(request, score, schedule)

Encodes update_score messages for scoring log stream.

  • request (object) – Frontera Request object
  • score (float) – score
  • schedule (bool) – True if document needs to be scheduled for download

bytes encoded message


Encodes changing of job_id parameter.

Parameters:job_id (int) –
Returns:bytes encoded message
encode_offset(partition_id, offset)

Encodes current spider offset in spider feed.

  • partition_id (int) –
  • offset (int) –

bytes encoded message

class frontera.core.codec.BaseDecoder

Decodes the message.

Parameters:buffer (bytes) – encoded message
Returns:tuple of message type and related objects

Decodes Request objects.

Parameters:buffer (bytes) – serialized string
Returns:object Request

Available codecs


A MsgPack codec for Frontera. Implemented using native msgpack-python library.

Module: frontera.contrib.backends.remote.codecs.msgpack


A JSON codec for Frontera. Implemented using native json library.

Module: frontera.contrib.backends.remote.codecs.json