How to read Kafka Message Header properties in Solace integrated Kafka Bridge receiver?

We have a requirement to read the Solace Topic information from Kafka Message Header properties? How can this be achieved using the substitution expression?

Using Solace version - Version 10.8.1.194

Hi there, I’m Solly AI, I generate responses to your questions using the power of the Solace Agent Mesh:

Please remember that AI technology can make mistakes so ensure that you read our Disclaimer.

AI Generated responses are a work in progress, your help in evaluating my response would be awesome! If my response makes sense, please mark it as a solution or give a :+1:. If my response doesn’t make sense for your topic, please react to it with a :shaking_face:.

Looking at the documentation, I can explain how to read Solace Topic information from Kafka Message Header properties using substitution expressions:

The Kafka receiver can access Kafka message header information using the following substitution expressions:

  1. ${kafkaHeader(<headerName>)} - Gets a header field from the Kafka message as bytes
  2. ${kafkaHeaderAsString(<headerName>)} - Gets a header field from the Kafka message as a string (bytes converted to ASCII characters)

When configuring a Kafka receiver topic binding, you can use these expressions in the Local Topic Expression to generate the SMF topic based on Kafka header values.

For example, if you want to use a Kafka header called “solaceTopic” as the SMF topic, you would configure:

Local Topic Expression: ${kafkaHeaderAsString("solaceTopic")}

Relevant source links:

1 Like

Thanks Solly AI, it worked!

2 Likes

Welcome back @kriishan_anz ! Glad you got this answer figured out. Feel free to share your use-case or any further follow up questions.

thanks @tamimi. I do have a follow-up question actually. How do we use wildcard kafka topics while configuring topic mapping for Kafka Receiver? For example - if the Kafka topic is ABC.DEF.GHI, can we use wildcard in Solace like ABC.*

Hi @kriishan_anz, when specifying the topic binding in the Kafka Receiver, you have a choice of providing the concrete name or a regex pattern. So while it would not be a * wildcard in the Solace style that you are used to, you can achieve a similar result with the right regular expression. The expressions may end up looking quite complicated - all depends on your topic taxonomy and exactly what part you want to wildcard.

First thing to clarify: Do you want the single level wildcard of * here, or the multi-level wildcard of >? Your regular expression would need to factor in each style of the Solace wildcard.

1 Like

Hi @JamilAhmed - thanks for the response. I was able to achieve the wild card behaviour using regex pattern.