How to Use a Subscriber Decorator in a Class to Utilize Class Functionality? #1922
Unanswered
Atanusaha143
asked this question in
Q&A
Replies: 1 comment
-
Subscriber can't provide to access to subscriber_obj = Subscriber()
broker.subscruber(subscriber_obj.handle_msg) Anyway, I don't recommend you to use class-based handlers and prefer any existing mechanisms like Context/Depends |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm working on a Python application where I need to process messages from a stream using a subscriber. I want to encapsulate the subscriber logic within a class so I can use class functionalities like helper methods and instance variables using
self
.Here's a simplified example of my current implementation:
Issue:
I want to refactor this code so that I can call the class methods using self rather than Subscriber.method_name(...). For example:
The current implementation using the decorator
@nats_broker.subscriber
doesn't provide access toself
Question:
Are there any best practices or alternative patterns I should consider for encapsulating subscriber logic while ensuring access to instance-level methods and variables? Additionally, I want to ensure that dependency injection is properly initialized through the class constructor (
__init__
).Beta Was this translation helpful? Give feedback.
All reactions