Skip to content

Instantly share code, notes, and snippets.

@darccio
Created August 15, 2019 09:28
Show Gist options
  • Save darccio/ba066a4720b7981a991ce1cf2c1ee23e to your computer and use it in GitHub Desktop.
Save darccio/ba066a4720b7981a991ce1cf2c1ee23e to your computer and use it in GitHub Desktop.
NSQ class-based consumer
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