Skip to content

ZeroMQ: ZeroMQMessageHandler with bind capability #9228

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

Closed
alessiomatricardi opened this issue Jun 10, 2024 · 3 comments · Fixed by #9229
Closed

ZeroMQ: ZeroMQMessageHandler with bind capability #9228

alessiomatricardi opened this issue Jun 10, 2024 · 3 comments · Fixed by #9229

Comments

@alessiomatricardi
Copy link
Contributor

alessiomatricardi commented Jun 10, 2024

Expected Behavior

The expected behaviour is that the ZeroMqMessageHandler could bind a port when the other part (a ZeroMqMessageProducer or whatever out of Spring world) connects to that port.

Current Behavior

As for now, the ZeroMqMessageHandler can only connect to a specific URL, while no binding is allowed.

Context

As per ZeroMQ philosophy, binding or connecting to a socket is completely decoupled from sender/receiver abstraction.

My question is: Is there any reason behind the current limitation? Something I'm missing out?
If you agree, I could make a PR to add this functionality

@alessiomatricardi alessiomatricardi added status: waiting-for-triage The issue need to be evaluated and its future decided type: enhancement labels Jun 10, 2024
@artembilan
Copy link
Member

Well, we even mention that in the doc: https://docs.spring.io/spring-integration/reference/zeromq.html#zeromq-outbound-channel-adapter.

I cannot recall why, but I believe it is just because the ZeroMqMessageHandler is passive and does its stuff only when we send a message into this handler.
Therefore it feels a bit awkward to make this component as a server side.
The workaround is very easy if intention is exactly to have a server in the producer application:

private String socketAddress = "inproc://messageHandler.test";

@Bean
ZContext context() {
	return new ZContext();
}

@Bean
ZMQ.Socket mySocket(ZContext context) {
	ZMQ.Socket socket = context.createSocket(SocketType.PAIR);
	socket.bind(this.socketAddress);
        return socket;
}

@Bean
ZeroMqMessageHandler myMessageHandler(ZContext context) {
     return new ZeroMqMessageHandler(context, this.socketAddress);
} 

Sorry, the SocketType.PAIR is in-memory, but you got a gist.

@alessiomatricardi
Copy link
Contributor Author

alessiomatricardi commented Jun 10, 2024

Yes, I read the docs and also got your point.

My point is that if we provide the instruments for binding of the message producer (inbound) we could provide this capability also on outbound.

A classical scenario could be this one:
My application has a publisher which publish on port 9090 => it will bind tcp://*:9090.

Over the network, there are many subscribers (eterogeneus for programming language and/or ZMQ library) who connect on tcp://publisher_ip:9090 and wait for messages.

My application send messages over a MessageChannel, and they are redirect to the ZMQ.Socket bound by the publisher and sent to all the subscribers

As for now, this approach is not applicable. Let me know if I’m avoiding some details or crucial points.

@artembilan
Copy link
Member

Ok. If that is the use-case which requires such a convenience, then let’s do that! Consider to implement that logic in the Lifecylce.start(). However this also could be done only for the current 6.4. As we have a reasonable workaround .

@artembilan artembilan added this to the 6.4.0-M1 milestone Jun 18, 2024
@artembilan artembilan added in: zeromq and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants