クラス KafkaMessageSource<K,V>
java.lang.ObjectSE
org.springframework.integration.util.AbstractExpressionEvaluator
org.springframework.integration.endpoint.AbstractMessageSource<ObjectSE>
org.springframework.integration.kafka.inbound.KafkaMessageSource<K,V>
- 型パラメーター:
K- 鍵の型。V- 値の型。
- 実装済みのインターフェース一覧:
Aware、BeanClassLoaderAware、BeanFactoryAware、BeanNameAware、DisposableBean、InitializingBean、Lifecycle、MessageSource<ObjectSE>、Pausable、IntegrationPattern、NamedComponent、IntegrationInboundManagement、IntegrationManagement、ManageableLifecycle
public class KafkaMessageSource<K,V>
extends AbstractMessageSource<ObjectSE>
implements Pausable, BeanClassLoaderAware
Apache Kafka のポーリングされたメッセージソース。一度に 1 つのスレッドだけがデータをポーリング (またはメッセージを確認) できます。
NOTE: アプリケーションがメッセージの順序が正しくないことを確認した場合、オフセットの前のすべてのメッセージが確認応答されるまで、確認応答は延期されます。複数のレコードが取得され、以前のオフセットが再キューイングされた場合、後続のオフセットからのレコードは、正常に処理された場合でも再配信されます。アプリケーションはべき等性を実装する必要があります。
バージョン 3.1.2 以降、このソースは Pausable を実装しており、Consumer を一時停止および再開できます。コンシューマーが一時停止している間、リバランスを防ぐために、max.poll.interval.ms 内で AbstractMessageSource.receive() を呼び出し続ける必要があります。
- 導入:
- 5.4
- 作成者:
- Gary Russell, Mark Norkin, Artem Bilan, Anshul Mehra, Christian Tzolov, Ngoc Nhan
ネストされたクラスの概要
ネストされたクラス修飾子と型クラス説明static classKafka の場合は AcknowledgmentCallback。static final recordKafkaAckInfo の場合は AcknowledgmentCallbackFactory。static interfaceKafkaAckCallback を構築するための情報。classKafkaAckCallback を構築するための情報。インターフェース org.springframework.integration.support.management.IntegrationManagement から継承されたネストクラス / インターフェース
IntegrationManagement.ManagementOverridesフィールド概要
フィールドクラス org.springframework.integration.util.AbstractExpressionEvaluator から継承されたフィールド
EXPRESSION_PARSER, loggerインターフェース org.springframework.integration.support.management.IntegrationManagement から継承されたフィールド
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEコンストラクター概要
コンストラクターコンストラクター説明KafkaMessageSource(org.springframework.kafka.core.ConsumerFactory<K, V> consumerFactory, org.springframework.kafka.listener.ConsumerProperties consumerProperties) 指定されたパラメーターを使用してインスタンスを作成します。KafkaMessageSource(org.springframework.kafka.core.ConsumerFactory<K, V> consumerFactory, org.springframework.kafka.listener.ConsumerProperties consumerProperties, boolean allowMultiFetch) 指定されたパラメーターを使用してインスタンスを作成します。KafkaMessageSource(org.springframework.kafka.core.ConsumerFactory<K, V> consumerFactory, org.springframework.kafka.listener.ConsumerProperties consumerProperties, KafkaMessageSource.KafkaAckCallbackFactory<K, V> ackCallbackFactory) 指定されたパラメーターを使用してインスタンスを作成します。KafkaMessageSource(org.springframework.kafka.core.ConsumerFactory<K, V> consumerFactory, org.springframework.kafka.listener.ConsumerProperties consumerProperties, KafkaMessageSource.KafkaAckCallbackFactory<K, V> ackCallbackFactory, boolean allowMultiFetch) 指定されたパラメーターを使用してインスタンスを作成します。方法の概要
修飾子と型メソッド説明protected voidvoiddestroy()protected ObjectSEサブクラスはこのメソッドを実装する必要があります。CollectionSE<org.apache.kafka.common.TopicPartition>現在割り当てられているパーティションを返します。protected StringSEprotected DurationSEorg.springframework.kafka.listener.ConsumerProperties構成されたコンシューマープロパティへの参照を取得します。ソースを開始する前に、プロパティをさらにカスタマイズできます。protected StringSEprotected org.springframework.kafka.support.converter.RecordMessageConverterprotected ClassSE<?>protected longprotected org.apache.kafka.clients.consumer.ConsumerRebalanceListenerbooleanisPaused()エンドポイントが一時停止しているかどうかを確認します。protected booleanbooleanprotected voidonInit()voidpause()エンドポイントを一時停止します。voidresume()一時停止した場合は、エンドポイントを再開します。voidsetBeanClassLoader(ClassLoaderSE classLoader) voidsetCloseTimeout(DurationSE closeTimeout) クローズタイムアウトを設定します。デフォルトは 30 秒です。voidsetMessageConverter(org.springframework.kafka.support.converter.RecordMessageConverter messageConverter) デフォルトのMessagingMessageConverterを置き換えるようにメッセージコンバーターを設定します。voidsetPayloadType(ClassSE<?> payloadType) ペイロード型を設定します。voidsetRawMessageHeader(boolean rawMessageHeader) true に設定すると、生のConsumerRecordがキーKafkaHeaders.RAW_DATAおよびIntegrationMessageHeaderAccessor.SOURCE_DATAのヘッダーとして含まれます。voidstart()voidstop()クラス org.springframework.integration.endpoint.AbstractMessageSource から継承されたメソッド
buildMessage, getBeanName, getComponentName, getManagedName, getManagedType, getOverrides, isLoggingEnabled, receive, registerMetricsCaptor, setBeanName, setHeaderExpressions, setLoggingEnabled, setManagedName, setManagedTypeクラス org.springframework.integration.util.AbstractExpressionEvaluator から継承されたメソッド
afterPropertiesSet, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, getBeanFactory, getEvaluationContext, getEvaluationContext, getMessageBuilderFactory, setBeanFactory, setConversionService, setSimpleEvaluationContextクラス java.lang.ObjectSE から継承されたメソッド
clone, equalsSE, finalize, getClass, hashCode, notify, notifyAll, toString, wait, waitSE, waitSEインターフェース org.springframework.integration.support.management.IntegrationManagement から継承されたメソッド
getThisAs, isObserved, registerObservationRegistryインターフェース org.springframework.integration.core.MessageSource から継承されたメソッド
getIntegrationPatternType
フィールドの詳細
REMAINING_RECORDS
前回のポーリングから残っているレコードの数。- 導入:
- 3.2
- 関連事項:
newAssignment
public volatile boolean newAssignment
コンストラクターの詳細
KafkaMessageSource
public KafkaMessageSource(org.springframework.kafka.core.ConsumerFactory<K, V> consumerFactory, org.springframework.kafka.listener.ConsumerProperties consumerProperties) 指定されたパラメーターを使用してインスタンスを作成します。ポーリングごとに複数のレコードをフェッチすることは無効になります。- パラメーター:
consumerFactory- コンシューマーファクトリ。consumerProperties- コンシューマーの特性。- 関連事項:
KafkaMessageSource
public KafkaMessageSource(org.springframework.kafka.core.ConsumerFactory<K, V> consumerFactory, org.springframework.kafka.listener.ConsumerProperties consumerProperties, boolean allowMultiFetch) 指定されたパラメーターを使用してインスタンスを構築します。各ポーリングで最大max.poll.recordsを取得できるようにするには、"allowMultiFetch" を true に設定します。false (デフォルト) の場合、コンシューマーファクトリがDefaultKafkaConsumerFactoryの場合はmax.poll.recordsが 1 に強制変換され、それ以外の場合はIllegalArgumentExceptionSE で拒否されます。重要: true の場合、max.poll.interval.ms内で受信したレコード数を消費するのに十分な速度でAbstractMessageSource.receive()を呼び出す必要があります。false の場合、max.poll.interval.ms内でAbstractMessageSource.receive()を呼び出す必要があります。pause()は、前回のポーリングのレコードが消費されるまで有効になりません。- パラメーター:
consumerFactory- コンシューマーファクトリ。consumerProperties- コンシューマーの特性。allowMultiFetch-max.poll.records > 1を許可する場合は true。
KafkaMessageSource
public KafkaMessageSource(org.springframework.kafka.core.ConsumerFactory<K, V> consumerFactory, org.springframework.kafka.listener.ConsumerProperties consumerProperties, KafkaMessageSource.KafkaAckCallbackFactory<K, V> ackCallbackFactory) 指定されたパラメーターを使用してインスタンスを作成します。ポーリングごとに複数のレコードをフェッチすることは無効になります。- パラメーター:
consumerFactory- コンシューマーファクトリ。consumerProperties- コンシューマーの特性。ackCallbackFactory- ack コールバックファクトリ。- 関連事項:
KafkaMessageSource
public KafkaMessageSource(org.springframework.kafka.core.ConsumerFactory<K, V> consumerFactory, org.springframework.kafka.listener.ConsumerProperties consumerProperties, KafkaMessageSource.KafkaAckCallbackFactory<K, V> ackCallbackFactory, boolean allowMultiFetch) 指定されたパラメーターを使用してインスタンスを構築します。各ポーリングで最大max.poll.recordsを取得できるようにするには、"allowMultiFetch" を true に設定します。false (デフォルト) の場合、コンシューマーファクトリがDefaultKafkaConsumerFactoryの場合はmax.poll.recordsが 1 に強制変換され、それ以外の場合はIllegalArgumentExceptionSE で拒否されます。重要: true の場合、max.poll.interval.ms内で受信したレコード数を消費するのに十分な速度でAbstractMessageSource.receive()を呼び出す必要があります。false の場合、max.poll.interval.ms内でAbstractMessageSource.receive()を呼び出す必要があります。pause()は、前回のポーリングのレコードが消費されるまで有効になりません。- パラメーター:
consumerFactory- コンシューマーファクトリ。consumerProperties- コンシューマーの特性。ackCallbackFactory- ack コールバックファクトリ。allowMultiFetch-max.poll.records > 1を許可する場合は true。
方法の詳細
getAssignedPartitions
現在割り当てられているパーティションを返します。- 戻り値:
- パーティション。
setBeanClassLoader
- 次で指定:
- インターフェース
BeanClassLoaderAware内のsetBeanClassLoader
onInit
protected void onInit()- オーバーライド:
- クラス
AbstractExpressionEvaluatorのonInit
getConsumerProperties
public org.springframework.kafka.listener.ConsumerProperties getConsumerProperties()構成されたコンシューマープロパティへの参照を取得します。ソースを開始する前に、プロパティをさらにカスタマイズできます。- 戻り値:
- プロパティ。
getGroupId
getClientId
getPollTimeout
protected long getPollTimeout()getMessageConverter
protected org.springframework.kafka.support.converter.RecordMessageConverter getMessageConverter()setMessageConverter
public void setMessageConverter(org.springframework.kafka.support.converter.RecordMessageConverter messageConverter) デフォルトのMessagingMessageConverterを置き換えるようにメッセージコンバーターを設定します。- パラメーター:
messageConverter- コンバーター。
getPayloadType
setPayloadType
ペイロード型を設定します。型対応のメッセージコンバーターが提供されている場合にのみ適用されます。- パラメーター:
payloadType- 変換する型。
getRebalanceListener
protected org.apache.kafka.clients.consumer.ConsumerRebalanceListener getRebalanceListener()getComponentType
- 次で指定:
- インターフェース
NamedComponent内のgetComponentType
isRawMessageHeader
protected boolean isRawMessageHeader()setRawMessageHeader
public void setRawMessageHeader(boolean rawMessageHeader) true に設定すると、生のConsumerRecordがキーKafkaHeaders.RAW_DATAおよびIntegrationMessageHeaderAccessor.SOURCE_DATAのヘッダーとして含まれます。呼び出し元がレコードにアクセスしてエラーを処理できるようにします。- パラメーター:
rawMessageHeader- ヘッダーを含める場合は true。
getCommitTimeout
setCloseTimeout
クローズタイムアウトを設定します。デフォルトは 30 秒です。- パラメーター:
closeTimeout- クローズタイムアウト。
isRunning
public boolean isRunning()- 次で指定:
- インターフェース
Lifecycle内のisRunning - 次で指定:
- インターフェース
ManageableLifecycle内のisRunning
start
public void start()- 次で指定:
- インターフェース
Lifecycle内のstart - 次で指定:
- インターフェース
ManageableLifecycle内のstart
stop
public void stop()- 次で指定:
- インターフェース
Lifecycle内のstop - 次で指定:
- インターフェース
ManageableLifecycle内のstop
pause
public void pause()インターフェースからコピーされた説明:Pausableエンドポイントを一時停止します。resume
public void resume()インターフェースからコピーされた説明:Pausable一時停止した場合は、エンドポイントを再開します。isPaused
public boolean isPaused()インターフェースからコピーされた説明:Pausableエンドポイントが一時停止しているかどうかを確認します。doReceive
クラスからコピーされた説明:AbstractMessageSourceサブクラスはこのメソッドを実装する必要があります。通常、返される値は型 T のpayloadになりますが、返される値はペイロードが型 T であるMessageインスタンスである場合もあります。また、追加のヘッダーの設定に使用されるAbstractIntegrationMessageBuilderである場合もあります。- 次で指定:
- クラス
AbstractMessageSource<ObjectSE>のdoReceive - 戻り値:
- 返された値。
createConsumer
protected void createConsumer()destroy
public void destroy()- 次で指定:
- インターフェース
DisposableBean内のdestroy - 次で指定:
- インターフェース
IntegrationManagement内のdestroy - オーバーライド:
- クラス
AbstractMessageSource<ObjectSE>のdestroy