Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to use Kafka keys and headers in db inserts? #1653

Open
reidmeyer opened this issue Jun 21, 2024 · 2 comments
Open

Possible to use Kafka keys and headers in db inserts? #1653

reidmeyer opened this issue Jun 21, 2024 · 2 comments

Comments

@reidmeyer
Copy link

All of the examples for db sinks are like:

INSERT INTO accounts (username,city) VALUES (:#username,:#city)

where the username and city are key names in the json message from the kafka.

Is it possible to insert the kafka key or a kafka header (which is also json)?

@davsclaus
Copy link
Contributor

You can use camel simple language something ala :#${header.kafka.KEY}

@reidmeyer
Copy link
Author

HI @davsclaus,

Perhaps I'm missing something super obvious, but I'm struggling to get it to work.

I have a kafka message that:

has value:

{
	"message": "hello there reid"
}

has kafka headers:

{
	"myheader": "myheadervalue"
}

and has a key:

"some-key"

and I have a sql insert like:

camel.kamelet.postgresql-sink.query: 'INSERT INTO mytable (message,other) VALUES (:#message,:#${header.kafka.KEY})'

this doesn't inject anything into header.kafka.KEY, weirdly.

I'm trying to do something like:

camel.kamelet.postgresql-sink.query: 'INSERT INTO mytable (message,mykey,myheader) VALUES (:#message,:#${kafka.key},:#${kafka.header.myheader})', but no luck yet.

Do you know the solution here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants