Skip to main content

A simple Django app to comunicate with postoffice

Project description

Post office django client

image image

What is postoffice django

postoffice_django is a django app to communicate with postoffice.

Features

  • Set up server via django commands:
    • Create necessary topics in postoffice with configure_postoffice_publishers to be able to publish a message
    • Create necessary publishers in postoffice with configure_postoffice_topics to be able to consume messages
  • Easily send messages to postoffice server

How to install it

Prerequisites

To be able to run the application, you must have

  • django
  • requests

Obviously, you need a django project up and running

Installing postoffice_django

At the moment there are two ways to install the app:

$ pip install postoffice-django

or add

postoffice-django

to your requirements file

Add it to your Django installed apps:

INSTALLED_APPS = [
    ...
    'postoffice_django'
]

Then, you need to set the required settings for your app:

POSTOFFICE = {
    'URL': 'http://fake.service',
    'CONSUMERS': [{
            'topic': 'some_topic',
            'target': 'http://www.some_url.com',
            'type': 'http',
            'from_now': True
        },
        {
            'topic': 'another_topic',
            'target': 'http://www.another_url.com',
            'type': 'pubsub',
            'from_now': False
        }],
    'TIMEOUT': 0.3,
    'ORIGIN_HOST': 'example.com',
    'TOPICS': ['topic_to_create', 'another_topic_to_create']
}
  • URL: Is the url where the Postoffice server is hosted.

  • CONSUMERS: Are the consumers which must been configured as publishers in Postoffice server. With that, we create the necessary topics and publishers on Postoffice.

    • topic: Topic name to the consumer

    • target: Url or pub/sub topic name

    • type: http/pubsub

  • TIMEOUT: Specific timeout to use in every communication with Postoffice. If not specified, the default value is 0.5 seconds.

  • ORIGIN_HOST: The host from where the topic is created (your host). It is necessary in order to postoffice know where the topic come from.

  • TOPICS: Topics to be created in order to send messages to postoffice

How to setup Postoffice via django commands

Now we are ready to start sending messages to postoffice. But first, we must generate topics and/or publishers in postoffice depending on the purpose of the project with postoffice.

If we need to create the topics to be able to publish, we should execute:

$ ./manage.py configure_postoffice_topics

and, if we need to create the publishers, we should execute:

$ ./manage.py configure_postoffice_publishers

Sending messages to postoffice

We have the publish method from the publishing module

from postoffice_django.publishing import publish

publish(topic: str, message: dict, **attributes: dict) -> None
  • topic: Topic name. This topic must exist on postoffice to manage the message.

  • message: Message to be sent. This must be a dict.

  • attributes: Additional attr. All attributes are cast to string when publishing a message.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

postoffice_django-0.5.4.tar.gz (9.4 kB view hashes)

Uploaded Source

Built Distribution

postoffice_django-0.5.4-py2.py3-none-any.whl (15.8 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page