Class ZeroMqMessageHandler
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractReactiveMessageHandler
org.springframework.integration.zeromq.outbound.ZeroMqMessageHandler
- 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.context.ApplicationContextAware,org.springframework.context.Lifecycle,org.springframework.core.Ordered,org.springframework.integration.context.ExpressionCapable,org.springframework.integration.context.Orderable,org.springframework.integration.IntegrationPattern,org.springframework.integration.support.context.NamedComponent,org.springframework.integration.support.management.IntegrationManagement,org.springframework.integration.support.management.ManageableLifecycle,org.springframework.integration.support.management.TrackableComponent,org.springframework.messaging.ReactiveMessageHandler
public class ZeroMqMessageHandler
extends org.springframework.integration.handler.AbstractReactiveMessageHandler
implements org.springframework.integration.support.management.ManageableLifecycle
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides -
Field Summary
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionZeroMqMessageHandler(org.zeromq.ZContext context, String connectUrl) Create an instance based on the providedZContextand connection string.ZeroMqMessageHandler(org.zeromq.ZContext context, String connectUrl, org.zeromq.SocketType socketType) Create an instance based on the providedZContext, connection string andSocketType.ZeroMqMessageHandler(org.zeromq.ZContext context, Supplier<String> connectUrl) Create an instance based on the providedZContextand connection string supplier.ZeroMqMessageHandler(org.zeromq.ZContext context, Supplier<String> connectUrl, org.zeromq.SocketType socketType) Create an instance based on the providedZContext, connection string supplier andSocketType. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()protected reactor.core.publisher.Mono<Void>handleMessageInternal(org.springframework.messaging.Message<?> message) booleanprotected voidonInit()voidsetMessageConverter(org.springframework.messaging.converter.MessageConverter messageConverter) Provide aMessageConverter(as an alternative tomessageMapper) for converting a request message intobyte[]for sending into ZeroMq socket.voidsetMessageMapper(org.springframework.integration.mapping.OutboundMessageMapper<byte[]> messageMapper) Provide anOutboundMessageMapperto convert a request message intobyte[]for sending into ZeroMq socket.voidsetSocketConfigurer(Consumer<org.zeromq.ZMQ.Socket> socketConfigurer) Provide aConsumerto configure a socket with arbitrary options, like security.voidSpecify a topic theSocketType.PUBsocket is going to use for distributing messages into the subscriptions.voidsetTopicExpression(org.springframework.expression.Expression topicExpression) Specify a SpEL expression to evaluate a topic aSocketType.PUBis going to use for distributing messages into the subscriptions.It is ignored for all otherSocketTypes supported.voidstart()voidstop()Methods inherited from class org.springframework.integration.handler.AbstractReactiveMessageHandler
handleMessageMethods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
ZeroMqMessageHandler
Create an instance based on the providedZContextand connection string.- Parameters:
context- theZContextto use for creating sockets.connectUrl- the URL to connect the socket to.
-
ZeroMqMessageHandler
Create an instance based on the providedZContextand connection string supplier.- Parameters:
context- theZContextto use for creating sockets.connectUrl- the supplier for URL to connect the socket to.- Since:
- 5.5.9
-
ZeroMqMessageHandler
public ZeroMqMessageHandler(org.zeromq.ZContext context, String connectUrl, org.zeromq.SocketType socketType) Create an instance based on the providedZContext, connection string andSocketType.- Parameters:
context- theZContextto use for creating sockets.connectUrl- the URL to connect the socket to.socketType- theSocketTypeto use; onlySocketType.PAIR,SocketType.PUBandSocketType.PUSHare supported.
-
ZeroMqMessageHandler
public ZeroMqMessageHandler(org.zeromq.ZContext context, Supplier<String> connectUrl, org.zeromq.SocketType socketType) Create an instance based on the providedZContext, connection string supplier andSocketType.- Parameters:
context- theZContextto use for creating sockets.connectUrl- the supplier for URL to connect the socket to.socketType- theSocketTypeto use; onlySocketType.PAIR,SocketType.PUBandSocketType.PUSHare supported.- Since:
- 5.5.9
-
-
Method Details
-
setMessageMapper
public void setMessageMapper(org.springframework.integration.mapping.OutboundMessageMapper<byte[]> messageMapper) Provide anOutboundMessageMapperto convert a request message intobyte[]for sending into ZeroMq socket. Ignored whenMessage.getPayload()is an instance ofZMsg.- Parameters:
messageMapper- theOutboundMessageMapperto use.
-
setMessageConverter
public void setMessageConverter(org.springframework.messaging.converter.MessageConverter messageConverter) Provide aMessageConverter(as an alternative tomessageMapper) for converting a request message intobyte[]for sending into ZeroMq socket. Ignored whenMessage.getPayload()is an instance ofZMsg.- Parameters:
messageConverter- theMessageConverterto use.
-
setSocketConfigurer
Provide aConsumerto configure a socket with arbitrary options, like security.- Parameters:
socketConfigurer- the configurer for socket options.
-
setTopic
Specify a topic theSocketType.PUBsocket is going to use for distributing messages into the subscriptions. It is ignored for all otherSocketTypes supported.- Parameters:
topic- the topic to use.
-
setTopicExpression
public void setTopicExpression(org.springframework.expression.Expression topicExpression) Specify a SpEL expression to evaluate a topic aSocketType.PUBis going to use for distributing messages into the subscriptions.It is ignored for all otherSocketTypes supported.- Parameters:
topicExpression- the expression to evaluate topic for publishing.
-
getComponentType
- Specified by:
getComponentTypein interfaceorg.springframework.integration.support.context.NamedComponent- Overrides:
getComponentTypein classorg.springframework.integration.handler.MessageHandlerSupport
-
onInit
protected void onInit()- Overrides:
onInitin classorg.springframework.integration.context.IntegrationObjectSupport
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle- Specified by:
startin interfaceorg.springframework.integration.support.management.ManageableLifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle- Specified by:
stopin interfaceorg.springframework.integration.support.management.ManageableLifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle- Specified by:
isRunningin interfaceorg.springframework.integration.support.management.ManageableLifecycle
-
handleMessageInternal
protected reactor.core.publisher.Mono<Void> handleMessageInternal(org.springframework.messaging.Message<?> message) - Specified by:
handleMessageInternalin classorg.springframework.integration.handler.AbstractReactiveMessageHandler
-
destroy
public void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Specified by:
destroyin interfaceorg.springframework.integration.support.management.IntegrationManagement- Overrides:
destroyin classorg.springframework.integration.handler.MessageHandlerSupport
-