Skip to main content
Rohit1997jio
Silver ⭐️⭐️⭐️
November 24, 2023
Question

send kafka topic as header when publishing data to another topic in NIFI

i want to send value of kafka.topic as header i.e (the topic from where i consumed message) to publish topic (another topic) by using publish processor.

But iam getting below error in publish processor- 

Screenshot1.pngScreenshot2.png

5 replies

joseomjr
Gold ⭐️⭐️
November 24, 2023

The error tells you it needs to be a regular expression matching the attribute you wish to send so if it's kafka.topic it could be that literally or more accurately would be kafka\.topic

Translate
Rohit1997jio
Silver ⭐️⭐️⭐️
November 26, 2023

kafka.topic is a key , it will have value of a kafka topic name e.g abc_xyz  .

this value will keep on depending from where iam consuming the meassge , from which topic .

my requirement is to send the topic from where i consumed as header to the topic where iam publishing it .

how can i do that ??

Translate
joseomjr
Gold ⭐️⭐️
November 27, 2023

Yes, the regular expression it's asking for is that of the attribute containing the value you want... It's not asking for the value. Since you want the value of the attribute kafka.topic (name/key) then this is what the regular expression you need to match. Have you tried just putting what I previously recommended "kafka\.topic"?

Translate
Rohit1997jio
Silver ⭐️⭐️⭐️
November 28, 2023

kafka\.topic  , i tried adding this  , but it did not work . I checked kafka headers too there also nothing being printed in haeder.

Translate
steven-matison
Platinum ⭐️⭐️
Platinum ⭐️⭐️
November 28, 2023

@joseomjr Is on to the right solution here.  Your regex statement should match "kafka.topic" not "${kafka.topic}".     A quick test in regex101.com confirms "kafka\.topic" should match.

Translate