Configuration

Possible configuration options for pyhermes are listed below.

BASE_URL

Specifies base URL of Hermes. Example:

BASE_URL = 'http://my-hermes.local'

URL_ADAPTER

Set this to any callable, if you want to add additional adapter for hermes requests (it's usefull when you're using service discovery, like Consul). Example usage (with requests-consul library):

def consul_adapter():
    from requests_consul.adapters.service import ConsulServiceAdapter
    return 'service://', ConsulServiceAdapter(**CONSUL)

BASE_URL = 'service://hermes'
URL_ADAPTER = consul_adapter

PUBLISHING_GROUP

Configuration of Hermes group to which you application will publish messages. Keys of this dictionary are the same as in Hermes creating group request body. Example:

PUBLISHING_GROUP = {
    'groupName': 'pl.allegro.pyhermes',
    'supportTeam': 'pyLabs',
    'owner': 'pyLabs',
    'contact': 'pylabs@allegro.pl'
}

PUBLISHING_TOPICS

Configuration of topics to which messages will be published from your application. Key of the main dictionary is name of the topic. Keys of single topic configuration are the same as in Hermes creating topic request body. Example:

PUBLISHING_TOPICS = {
    'test1': {
        'description': "test topic",
        'ack': 'LEADER',
        'retentionTime': 1,
        'trackingEnabled': False,
        'contentType': 'JSON',
        'validationEnabled': False,
    }
}

You don't have to specify all properties for single topic, just like in Hermes creating topic request body.

Note that full topic name for publishing will be combination of publish group name (PUBLISHING_GROUP['groupName']) and topic name, for example pl.allegro.pyhermes.test1.

SUBSCRIBERS_MAPPING

Here you could define mapping for subscribed topics. Example:

SUBSCRIBERS_MAPPING = {
    'pl.allegro.pyhermes.test1': 'my-topic'
}

Then you could use mapped topic for your subscriptions:

import pyhermes

@pyhermes.subscriber(topic='my-topic')
def my_handler(data):
    pass

In this case, my_handler will be used for every message coming for pl.allegro.pyhermes.test1 topic.