Class ZeroMqMessageProducer

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.endpoint.MessageProducerSupport
org.springframework.integration.zeromq.inbound.ZeroMqMessageProducer
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.core.MessageProducer, org.springframework.integration.IntegrationPattern, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.ManageableLifecycle, org.springframework.integration.support.management.ManageableSmartLifecycle, org.springframework.integration.support.management.TrackableComponent

@ManagedResource
@IntegrationManagedResource
public class ZeroMqMessageProducer
extends org.springframework.integration.endpoint.MessageProducerSupport
A MessageProducerSupport implementation for consuming messages from ZeroMq socket. Only SocketType.PAIR, SocketType.SUB and SocketType.PULL are supported. This component can bind or connect the socket.

When the SocketType.SUB is used, the received topic is stored in the ZeroMqHeaders.TOPIC.

Since:
5.4
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.time.Duration DEFAULT_CONSUME_DELAY  

    Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint

    lifecycleCondition, lifecycleLock

    Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors 
    Constructor Description
    ZeroMqMessageProducer​(org.zeromq.ZContext context)  
    ZeroMqMessageProducer​(org.zeromq.ZContext context, org.zeromq.SocketType socketType)  
  • Method Summary

    Modifier and Type Method Description
    void destroy()  
    protected void doStart()  
    protected void doStop()  
    int getBoundPort()
    Return the port a socket is bound or 0 if this message producer has not been started yet or the socket is connected - not bound.
    java.lang.String getComponentType()  
    protected void onInit()  
    void setBindPort​(int port)
    Configure a port for TCP protocol binding via ZMQ.Socket.bind(String).
    void setConnectUrl​(java.lang.String connectUrl)
    Configure an URL for ZMQ.Socket.connect(String).
    void setConsumeDelay​(java.time.Duration consumeDelay)
    Specify a Duration to delay consumption when no data received.
    void setMessageConverter​(org.springframework.messaging.converter.MessageConverter messageConverter)
    Provide a MessageConverter (as an alternative to messageMapper) for converting a consumed data into a message to produce.
    void setMessageMapper​(org.springframework.integration.mapping.InboundMessageMapper<byte[]> messageMapper)
    Provide an InboundMessageMapper to convert a consumed data into a message to produce.
    void setReceiveRaw​(boolean receiveRaw)
    Whether raw ZMsg is present as a payload of message to produce or it is fully converted to a Message including ZeroMqHeaders.TOPIC header (if any).
    void setSocketConfigurer​(java.util.function.Consumer<org.zeromq.ZMQ.Socket> socketConfigurer)
    Provide a Consumer to configure a socket with arbitrary options, like security.
    void setTopics​(java.lang.String... topics)
    Specify topics the SocketType.SUB socket is going to use for subscription.
    void subscribeToTopics​(java.lang.String... topics)  
    void unsubscribeFromTopics​(java.lang.String... topics)  

    Methods inherited from class org.springframework.integration.endpoint.MessageProducerSupport

    afterSingletonsInstantiated, buildErrorMessage, getErrorChannel, getErrorMessageAttributes, getIntegrationPatternType, getMessagingTemplate, getOutputChannel, sendErrorMessageIfNecessary, sendMessage, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setOutputChannel, setOutputChannelName, setSendTimeout, setShouldTrack, subscribeToPublisher

    Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint

    doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stop

    Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport

    afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface org.springframework.integration.support.context.NamedComponent

    getBeanName, getComponentName
  • Field Details

  • Constructor Details

  • Method Details

    • setConsumeDelay

      public void setConsumeDelay​(java.time.Duration consumeDelay)
      Specify a Duration to delay consumption when no data received.
      Parameters:
      consumeDelay - the Duration to delay consumption when empty; defaults to DEFAULT_CONSUME_DELAY.
    • setMessageMapper

      public void setMessageMapper​(org.springframework.integration.mapping.InboundMessageMapper<byte[]> messageMapper)
      Provide an InboundMessageMapper to convert a consumed data into a message to produce. Ignored when setReceiveRaw(boolean) is true.
      Parameters:
      messageMapper - the InboundMessageMapper to use.
    • setMessageConverter

      public void setMessageConverter​(org.springframework.messaging.converter.MessageConverter messageConverter)
      Provide a MessageConverter (as an alternative to messageMapper) for converting a consumed data into a message to produce. Ignored when setReceiveRaw(boolean) is true.
      Parameters:
      messageConverter - the MessageConverter to use.
    • setReceiveRaw

      public void setReceiveRaw​(boolean receiveRaw)
      Whether raw ZMsg is present as a payload of message to produce or it is fully converted to a Message including ZeroMqHeaders.TOPIC header (if any).
      Parameters:
      receiveRaw - to convert from ZMsg or not; defaults to convert.
    • setSocketConfigurer

      public void setSocketConfigurer​(java.util.function.Consumer<org.zeromq.ZMQ.Socket> socketConfigurer)
      Provide a Consumer to configure a socket with arbitrary options, like security.
      Parameters:
      socketConfigurer - the configurer for socket options.
    • setTopics

      public void setTopics​(java.lang.String... topics)
      Specify topics the SocketType.SUB socket is going to use for subscription. It is ignored for all other SocketTypes supported.
      Parameters:
      topics - the topics to use.
    • setConnectUrl

      public void setConnectUrl​(@Nullable java.lang.String connectUrl)
      Configure an URL for ZMQ.Socket.connect(String). Mutually exclusive with the setBindPort(int).
      Parameters:
      connectUrl - the URL to connect ZeroMq socket to.
    • setBindPort

      public void setBindPort​(int port)
      Configure a port for TCP protocol binding via ZMQ.Socket.bind(String). Mutually exclusive with the setConnectUrl(String).
      Parameters:
      port - the port to bind ZeroMq socket to over TCP.
    • getBoundPort

      public int getBoundPort()
      Return the port a socket is bound or 0 if this message producer has not been started yet or the socket is connected - not bound.
      Returns:
      the port for a socket or 0.
    • getComponentType

      public java.lang.String getComponentType()
      Specified by:
      getComponentType in interface org.springframework.integration.support.context.NamedComponent
      Overrides:
      getComponentType in class org.springframework.integration.context.IntegrationObjectSupport
    • onInit

      protected void onInit()
      Overrides:
      onInit in class org.springframework.integration.endpoint.MessageProducerSupport
    • subscribeToTopics

      @ManagedOperation public void subscribeToTopics​(java.lang.String... topics)
    • unsubscribeFromTopics

      @ManagedOperation public void unsubscribeFromTopics​(java.lang.String... topics)
    • doStart

      protected void doStart()
      Overrides:
      doStart in class org.springframework.integration.endpoint.MessageProducerSupport
    • doStop

      protected void doStop()
      Overrides:
      doStop in class org.springframework.integration.endpoint.MessageProducerSupport
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Overrides:
      destroy in class org.springframework.integration.endpoint.AbstractEndpoint