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

Question: Trying to find the best way to join multiple topics #463

Open
Quinoa3 opened this issue Sep 11, 2024 · 1 comment
Open

Question: Trying to find the best way to join multiple topics #463

Quinoa3 opened this issue Sep 11, 2024 · 1 comment

Comments

@Quinoa3
Copy link

Quinoa3 commented Sep 11, 2024

I have three topics of distinct messages all with the same key of event id.
The goal is to aggregate the messages and when they all arrive to emit a combined message onto a new stream. Currently I have groups and the process Callback defined as follows. All three are similar.

func processPageView(ctx goka.Context, msg interface{}) {
	var pageView *message.PageViewMessage
	pageView = msg.(*message.PageViewMessage)
	baseEventValue := ctx.Join(baseEventTable)
	productInfoValue := ctx.Join(productInfoTable)
	if baseEventValue != nil && productInfoValue != nil {
		fullSignal := &message.FullSignal{}
		fullSignal.ProductInfoMessage = productInfoValue.(*message.ProductInfoMessage)
		fullSignal.BaseEventMessage = baseEventValue.(*message.BaseEventMessage)
		fullSignal.PageViewMessage = pageView
		ctx.Emit(fullSignalStream, ctx.Key(), fullSignal)
	} else {
		ctx.SetValue(pageView)
	}
}

func definePageViewGroup() *goka.GroupGraph {
	group := goka.DefineGroup(baseEventGroup,
		goka.Input(pageViewStream, new(codec.PageViewMessageCodec), processPageView),
		goka.Output(fullSignalStream, new(codec.FullSignalCodec)),
		goka.Join(baseEventTable, new(codec.BaseEventMessageCodec)),
		goka.Join(productInfoTable, new(codec.ProductInfoMessageCodec)),
		goka.Persist(new(codec.PageViewMessageCodec)),
	)
	return group
}

Is there a better way to do this?
My last issues is if one of the messages doesn't arrive how can I still emit a message with the data that does exist?
Thanks

@Quinoa3 Quinoa3 changed the title Trying to find the best way to join multiple topics Question: Trying to find the best way to join multiple topics Sep 13, 2024
@Quinoa3
Copy link
Author

Quinoa3 commented Sep 13, 2024

Also what is the best way to delete keys and values from other tables/groups?

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

1 participant