Last active
February 16, 2022 09:00
-
-
Save Marlysson/111c738dac66571a6f789bfb0a1b4e1b to your computer and use it in GitHub Desktop.
Integrating ZeroMQ with Masonite
This file contains hidden or 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
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