-
Notifications
You must be signed in to change notification settings - Fork 1.1k
GH-9228: ZeroMQ - provide binding to ZeroMqMessageHandler #9229
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
Changes from all commits
b2f83e3
4630c86
cecc3c5
6e06a09
1604b3c
89e7802
71e6276
7937f1c
d0c1e07
f8ecae0
7a1f7ee
bcac0a7
1348389
920c127
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2020-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.integration.zeromq; | ||
|
||
import org.zeromq.ZMQ; | ||
|
||
/** | ||
* Module that wraps common methods of ZeroMq integration classes | ||
* | ||
* @author Alessio Matricardi | ||
* | ||
* @since 6.4 | ||
* | ||
*/ | ||
public final class ZeroMqUtils { | ||
|
||
/** | ||
* Bind the ZeroMq socket to the given port over the TCP transport protocol. | ||
* @param socket the ZeroMq socket | ||
* @param port the port to bind ZeroMq socket to over TCP. If equal to 0, the socket will bind to a random port. | ||
* @return the effectively bound port | ||
*/ | ||
public static int bindSocket(ZMQ.Socket socket, int port) { | ||
if (port == 0) { | ||
return socket.bindToRandomPort("tcp://*"); | ||
artembilan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else { | ||
boolean bound = socket.bind("tcp://*:" + port); | ||
if (!bound) { | ||
throw new IllegalArgumentException("Cannot bind ZeroMQ socket to port: " + port); | ||
} | ||
return port; | ||
} | ||
} | ||
|
||
private ZeroMqUtils() { | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
* Factory class for ZeroMq components DSL. | ||
* | ||
* @author Artem Bilan | ||
* @author Alessio Matricardi | ||
* | ||
* @since 5.4 | ||
*/ | ||
|
@@ -58,6 +59,17 @@ public static ZeroMqMessageHandlerSpec outboundChannelAdapter(ZContext context, | |
return outboundChannelAdapter(context, () -> connectUrl); | ||
} | ||
|
||
/** | ||
* Create an instance of {@link ZeroMqMessageHandlerSpec} for the provided {@link ZContext} and binding port. | ||
* @param context the {@link ZContext} to use. | ||
* @param port the port to bind ZeroMq socket to over TCP. | ||
* @return the spec. | ||
* @since 6.4 | ||
*/ | ||
public static ZeroMqMessageHandlerSpec outboundChannelAdapter(ZContext context, int port) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if DSL has to expose extra factories to explicitly bind to random port. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or you have missed to push the change, or just didn't implement yet. |
||
return new ZeroMqMessageHandlerSpec(context, port); | ||
} | ||
|
||
/** | ||
* Create an instance of {@link ZeroMqMessageHandlerSpec} for the provided {@link ZContext} | ||
* and connection URL supplier. | ||
|
@@ -84,6 +96,43 @@ public static ZeroMqMessageHandlerSpec outboundChannelAdapter(ZContext context, | |
return new ZeroMqMessageHandlerSpec(context, connectUrl, socketType); | ||
} | ||
|
||
/** | ||
* Create an instance of {@link ZeroMqMessageHandlerSpec} for the provided {@link ZContext}. | ||
* The created socket will be bound to a random port. | ||
* @param context the {@link ZContext} to use. | ||
* @return the spec. | ||
* @since 6.4 | ||
*/ | ||
public static ZeroMqMessageHandlerSpec outboundChannelAdapter(ZContext context) { | ||
return new ZeroMqMessageHandlerSpec(context); | ||
} | ||
|
||
/** | ||
* Create an instance of {@link ZeroMqMessageHandlerSpec} for the provided {@link ZContext} and {@link SocketType}. | ||
* The created socket will be bound to a random port. | ||
* @param context the {@link ZContext} to use. | ||
* @param socketType the {@link SocketType} for ZeroMq socket. | ||
* @return the spec. | ||
* @since 6.4 | ||
*/ | ||
public static ZeroMqMessageHandlerSpec outboundChannelAdapter(ZContext context, SocketType socketType) { | ||
return new ZeroMqMessageHandlerSpec(context, socketType); | ||
} | ||
|
||
/** | ||
* Create an instance of {@link ZeroMqMessageHandlerSpec} for the provided {@link ZContext}, binding port | ||
* and {@link SocketType}. | ||
* @param context the {@link ZContext} to use. | ||
* @param port the port to bind ZeroMq socket to over TCP. | ||
* @param socketType the {@link SocketType} for ZeroMq socket. | ||
* @return the spec. | ||
* @since 6.4 | ||
*/ | ||
public static ZeroMqMessageHandlerSpec outboundChannelAdapter(ZContext context, int port, | ||
SocketType socketType) { | ||
return new ZeroMqMessageHandlerSpec(context, port, socketType); | ||
} | ||
|
||
/** | ||
* Create an instance of {@link ZeroMqMessageHandlerSpec} for the provided {@link ZContext}, | ||
* connection URL supplier and {@link SocketType}. | ||
|
Uh oh!
There was an error while loading. Please reload this page.