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:
Aware,BeanFactoryAware,BeanNameAware,DisposableBean,InitializingBean,SmartInitializingSingleton,ApplicationContextAware,Lifecycle,Phased,SmartLifecycle,ComponentSourceAware,ExpressionCapable,OrderlyShutdownCapable,MessageProducer,IntegrationPattern,KafkaInboundEndpoint,NamedComponent,IntegrationInboundManagement,IntegrationManagement,ManageableLifecycle,ManageableSmartLifecycle,TrackableComponent
public class KafkaShareMessageDrivenChannelAdapter<K,V>
extends MessageProducerSupport
implements KafkaInboundEndpoint, 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
- Author:
- Artem Bilan
- See Also:
-
AbstractShareKafkaMessageListenerContainerShareAcknowledgment
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverridesNested classes/interfaces inherited from interface org.springframework.integration.kafka.inbound.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 org.springframework.integration.kafka.inbound.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 TypeMethodDescriptionintCalled after normal shutdown of schedulers, executors etc, and after the shutdown delay has elapsed, but before any forced shutdown of any remaining active scheduler/executor threads.Can optionally return the number of active messages still in process.intCalled before shutdown begins.protected voiddoStart()Take no action by default.protected voiddoStop()Take no action by default.protected AttributeAccessorgetErrorMessageAttributes(@Nullable Message<?> message) Populate anAttributeAccessorto be used when building an error message with theerrorMessageStrategy.protected voidonInit()Subclasses may implement this for initialization logic.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 java.lang.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 org.springframework.integration.kafka.inbound.KafkaInboundEndpoint
doWithRetryMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentNameMethods inherited from interface org.springframework.context.SmartLifecycle
isPauseable
-
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
When using a type-aware message converter such asStringJsonMessageConverter, set the payload type the converter should create. Defaults toObject.- Parameters:
payloadType- the type.
-
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 interfaceNamedComponent- Overrides:
getComponentTypein classMessageProducerSupport
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classMessageProducerSupport
-
doStart
protected void doStart()Description copied from class:MessageProducerSupportTake no action by default. Subclasses may override this if they need lifecycle-managed behavior. Protected by 'lifecycleLock'.- Overrides:
doStartin classMessageProducerSupport
-
doStop
protected void doStop()Description copied from class:MessageProducerSupportTake no action by default. Subclasses may override this if they need lifecycle-managed behavior.- Overrides:
doStopin classMessageProducerSupport
-
beforeShutdown
public int beforeShutdown()Description copied from interface:OrderlyShutdownCapableCalled before shutdown begins. Implementations should stop accepting new messages. Can optionally return the number of active messages in process.- Specified by:
beforeShutdownin interfaceOrderlyShutdownCapable- Returns:
- The number of active messages if available.
-
afterShutdown
public int afterShutdown()Description copied from interface:OrderlyShutdownCapableCalled after normal shutdown of schedulers, executors etc, and after the shutdown delay has elapsed, but before any forced shutdown of any remaining active scheduler/executor threads.Can optionally return the number of active messages still in process.- Specified by:
afterShutdownin interfaceOrderlyShutdownCapable- Returns:
- The number of active messages if available.
-
getErrorMessageAttributes
Description copied from class:MessageProducerSupportPopulate anAttributeAccessorto be used when building an error message with theerrorMessageStrategy.- Overrides:
getErrorMessageAttributesin classMessageProducerSupport- Parameters:
message- the message.- Returns:
- the attributes.
-