Class KafkaShareMessageDrivenChannelAdapter<K,V>
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.endpoint.MessageProducerSupport
org.springframework.integration.kafka.inbound.KafkaShareMessageDrivenChannelAdapter<K,V>
- Type Parameters:
K- the key type.V- the value type.
- 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.ComponentSourceAware, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.context.OrderlyShutdownCapable, org.springframework.integration.core.MessageProducer, org.springframework.integration.IntegrationPattern, KafkaInboundEndpoint, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.IntegrationInboundManagement, org.springframework.integration.support.management.IntegrationManagement, org.springframework.integration.support.management.ManageableLifecycle, org.springframework.integration.support.management.ManageableSmartLifecycle, org.springframework.integration.support.management.TrackableComponent
public class KafkaShareMessageDrivenChannelAdapter<K,V>
extends org.springframework.integration.endpoint.MessageProducerSupport
implements KafkaInboundEndpoint, org.springframework.integration.context.OrderlyShutdownCapable
Message-driven channel adapter for Kafka share groups (KIP-932 queues), backed by a
AbstractShareKafkaMessageListenerContainer.
Share consumers support only explicit topics (no topic patterns or partition
assignment), no batch listeners, and no consumer seeks; this adapter therefore has
no ListenerMode and no retry template, and does not implement
Pausable. It also has no flag to leave a RecordFilterStrategy-discarded
record unacknowledged (unlike KafkaMessageDrivenChannelAdapter.setAckDiscarded(boolean)):
a discarded record is always terminally acknowledged, since an unacknowledged record in
a share group is simply redelivered to another consumer rather than left uncommitted.
The behavior depends on the container's ContainerProperties.ShareAckMode:
ContainerProperties.ShareAckMode.EXPLICIT(the default) andContainerProperties.ShareAckMode.IMPLICIT- the listener receives noShareAcknowledgment; the container itself sendsAcknowledgeType.ACCEPTafter the flow returns normally, and consults the container'sShareConsumerRecordRecoverer(default: reject) when the flow throws.ContainerProperties.ShareAckMode.MANUAL- theShareAcknowledgmentis provided in theKafkaHeaders.ACKNOWLEDGMENTmessage header (together with theKafkaHeaders.CONSUMERheader), and whichever flow receives the message is responsible for calling exactly one ofShareAcknowledgment.acknowledge(),ShareAcknowledgment.release(), orShareAcknowledgment.reject()on it. The container will not poll again - and will not stop - until every record from the current poll has been terminally acknowledged, so a flow that never acknowledges (or hands the message off without acknowledging) stalls the consumer thread permanently. This adapter acknowledges on the flow's behalf only when no flow ever received the message: it rejects a record that failed conversion, and accepts a record discarded by aRecordFilterStrategy.
- Since:
- 7.2
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
org.springframework.integration.support.management.IntegrationManagement.ManagementOverridesNested classes/interfaces inherited from interface KafkaInboundEndpoint
KafkaInboundEndpoint.RetryContext -
Field Summary
Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleLockFields 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 KafkaInboundEndpoint
ATTRIBUTES_HOLDER, CONTEXT_ACKNOWLEDGMENT, CONTEXT_CONSUMER, CONTEXT_RECORDFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionKafkaShareMessageDrivenChannelAdapter(org.springframework.kafka.listener.AbstractShareKafkaMessageListenerContainer<K, V> shareListenerContainer) Construct an instance with the provided container. -
Method Summary
Modifier and TypeMethodDescriptionintintprotected voiddoStart()protected voiddoStop()protected org.springframework.core.AttributeAccessorgetErrorMessageAttributes(@Nullable org.springframework.messaging.Message<?> message) protected voidonInit()voidsetBindSourceRecord(boolean bindSourceRecord) Set to true to bind the source consumer record in the header namedIntegrationMessageHeaderAccessor.SOURCE_DATA.voidsetPayloadType(Class<?> payloadType) When using a type-aware message converter such asStringJsonMessageConverter, set the payload type the converter should create.voidsetRecordFilterStrategy(org.springframework.kafka.listener.adapter.RecordFilterStrategy<K, V> recordFilterStrategy) Specify aRecordFilterStrategyto discard records before they are converted and sent.voidsetRecordMessageConverter(org.springframework.kafka.support.converter.RecordMessageConverter messageConverter) Set the message converter to use.Methods inherited from class org.springframework.integration.endpoint.MessageProducerSupport
afterSingletonsInstantiated, buildErrorMessage, getErrorChannel, getErrorMessageStrategy, getIntegrationPatternType, getMessagingTemplate, getOutputChannel, getOutputChannelName, getRequiredOutputChannel, isObserved, registerObservationRegistry, sendErrorMessageIfNecessary, sendMessage, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setObservationConvention, setOutputChannel, setOutputChannelName, setSendTimeout, setShouldTrack, subscribeToPublisherMethods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
destroy, 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, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
destroy, getManagedName, getManagedType, getOverrides, getThisAs, isLoggingEnabled, registerMetricsCaptor, setLoggingEnabled, setManagedName, setManagedTypeMethods inherited from interface KafkaInboundEndpoint
doWithRetryMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentNameMethods inherited from interface org.springframework.context.SmartLifecycle
isPauseable, pause, restart
-
Constructor Details
-
Method Details
-
setRecordMessageConverter
public void setRecordMessageConverter(org.springframework.kafka.support.converter.RecordMessageConverter messageConverter) Set the message converter to use.- Parameters:
messageConverter- the converter.
-
setRecordFilterStrategy
public void setRecordFilterStrategy(org.springframework.kafka.listener.adapter.RecordFilterStrategy<K, V> recordFilterStrategy) Specify aRecordFilterStrategyto discard records before they are converted and sent. A discarded record is terminally acknowledged (accepted) by this adapter when the container'sContainerProperties.ShareAckModeisMANUAL.- Parameters:
recordFilterStrategy- theRecordFilterStrategyto use.
-
setPayloadType
-
setBindSourceRecord
public void setBindSourceRecord(boolean bindSourceRecord) Set to true to bind the source consumer record in the header namedIntegrationMessageHeaderAccessor.SOURCE_DATA.- Parameters:
bindSourceRecord- true to bind.
-
getComponentType
- Specified by:
getComponentTypein interfaceorg.springframework.integration.support.context.NamedComponent- Overrides:
getComponentTypein classorg.springframework.integration.endpoint.MessageProducerSupport
-
onInit
protected void onInit()- Overrides:
onInitin classorg.springframework.integration.endpoint.MessageProducerSupport
-
doStart
protected void doStart()- Overrides:
doStartin classorg.springframework.integration.endpoint.MessageProducerSupport
-
doStop
protected void doStop()- Overrides:
doStopin classorg.springframework.integration.endpoint.MessageProducerSupport
-
beforeShutdown
public int beforeShutdown()- Specified by:
beforeShutdownin interfaceorg.springframework.integration.context.OrderlyShutdownCapable
-
afterShutdown
public int afterShutdown()- Specified by:
afterShutdownin interfaceorg.springframework.integration.context.OrderlyShutdownCapable
-
getErrorMessageAttributes
protected org.springframework.core.AttributeAccessor getErrorMessageAttributes(@Nullable org.springframework.messaging.Message<?> message) - Overrides:
getErrorMessageAttributesin classorg.springframework.integration.endpoint.MessageProducerSupport
-