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
FieldsFields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLockFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionZeroMqMessageProducer(org.zeromq.ZContext context) ZeroMqMessageProducer(org.zeromq.ZContext context, org.zeromq.SocketType socketType) -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()protected voiddoStart()protected voiddoStop()intReturn the port a socket is bound or 0 if this message producer has not been started yet or the socket is connected - not bound.protected voidonInit()voidsetBindPort(int port) Configure a port for TCP protocol binding viaZMQ.Socket.bind(String).voidsetConnectUrl(String connectUrl) Configure an URL forZMQ.Socket.connect(String).voidsetConsumeDelay(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(Consumer<org.zeromq.ZMQ.Socket> socketConfigurer) Provide aConsumerto configure a socket with arbitrary options, like security.voidSpecify topics theSocketType.SUBsocket is going to use for subscription.voidsubscribeToTopics(String... topics) voidunsubscribeFromTopics(String... topics) Methods inherited from class org.springframework.integration.endpoint.MessageProducerSupport
afterSingletonsInstantiated, buildErrorMessage, getErrorChannel, getErrorMessageAttributes, getErrorMessageStrategy, 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Field Details
-
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
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
Provide aConsumerto configure a socket with arbitrary options, like security.- Parameters:
socketConfigurer- the configurer for socket options.
-
setTopics
Specify topics theSocketType.SUBsocket is going to use for subscription. It is ignored for all otherSocketTypes supported.- Parameters:
topics- the topics to use.
-
setConnectUrl
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
- 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
-
unsubscribeFromTopics
-
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
-