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

KafkaConsume accept array of string or RegExp #436

Merged
merged 9 commits into from
May 10, 2024

Conversation

demetris-manikas
Copy link
Contributor

This PR adds support for declaring an array of topics for a consumer.

@demetris-manikas
Copy link
Contributor Author

Needs a bit more work. I 'll let you know when is ready.

@demetris-manikas
Copy link
Contributor Author

It's ok now.
I had some problems creating a proper name for the group.
By the way I found out that names can contain only a-z, A-Z, 0-9, . (dot), _ (underscore), and - (dash)
and also one should not use both _ and .
Please make sure that naming suits you.
I ve left a console log in the code so that you can preview the generated thingy.

@Workflow()
static async testConsumeTopicsArray(_ctxt: WorkflowContext, topic: string, _partition: number, message: KafkaMessage) {
const isWfMessage = topic == wfTopic && message.value?.toString() === wfMessage;
const isTxnMessage = txnTopic && message.value?.toString() === txnMessage;
Copy link
Contributor

@kraftp kraftp May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be topic === txnTopic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Copy pasta mistake!

@@ -135,14 +142,26 @@ export class DBOSKafka {
}
}

safeGroupName(topics: Array<string | RegExp>) {
const res= topics.map(r => r.toString()).map( r=> r.replaceAll(/[^a-zA-Z0-9\\-]/g, '')).join('-');
Copy link
Contributor

@kraftp kraftp May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Contributor

@kraftp kraftp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change, just minor nits (and remove the console.log) and we can merge!

@demetris-manikas
Copy link
Contributor Author

Added a max length check as well.

Copy link
Contributor

@kraftp kraftp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@kraftp kraftp merged commit 5545eba into dbos-inc:main May 10, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants