Internals

Internal to the order preparation service, there are three stages:
  • Queue consumption,
  • Order preparation, and
  • Queue publishing.

Settings

Settings for the order preparation service.

order_prep.settings.INCOMING_AMQP

The incoming AMQP queue settings. It has the following keys:

HOST
The hostname of the AMQP server.
PORT
The port of the AMQP server.
USER
The username to use when authenticating against the AMQP server.
PASSWORD
The password to use when authenticating against the AMQP server.
VHOST
The virtual host to connect to on the AMQP server.
EXCHANGE
The exchange to connect to on the AMQP server.
EXCHANGE_TYPE
The type of EXCHANGE.
QUEUE_NAME
The name of the queue to consume.
ROUTING_KEY
The routing key of messages to be consumed.
order_prep.settings.OUTGOING_AMQP

The outgoing AMQP settings. It has the following keys:

HOST
The hostname of the AMQP server.
PORT
The port of the AMQP server.
USER
The username to use when authenticating against the AMQP server.
PASSWORD
The password to use when authenticating against the AMQP server.
VHOST
The virtual host to connect to on the AMQP server.
EXCHANGE
The exchange to connect to on the AMQP server.
ROUTING_KEY
The default routing key of messages produced.

Queue Consumption

There is a single callback function used for the queue consumption, consumer.consume_order().

order_prep.consumer.consume_order(body, message)

The callback to consume an order message from the queue.

This callback will prepare the order and then publish it to the Order DCS queue. Once that is done, it acknowledges the incoming message.

If processing fails, a critical log message is written and the incoming message is not acknowledged.

Parameters:

body
The body of the queue message. This will be a single JSON object representing an order.
message
The message header of the queue message. This is discarded.
Returns:
None

This callback is hooked up to the server using run.connect_consumer() which also uses lib.get_broker_connection().

order_prep.run.connect_consumer()

Return a connection with a consumer attached for the incoming queue.

The settings defined in order_prep.settings.INCOMING_AMQP are used to do this.

Returns:
A kombu.connection.BrokerConnection object connected to the server defined in INCOMING_AMQP. An order preparation consumer is attached appropriately.
order_prep.lib.get_broker_connection(amqp_settings)

Return a BrokerConnection for the given settings.

Parameters:

amqp_settings
A dictionary containing the connection settings. The dictionary must have the HOST, PORT, USER, PASSWORD and VHOST keys set. See order_prep.settings.INCOMING_AMQP and order_prep.settings.OUTGOING_AMQP for examples.
Returns:
A kombu.connection.BrokerConnection.

run.connect_consumer() is used by run.runloop() to set up a connection from which it consumes events forever.

order_prep.run.runloop()

Set up a connection and repeatedly consume events.

Order Preparation

Once an order has been received from the queue and processed in to its representative dictionary, it is passed to prepare_order(). prepare_order() in turn farms it out to normalise_lines() to generate a list of jobs in the order which can then be passed to add_completion_stages().

order_prep.preparation.prepare_order(order)

Returns a prepared order.

This means the following things will have happened:
  • All order lines will have been split in to jobs.
  • All jobs will have had the appropriate completion stages assigned to them.

Parameters:

order
An order dictionary.
Returns:

A prepared order dictionary.

No attribute but order_lines will have been modified.

order_prep.preparation.normalise_lines(order)

Normalises order lines for processing by the rest of the GD stack.

Parameters:

order
An order dictionary.
Returns:

An order dictionary with normalised order lines.

No attribute but order_lines will have been modified.

order_prep.preparation.add_completion_stages(order)

Adds completion stages to the order lines in an order.

Parameters:

order
An order dictionary.
Returns:

An order dictionary with completion stages set on all order lines.

No attribute but order_lines will have been modified.

Queue Publishing

Once an order has been prepared for the fulfilment process, it is published to the outgoing queue by prepare_order(). This is done using publish_order() which in turn uses get_producer() to get the producer to publish to.

order_prep.publisher.publish_order(order)

Publish an order to the outgoing queue defined in settings.

Parameters:

order
The order to be published (this will be the body of the outgoing message).
order_prep.publisher.get_producer()

Return a kombu.messaging.Producer for the outgoing server.

Table Of Contents

Previous topic

API

Next topic

Tests

This Page