Skip to main content

general sugarcoat for all pubsub flavors.

Project description

tesselite-pubsub

ci cd

General sugarcoat for all pubsub flavors.

purpose

Publish Subscribe is a pretty simple mechanism understandable by any human. For example, it is the ruling mechanism of all social networks.

But, in Python, pubsub is very complex to code given the variety of broker technologies (redis, rabbitMQ, kafka, GCP PubSub, Azure Event Hubs..)

The purpose of this library is to streamline the coding of Pubsub in a single-line call!

usage

Available Brokers:

internal name official name client library
gcp-pubsub Goggle Cloud Pubsub google-cloud-pubsub = "^2.26.1"
redis Redis redis = "^5.1.1"

Unvailable Brokers:

internal name official name client library
rabbitmq RabbitMQ todo
kafka Apache Kafka todo

low level usage

consume

from tesselite.pubsub import pubsubFactory

def callback(message): # callback function inputs serialized message 
    print(f"received this: {message}")
    
# consume loop
with pubsubFactory(broker="gcp-pubsub")(topic="tesselite-pubsub", log_name="consumer") as pubsub:
    pubsub.consume(callback=callback, deadLetter=None, subscription="tesselite")

publish

from tesselite.pubsub import pubsubFactory

def encoder(): # callback function inputs serialized message 
    yield "hello world"
    
# publish loop
with pubsubFactory(broker="gcp-pubsub")(topic="tesselite-pubsub", log_name="publisher") as pubsub:
    for msg in encoder():
        pubsub.publish(msg)

high level usage

consume

from tesselite.samples import consume # importing consume sample


def callback(message): # callback function inputs serialized message 
    print(f"received this: {message}")

if __name__ == '__main__':
    consume(broker='gcp-pubsub', callback=callback) # single-lined consume loop (default topic: tesselite-pubsub

publish

from tesselite.samples import publish # importing publish sample


def encoder(): # callback function inputs serialized message 
    yield "hello"

if __name__ == '__main__':
    publish(broker='gcp-pubsub', encoder=encoder) # single-lined publish call (default topic: tesselite-pubsub

behavior

Best Case Scenario

All broker backends technology implements the same interface → One would swap seamlessly to any broker technology by shifting the broker's name:

from tesselite import pubsubFactory

# broker : gcp-pubsub
client_gcp = pubsubFactory(broker="gcp-pubsub")(topic="tesselite-pubsub", log_name="tesselite")

# broker : redis
client_redis = pubsubFactory(broker="redis")(topic="tesselite-pubsub", log_name="tesselite")

The connection to broker auto-heals when the broker backend is unavailable → When auto-healing happens the log trace looks like this:

[tesselite][ERROR][2024-10-28 06:22:07] (open) connexion error [ConnectionError] => backoff.
[tesselite][ERROR][2024-10-28 06:22:13] (open) connexion error [ConnectionError] => backoff.
[tesselite][ERROR][2024-10-28 06:22:21] (open) connexion error [ConnectionError] => backoff.
[consume][INFO][2024-10-28 06:22:29] ready.
received this: {"uid": 0, "payload": "( publish ) hello world!"}
received this: {"uid": 1, "payload": "( publish ) hello world!"}
received this: {"uid": 2, "payload": "( publish ) hello world!"}

The procedure below is applied seamlessly to all broker technologies → To guarantee a fail-proof onboarding to the broker:

  1. topic checkout
  2. topic creation
  3. subscription checkout
  4. subscription creation
  5. publish or consume

Worst Case Scenario

A) Messages are lost if the subscription doesn't exist → This is an incurable limitation of pubsub mechanics.

B) The broker redis would drop messages if the consumer disconnects → This seems to be related to 'livestream' behavior of Redis.

C) The broker gcp-pubsub would freeze for a random timeperiod if no messages are available → This would generate sluggishness from time to time.

Therefore, the broker redis is ideal for livestreaming but not for message retention critical PaaS.

Therefore, the broker gcp-pubsub is ideal for message retention critical PaaS but maybe sluggish for livestream.

releases

Notes

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

tesselite_pubsub-0.1.8.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tesselite_pubsub-0.1.8-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file tesselite_pubsub-0.1.8.tar.gz.

File metadata

  • Download URL: tesselite_pubsub-0.1.8.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for tesselite_pubsub-0.1.8.tar.gz
Algorithm Hash digest
SHA256 d439627ae8c5f8bc84e3e00b4260d609c69e33ecb890c079bfb4ced8e8fa4977
MD5 ed1ee32aa3e344ff79c6e5548628919c
BLAKE2b-256 47c37e40dd978d0c83c335779c56d6b1c8746e3fc0bc9b586016e5cf5b7c69e5

See more details on using hashes here.

File details

Details for the file tesselite_pubsub-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: tesselite_pubsub-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for tesselite_pubsub-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 f793cb6a4e4d4904b89ada7129852d13f104dcf768b962f56cac8434a59a5fdb
MD5 0a6abf7d21bae272d66f37fbb3595447
BLAKE2b-256 203ab15365fa0ddd0caebbf556a943a72d55e26b150de48ac8ee9d62dac6fddd

See more details on using hashes here.

Supported by

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