broker

class naz.broker.BaseBroker[source]

Bases: abc.ABC

This is the interface that must be implemented to satisfy naz’s broker. User implementations should inherit this class and implement the enqueue and dequeue methods with the type signatures shown.

naz calls an implementation of this class to enqueue and/or dequeue an item.

abstract async dequeue()[source]

dequeue an item.

Return type

Message

Returns

item that was dequeued. The item has to be returned as a naz.protocol.Message class instance. It is up to the broker implementation to do the de-serialization(if neccesary). naz.protocol module has a utility function json_to_Message that you can use to de-serialize a json string into naz.protocol.Message class instance.

abstract async enqueue(message)[source]

enqueue/save an item.

Parameters

message (Message) – The item to be enqueued/saved The message is a naz.protocol.Message class instance; It is up to the broker implementation to do the serialization(if neccesary) in order to be able to store it. naz.protocol.Message has a to_json() method that you can use to serialize a naz.protocol.Message class instance into json.

Return type

None

class naz.broker.SimpleBroker(maxsize=2500)[source]

Bases: naz.broker.BaseBroker

This is an in-memory implementation of BaseBroker.

Note: It should only be used for tests and demo purposes.

__init__(maxsize=2500)[source]
Parameters

maxsize (int) – the maximum number of items(not size) that can be put in the queue.

Return type

None

async dequeue()[source]

dequeue an item.

Return type

Message

Returns

item that was dequeued. The item has to be returned as a naz.protocol.Message class instance. It is up to the broker implementation to do the de-serialization(if neccesary). naz.protocol module has a utility function json_to_Message that you can use to de-serialize a json string into naz.protocol.Message class instance.

async enqueue(message)[source]

enqueue/save an item.

Parameters

message (Message) – The item to be enqueued/saved The message is a naz.protocol.Message class instance; It is up to the broker implementation to do the serialization(if neccesary) in order to be able to store it. naz.protocol.Message has a to_json() method that you can use to serialize a naz.protocol.Message class instance into json.

Return type

None