Class ZeroMqProxy
- All Implemented Interfaces:
Aware
,BeanNameAware
,DisposableBean
,InitializingBean
,Lifecycle
,Phased
,SmartLifecycle
public class ZeroMqProxy extends Object implements InitializingBean, SmartLifecycle, BeanNameAware, DisposableBean
The ZeroMqProxy.Type
dictates which pair of ZeroMQ sockets to bind with this proxy
to implement any possible patterns for ZeroMQ intermediary. Defaults to @link ZeroMqProxy.Type.PULL_PUSH
.
The control socket is exposed as a SocketType.PAIR
with an inter-thread transport
on the "inproc://" + beanName + ".control"
address; it can be obtained via getControlAddress()
.
Should be used with the same application from SocketType.PAIR
socket to send
ZMQ.PROXY_TERMINATE
, ZMQ.PROXY_PAUSE
and/or ZMQ.PROXY_RESUME
commands.
If the proxy cannot be started for some reason, an error message is logged and this component is left in the non-started state.
With an exposeCaptureSocket
option, an additional capture data socket is bound to inter-thread transport
as a SocketType.PUB
. There is no specific topic selection, so all the subscribers to this socket
must subscribe with plain ZMQ.SUBSCRIPTION_ALL
.
The address for this socket is "inproc://" + beanName + ".capture"
.
- Since:
- 5.4
- Author:
- Artem Bilan
- See Also:
ZMQ.proxy(ZMQ.Socket, ZMQ.Socket, ZMQ.Socket)
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ZeroMqProxy.Type
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ZeroMqProxy(org.zeromq.ZContext context)
Create aZeroMqProxy
instance based on the providedZContext
andZeroMqProxy.Type.PULL_PUSH
as default mode.ZeroMqProxy(org.zeromq.ZContext context, ZeroMqProxy.Type type)
-
Method Summary
Modifier and Type Method Description void
afterPropertiesSet()
void
destroy()
int
getBackendPort()
Return the port a backend socket is bound or null if this proxy has not been started yet.String
getCaptureAddress()
Return the address aninproc
capture socket is bound or null if this proxy has not been started yet orcaptureAddress
is false.String
getControlAddress()
Return the address aninproc
control socket is bound or null if this proxy has not been started yet.int
getFrontendPort()
Return the port a frontend socket is bound or 0 if this proxy has not been started yet.int
getPhase()
ZeroMqProxy.Type
getType()
boolean
isAutoStartup()
boolean
isRunning()
void
setAutoStartup(boolean autoStartup)
void
setBackendPort(int backendPort)
Specify a fixed port for backend socket of the proxy.void
setBackendSocketConfigurer(Consumer<org.zeromq.ZMQ.Socket> backendSocketConfigurer)
Provide aConsumer
to configure a proxy backend socket with arbitrary options, like security.void
setBeanName(String beanName)
void
setExposeCaptureSocket(boolean exposeCaptureSocket)
Whether to bind and expose a capture socket for the proxy data.void
setFrontendPort(int frontendPort)
Specify a fixed port for frontend socket of the proxy.void
setFrontendSocketConfigurer(Consumer<org.zeromq.ZMQ.Socket> frontendSocketConfigurer)
Provide aConsumer
to configure a proxy frontend socket with arbitrary options, like security.void
setPhase(int phase)
void
setProxyExecutor(Executor proxyExecutor)
Configure an executor to perform a ZeroMQ proxy loop.void
start()
void
stop()
-
Constructor Details
-
ZeroMqProxy
public ZeroMqProxy(org.zeromq.ZContext context)Create aZeroMqProxy
instance based on the providedZContext
andZeroMqProxy.Type.PULL_PUSH
as default mode.- Parameters:
context
- theZContext
to use
-
ZeroMqProxy
- Parameters:
context
- theZContext
to usetype
- theZeroMqProxy.Type
to use.
-
-
Method Details
-
setProxyExecutor
Configure an executor to perform a ZeroMQ proxy loop. The thread is held until ZeroMQ proxy loop is terminated. By default an internalExecutors.newSingleThreadExecutor()
instance is used.- Parameters:
proxyExecutor
- theExecutor
to use for ZeroMQ proxy loop
-
setFrontendPort
public void setFrontendPort(int frontendPort)Specify a fixed port for frontend socket of the proxy.- Parameters:
frontendPort
- the port to use; must be more than 0
-
setBackendPort
public void setBackendPort(int backendPort)Specify a fixed port for backend socket of the proxy.- Parameters:
backendPort
- the port to use; must be more than 0
-
setFrontendSocketConfigurer
public void setFrontendSocketConfigurer(@Nullable Consumer<org.zeromq.ZMQ.Socket> frontendSocketConfigurer)Provide aConsumer
to configure a proxy frontend socket with arbitrary options, like security.- Parameters:
frontendSocketConfigurer
- the configurer for frontend socket
-
setBackendSocketConfigurer
public void setBackendSocketConfigurer(@Nullable Consumer<org.zeromq.ZMQ.Socket> backendSocketConfigurer)Provide aConsumer
to configure a proxy backend socket with arbitrary options, like security.- Parameters:
backendSocketConfigurer
- the configurer for backend socket
-
setExposeCaptureSocket
public void setExposeCaptureSocket(boolean exposeCaptureSocket)Whether to bind and expose a capture socket for the proxy data.- Parameters:
exposeCaptureSocket
- true to bind capture socket for proxy
-
setBeanName
- Specified by:
setBeanName
in interfaceBeanNameAware
-
setAutoStartup
public void setAutoStartup(boolean autoStartup) -
setPhase
public void setPhase(int phase) -
getType
-
getFrontendPort
public int getFrontendPort()Return the port a frontend socket is bound or 0 if this proxy has not been started yet.- Returns:
- the port for a frontend socket or 0
-
getBackendPort
public int getBackendPort()Return the port a backend socket is bound or null if this proxy has not been started yet.- Returns:
- the port for a backend socket or 0
-
getControlAddress
Return the address aninproc
control socket is bound or null if this proxy has not been started yet.- Returns:
- the the address for control socket or null
-
getCaptureAddress
Return the address aninproc
capture socket is bound or null if this proxy has not been started yet orcaptureAddress
is false.- Returns:
- the the address for capture socket or null
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartup
in interfaceSmartLifecycle
-
getPhase
public int getPhase()- Specified by:
getPhase
in interfacePhased
- Specified by:
getPhase
in interfaceSmartLifecycle
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
start
public void start() -
stop
public void stop() -
isRunning
public boolean isRunning() -
destroy
public void destroy()- Specified by:
destroy
in interfaceDisposableBean
-