Skip to content

Instantly share code, notes, and snippets.

@Marlysson
Last active February 16, 2022 09:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marlysson/111c738dac66571a6f789bfb0a1b4e1b to your computer and use it in GitHub Desktop.
Save Marlysson/111c738dac66571a6f789bfb0a1b4e1b to your computer and use it in GitHub Desktop.
Integrating ZeroMQ with Masonite
from masonite.providers import Provider
class ZeroMQProvider(Provider):
def __init__(self, application):
self.application = application
def register(self):
print("Starting zeromq")
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")
while True:
# Wait for data sent from client
data = socket.recv()
print(f"Received request: {message}")
# Send reply back to client
socket.send(b"World {}")
# With self.application you have access to all Masonite resources..
# Make a queue to receiving data from client zeromq and run some job to make some processing ( persist in database maybe ):
# self.application.make("queue").push(Job(data))
def boot(self):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment