Class ZeroMqProxy

java.lang.Object
org.springframework.integration.zeromq.ZeroMqProxy
All Implemented Interfaces:
Aware, BeanNameAware, DisposableBean, InitializingBean, Lifecycle, Phased, SmartLifecycle

public class ZeroMqProxy extends Object implements InitializingBean, SmartLifecycle, BeanNameAware, DisposableBean
This class encapsulates the logic to configure and manage a ZeroMQ proxy. It binds frontend and backend sockets over TCP on all the available network interfaces with either provided or randomly selected ports.

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, Christian Tzolov
See Also:
  • ZMQ.proxy(ZMQ.Socket, ZMQ.Socket, ZMQ.Socket)
  • Constructor Details

  • Method Details

    • setProxyExecutor

      public void setProxyExecutor(Executor proxyExecutor)
      Configure an executor to perform a ZeroMQ proxy loop. The thread is held until ZeroMQ proxy loop is terminated. By default, an internal Executors.newSingleThreadExecutor() instance is used.
      Parameters:
      proxyExecutor - the Executor 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 a Consumer 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 a Consumer 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

      public void setBeanName(String beanName)
      Specified by:
      setBeanName in interface BeanNameAware
    • setAutoStartup

      public void setAutoStartup(boolean autoStartup)
    • setPhase

      public void setPhase(int phase)
    • getType

      public ZeroMqProxy.Type 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

      @Nullable public String getControlAddress()
      Return the address an inproc control socket is bound or null if this proxy has not been started yet.
      Returns:
      the address for control socket or null
    • getCaptureAddress

      @Nullable public String getCaptureAddress()
      Return the address an inproc capture socket is bound or null if this proxy has not been started yet or captureAddress is false.
      Returns:
      the address for capture socket or null
    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface SmartLifecycle
    • getPhase

      public int getPhase()
      Specified by:
      getPhase in interface Phased
      Specified by:
      getPhase in interface SmartLifecycle
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface InitializingBean
    • start

      public void start()
      Specified by:
      start in interface Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface Lifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface Lifecycle
    • destroy

      public void destroy()
      Specified by:
      destroy in interface DisposableBean