Class ZeroMqMessageHandler

All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Ordered, ExpressionCapable, Orderable, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, ReactiveMessageHandler

public class ZeroMqMessageHandler extends AbstractReactiveMessageHandler
The AbstractReactiveMessageHandler implementation for publishing messages over ZeroMq socket. Only SocketType.PAIR, SocketType.PUB and SocketType.PUSH are supported. This component is only connecting (no Binding) to another side, e.g. ZeroMq proxy.

When the SocketType.PUB is used, the topicExpression is evaluated against a request message to inject a topic frame into a ZeroMq message if it is not null. The subscriber side must receive the topic frame first before parsing the actual data.

When the payload of the request message is a ZMsg, no any conversion and topic extraction happen: the ZMsg is sent into a socket as is and it is not destroyed for possible further reusing.

Since:
5.4
Author:
Artem Bilan
  • Constructor Details

    • ZeroMqMessageHandler

      public ZeroMqMessageHandler(org.zeromq.ZContext context, String connectUrl)
      Create an instance based on the provided ZContext and connection string.
      Parameters:
      context - the ZContext to use for creating sockets.
      connectUrl - the URL to connect the socket to.
    • ZeroMqMessageHandler

      public ZeroMqMessageHandler(org.zeromq.ZContext context, String connectUrl, org.zeromq.SocketType socketType)
      Create an instance based on the provided ZContext, connection string and SocketType.
      Parameters:
      context - the ZContext to use for creating sockets.
      connectUrl - the URL to connect the socket to.
      socketType - the SocketType to use; only SocketType.PAIR, SocketType.PUB and SocketType.PUSH are supported.
  • Method Details

    • setMessageMapper

      public void setMessageMapper(OutboundMessageMapper<byte[]> messageMapper)
      Provide an OutboundMessageMapper to convert a request message into byte[] for sending into ZeroMq socket. Ignored when Message.getPayload() is an instance of ZMsg.
      Parameters:
      messageMapper - the OutboundMessageMapper to use.
    • setMessageConverter

      public void setMessageConverter(MessageConverter messageConverter)
      Provide a MessageConverter (as an alternative to messageMapper) for converting a request message into byte[] for sending into ZeroMq socket. Ignored when Message.getPayload() is an instance of ZMsg.
      Parameters:
      messageConverter - the MessageConverter to use.
    • setSocketConfigurer

      public void setSocketConfigurer(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.
    • setTopic

      public void setTopic(String topic)
      Specify a topic the SocketType.PUB socket is going to use for distributing messages into the subscriptions. It is ignored for all other SocketTypes supported.
      Parameters:
      topic - the topic to use.
    • setTopicExpression

      public void setTopicExpression(Expression topicExpression)
      Specify a SpEL expression to evaluate a topic a SocketType.PUB is going to use for distributing messages into the subscriptions.It is ignored for all other SocketTypes supported.
      Parameters:
      topicExpression - the expression to evaluate topic for publishing.
    • getComponentType

      public String getComponentType()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this method to provide component type information.
      Specified by:
      getComponentType in interface NamedComponent
      Overrides:
      getComponentType in class MessageHandlerSupport
    • onInit

      protected void onInit()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this for initialization logic.
      Overrides:
      onInit in class IntegrationObjectSupport
    • handleMessageInternal

      protected reactor.core.publisher.Mono<Void> handleMessageInternal(Message<?> message)
      Specified by:
      handleMessageInternal in class AbstractReactiveMessageHandler
    • destroy

      public void destroy()
      Specified by:
      destroy in interface DisposableBean
      Specified by:
      destroy in interface IntegrationManagement
      Overrides:
      destroy in class MessageHandlerSupport