Skip to content

How to get the name of the topic outside the kafkalistener? #2666

Answered by artembilan
hariraogotit asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you can add a RecordInterceptor to catch the listener call.
See AbstractMessageListenerContainer:

		/**
	 * Set an interceptor to be called before calling the record listener.
	 * Does not apply to batch listeners.
	 * @param recordInterceptor the interceptor.
	 * @since 2.2.7
	 * @see #setInterceptBeforeTx(boolean)
	 */
	public void setRecordInterceptor(RecordInterceptor<K, V> recordInterceptor) {

So, probably in the impl you can set some ThreadLocal value and get access to it downstream in your business logic if the listener method.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@hariraogotit
Comment options

@artembilan
Comment options

Answer selected by hariraogotit
@hariraogotit
Comment options

@artembilan
Comment options

@hariraogotit
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants