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.DurationDEFAULT_CONSUME_DELAYFields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLock -
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 voiddestroy()protected voiddoStart()protected voiddoStop()intgetBoundPort()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.StringgetComponentType()protected voidonInit()voidsetBindPort(int port)Configure a port for TCP protocol binding viaZMQ.Socket.bind(String).voidsetConnectUrl(java.lang.String connectUrl)Configure an URL forZMQ.Socket.connect(String).voidsetConsumeDelay(java.time.Duration consumeDelay)Specify aDurationto delay consumption when no data received.voidsetMessageConverter(org.springframework.messaging.converter.MessageConverter messageConverter)Provide aMessageConverter(as an alternative tomessageMapper) for converting a consumed data into a message to produce.voidsetMessageMapper(org.springframework.integration.mapping.InboundMessageMapper<byte[]> messageMapper)Provide anInboundMessageMapperto convert a consumed data into a message to produce.voidsetReceiveRaw(boolean receiveRaw)Whether rawZMsgis present as a payload of message to produce or it is fully converted to aMessageincludingZeroMqHeaders.TOPICheader (if any).voidsetSocketConfigurer(java.util.function.Consumer<org.zeromq.ZMQ.Socket> socketConfigurer)Provide aConsumerto configure a socket with arbitrary options, like security.voidsetTopics(java.lang.String... topics)Specify topics theSocketType.SUBsocket is going to use for subscription.voidsubscribeToTopics(java.lang.String... topics)voidunsubscribeFromTopics(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, subscribeToPublisherMethods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stopMethods 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
-
Field Details
-
DEFAULT_CONSUME_DELAY
public static final java.time.Duration DEFAULT_CONSUME_DELAY
-
-
Constructor Details
-
ZeroMqMessageProducer
public ZeroMqMessageProducer(org.zeromq.ZContext context) -
ZeroMqMessageProducer
public ZeroMqMessageProducer(org.zeromq.ZContext context, org.zeromq.SocketType socketType)
-
-
Method Details
-
setConsumeDelay
public void setConsumeDelay(java.time.Duration consumeDelay)Specify aDurationto delay consumption when no data received.- Parameters:
consumeDelay- theDurationto delay consumption when empty; defaults toDEFAULT_CONSUME_DELAY.
-
setMessageMapper
public void setMessageMapper(org.springframework.integration.mapping.InboundMessageMapper<byte[]> messageMapper)Provide anInboundMessageMapperto convert a consumed data into a message to produce. Ignored whensetReceiveRaw(boolean)istrue.- Parameters:
messageMapper- theInboundMessageMapperto use.
-
setMessageConverter
public void setMessageConverter(org.springframework.messaging.converter.MessageConverter messageConverter)Provide aMessageConverter(as an alternative tomessageMapper) for converting a consumed data into a message to produce. Ignored whensetReceiveRaw(boolean)istrue.- Parameters:
messageConverter- theMessageConverterto use.
-
setReceiveRaw
public void setReceiveRaw(boolean receiveRaw)Whether rawZMsgis present as a payload of message to produce or it is fully converted to aMessageincludingZeroMqHeaders.TOPICheader (if any).- Parameters:
receiveRaw- to convert fromZMsgor not; defaults to convert.
-
setSocketConfigurer
public void setSocketConfigurer(java.util.function.Consumer<org.zeromq.ZMQ.Socket> socketConfigurer)Provide aConsumerto 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 theSocketType.SUBsocket is going to use for subscription. It is ignored for all otherSocketTypes supported.- Parameters:
topics- the topics to use.
-
setConnectUrl
public void setConnectUrl(@Nullable java.lang.String connectUrl)Configure an URL forZMQ.Socket.connect(String). Mutually exclusive with thesetBindPort(int).- Parameters:
connectUrl- the URL to connect ZeroMq socket to.
-
setBindPort
public void setBindPort(int port)Configure a port for TCP protocol binding viaZMQ.Socket.bind(String). Mutually exclusive with thesetConnectUrl(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:
getComponentTypein interfaceorg.springframework.integration.support.context.NamedComponent- Overrides:
getComponentTypein classorg.springframework.integration.context.IntegrationObjectSupport
-
onInit
protected void onInit()- Overrides:
onInitin classorg.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:
doStartin classorg.springframework.integration.endpoint.MessageProducerSupport
-
doStop
protected void doStop()- Overrides:
doStopin classorg.springframework.integration.endpoint.MessageProducerSupport
-
destroy
public void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Overrides:
destroyin classorg.springframework.integration.endpoint.AbstractEndpoint
-