Skip to content

Commit

Permalink
Merge pull request #15 from mr-raccoon-97/main
Browse files Browse the repository at this point in the history
Add message class
  • Loading branch information
mapache-software authored Nov 15, 2024
2 parents 500eb52 + f124e9e commit 97041d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions pybondi/publisher.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
from typing import Any
from typing import Callable
from datetime import datetime, timezone
from collections import deque
from dataclasses import dataclass
from abc import ABC, abstractmethod

@dataclass
class Message:
'''
A message to be published by the publisher.
Attributes:
sender: The identifier of the entitiy that sends the message.
payload: The payload of the message.
'''
sender: str
payload: Any
timestamp: datetime = datetime.now(timezone.utc)


class Base(ABC):
"""
An abstract base class for a publisher.
Expand All @@ -22,7 +38,7 @@ class Base(ABC):
"""

@abstractmethod
def publish(self, topic: str, message: Any) -> None:
def publish(self, topic: str, message: Message) -> None:
"""
Publishes a message to a topic.
Expand Down Expand Up @@ -74,7 +90,7 @@ def subscribe(self, topic: str, subscriber: Callable):
'''
self.subscribers.setdefault(topic, []).append(subscriber)

def publish(self, topic: str, message: Any):
def publish(self, topic: str, message: Message):
'''
Receives a message from the publisher.
'''
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pybondi"
version = "0.3.1"
version = "0.3.2"
description = "A lightweight library for creating event driven systems using domain driven design."
authors = ["Eric Cardozo <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 97041d7

Please sign in to comment.