Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUBHandler and listener should support connect and bind respectively #1544

Open
mivade opened this issue Jun 2, 2021 · 0 comments
Open

PUBHandler and listener should support connect and bind respectively #1544

mivade opened this issue Jun 2, 2021 · 0 comments

Comments

@mivade
Copy link
Contributor

mivade commented Jun 2, 2021

PUBHandler by default will bind a socket to the given address while the builtin listener will connect to the address. This is fine insofar as usually PUB is bound and SUB is connected but there is nothing that requires this pattern. In fact I would like to use PUBHandler as an easy way for distributed workers to send log messages to a central manager. With the default behavior if more than one worker uses the same address then I get errors regarding the address already being in use. I can work around this by creating the socket myself like:

ctx = zmq.Context.instance()
socket = ctx.socket(zmq.PUSH)
socket.connect("inproc://test")
logger = logging.getLogger("test")
logger.setLevel(logging.INFO)
handler = PUBHandler(socket)
handler.setLevel(logging.INFO)
logger.addHandler(handler)

but then I have to write the listener logic myself since there is no way to have it bind rather than connect. Ideally we could have options that allow us to select bind vs. connect, something like:

handler = PUBHandler("tcp://127.0.0.1:12345", connect=True)

and

python -m zmq.log --bind tcp://127.0.0.1:12345

If there is openness to allow for toggling this I'm willing to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant