Created
August 15, 2019 09:28
-
-
Save darccio/ba066a4720b7981a991ce1cf2c1ee23e to your computer and use it in GitHub Desktop.
NSQ class-based consumer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nsq | |
class NSQWorker: | |
def __init__(self, *args, **kwargs): | |
self.banner = 'Hello from worker' | |
def process_message(self, message): | |
print(self.banner) | |
print(message.id) | |
print(message.body) | |
return True | |
worker = NSQWorker() | |
p1 = nsq.Reader( | |
message_handler=lambda m: worker.process_message(m), | |
lookupd_http_addresses=['http://127.0.0.1:4161'], | |
topic='dev_p1', | |
channel='worker', | |
) | |
p2 = nsq.Reader( | |
message_handler=lambda m: worker.process_message(m), | |
lookupd_http_addresses=['http://127.0.0.1:4161'], | |
topic='dev_p2', | |
channel='worker', | |
) | |
nsq.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment