Class ZeroMqProxy

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

public class ZeroMqProxy
extends java.lang.Object
implements org.springframework.beans.factory.InitializingBean, org.springframework.context.SmartLifecycle, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.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
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

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors 
    Constructor Description
    ZeroMqProxy​(org.zeromq.ZContext context)
    Create a ZeroMqProxy instance based on the provided ZContext and ZeroMqProxy.Type.PULL_PUSH as default mode.
    ZeroMqProxy​(org.zeromq.ZContext context, ZeroMqProxy.Type type)
    Create a ZeroMqProxy instance based on the provided ZContext and ZeroMqProxy.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.
    java.lang.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.
    java.lang.String getControlAddress()
    Return the address an inproc 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​(java.util.function.Consumer<org.zeromq.ZMQ.Socket> backendSocketConfigurer)
    Provide a Consumer to configure a proxy backend socket with arbitrary options, like security.
    void setBeanName​(java.lang.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​(java.util.function.Consumer<org.zeromq.ZMQ.Socket> frontendSocketConfigurer)
    Provide a Consumer to configure a proxy frontend socket with arbitrary options, like security.
    void setPhase​(int phase)  
    void setProxyExecutor​(java.util.concurrent.Executor proxyExecutor)
    Configure an executor to perform a ZeroMQ proxy loop.
    void start()  
    void stop()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.context.SmartLifecycle

    stop
  • Constructor Details

  • Method Details

    • setProxyExecutor

      public void setProxyExecutor​(java.util.concurrent.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 java.util.function.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 java.util.function.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​(java.lang.String beanName)
      Specified by:
      setBeanName in interface org.springframework.beans.factory.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 java.lang.String getControlAddress()
      Return the address an inproc control socket is bound or null if this proxy has not been started yet.
      Returns:
      the the address for control socket or null
    • getCaptureAddress

      @Nullable public java.lang.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 the address for capture socket or null
    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface org.springframework.context.SmartLifecycle
    • getPhase

      public int getPhase()
      Specified by:
      getPhase in interface org.springframework.context.Phased
      Specified by:
      getPhase in interface org.springframework.context.SmartLifecycle
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean