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

Can I Emit to a KTable? #344

Closed
pfortin-urbn opened this issue Aug 26, 2021 · 4 comments
Closed

Can I Emit to a KTable? #344

pfortin-urbn opened this issue Aug 26, 2021 · 4 comments

Comments

@pfortin-urbn
Copy link

pfortin-urbn commented Aug 26, 2021

@frairon - I am in a processor and it has received a message to update the KTable but it could be for another key that the context key. Can I use ctx.Emit to update the KTable and if I do that will local storage also be updated? What is the preferred way to update the state of a key that is determined in the processor?

@jomaresch
Copy link
Contributor

Hey @pfortin-urbn.

I think the ctx.Loopback() function can solve this.

goka/context.go

Line 117 in 15746b5

Loopback(key string, value interface{}, options ...ContextOption)

So if you receive a message with the key key_a and you want to update the stored value of key_b you can loopback the message to key_b using ctx.Loopback("key_b", updateMessage).
In the Loop-Edge you define how to update the value.

goka/graph.go

Line 324 in 0085fa7

func Loop(c Codec, cb ProcessCallback) Edge {

Here is also a good example.
Based on one input message, we update the values of 2 different keys (the receiver_id and sender_id).

I hope this helps 🙂

@db7
Copy link
Collaborator

db7 commented Sep 1, 2021

By KTable do you mean a KTable of Kafka Streams? If yes, you'll need to configure the hash function since Sarama uses a different hash function than the Java clients. You'll need to create an emitter, configure the hash function (murmur2 AFAIR) and pass the emitter object to the process callback.

@jomaresch
Copy link
Contributor

Oh sorry for the confusion. Somehow i totally missed the KTable part.

@pfortin-urbn
Copy link
Author

@db7 Thanks I kinda knew that but wanted to know if there was easier way thanks!

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

3 participants