Class ZeroMqProxy
- All Implemented Interfaces:
Aware,BeanNameAware,DisposableBean,InitializingBean,Lifecycle,Phased,SmartLifecycle
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 -
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionZeroMqProxy(org.zeromq.ZContext context) Create aZeroMqProxyinstance based on the providedZContextandZeroMqProxy.Type.PULL_PUSHas default mode.ZeroMqProxy(org.zeromq.ZContext context, ZeroMqProxy.Type type) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoiddestroy()intReturn the port a backend socket is bound or null if this proxy has not been started yet.Return the address aninproccapture socket is bound or null if this proxy has not been started yet orcaptureAddressis false.Return the address aninproccontrol socket is bound or null if this proxy has not been started yet.intReturn the port a frontend socket is bound or 0 if this proxy has not been started yet.intgetPhase()getType()booleanbooleanvoidsetAutoStartup(boolean autoStartup) voidsetBackendPort(int backendPort) Specify a fixed port for backend socket of the proxy.voidsetBackendSocketConfigurer(Consumer<org.zeromq.ZMQ.Socket> backendSocketConfigurer) Provide aConsumerto configure a proxy backend socket with arbitrary options, like security.voidsetBeanName(String beanName) voidsetExposeCaptureSocket(boolean exposeCaptureSocket) Whether to bind and expose a capture socket for the proxy data.voidsetFrontendPort(int frontendPort) Specify a fixed port for frontend socket of the proxy.voidsetFrontendSocketConfigurer(Consumer<org.zeromq.ZMQ.Socket> frontendSocketConfigurer) Provide aConsumerto configure a proxy frontend socket with arbitrary options, like security.voidsetPhase(int phase) voidsetProxyExecutor(Executor proxyExecutor) Configure an executor to perform a ZeroMQ proxy loop.voidstart()voidstop()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
stop
-
Constructor Details
-
ZeroMqProxy
public ZeroMqProxy(org.zeromq.ZContext context) Create aZeroMqProxyinstance based on the providedZContextandZeroMqProxy.Type.PULL_PUSHas default mode.- Parameters:
context- theZContextto use
-
ZeroMqProxy
- Parameters:
context- theZContextto usetype- theZeroMqProxy.Typeto 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- theExecutorto 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 aConsumerto 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 aConsumerto 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:
setBeanNamein 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 aninproccontrol socket is bound or null if this proxy has not been started yet.- Returns:
- the address for control socket or null
-
getCaptureAddress
Return the address aninproccapture socket is bound or null if this proxy has not been started yet orcaptureAddressis false.- Returns:
- the address for capture socket or null
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceSmartLifecycle
-
getPhase
public int getPhase()- Specified by:
getPhasein interfacePhased- Specified by:
getPhasein interfaceSmartLifecycle
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
start
public void start() -
stop
public void stop() -
isRunning
public boolean isRunning() -
destroy
public void destroy()- Specified by:
destroyin interfaceDisposableBean
-