Skip to main content

general sugarcoat for all pubsub flavors.

Project description

tesselite-pubsub

general sugarcoat for all pubsub flavors.

pubsub

Publish Subscribe is a pretty simple mechanism understandable by any human.

For example, it is the ruling mechanism of all Social Networks.

But, yet very complex to code in Python given the variety of backends logic (redis, rabbitMQ, kafka, GCP PubSub, Azure Event Hubs..)

The goal of this library is to streamline the coding of Pubsub in two simple calls:


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"

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 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

Behavior

Best Case Scenario

The interface to all broker backends technology is generic. One would swap seamlessly to any broker technology:

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.

The generic mechanics bellow works for all broker backends:

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

Pathologic Behaviors

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.

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.5.tar.gz (8.6 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.5-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tesselite_pubsub-0.1.5.tar.gz
  • Upload date:
  • Size: 8.6 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.5.tar.gz
Algorithm Hash digest
SHA256 9600914d64e67231f7b7651cdbbcc425b6b330868542576c2498389fba1b25b1
MD5 8d3969c9d8d75aaa868eda23860dc86c
BLAKE2b-256 3b988b6b6cd720f1d73dca3bbba6032445898f9bee5f54b49b2142fa25375382

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tesselite_pubsub-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 10.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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8058504b402c8d7865b2c85f19d8036086a2014333a0f01d2f503d48ac875bf7
MD5 a4ce9b2f9bbdb0265d0d2133f39086e5
BLAKE2b-256 3f7e95535e65f555a92b759819fe95e43ba7b052a4f9625efbcfb9e63e506d00

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