feat(api): support wildcard topic subscriptions#912
Conversation
alexluong
left a comment
There was a problem hiding this comment.
Heya, overall looks great and we should be quite close!
A few notes
1: I see we're not changing the portal (internal/portal) yet. Do you intend for that to be out of scope of this PR?
2: There's this case on the List Destination API where we can run GET /tenants/X/destinations?topics=user.created. I wonder what the behavior for this should be with wildcard support.
3: We should add tests to make sure destination with wildcard topics will be matched properly in event delivery (via /publish). I can also help commit the test for this if you prefer.
|
awesome @alexluong about the portal stuff.. i think i might let the team decide on how the ui would evolve. as @alexbouchardd pointed out. the current topic input can't really accommodate it cleanly.
i might play around with something.. but i'm not going to be making any decisions on that |
|
You can maybe map the top-level A bigger issue with just ignoring it is that the UI may break if the user uses the API to set their topics with a wildcard and then later loads the UI |

Summary
adds support for wildcard patterns in destination topic subscriptions.
destinations can now subscribe to topic families using
*inside a topic string, for example:user.**.createdorder.*.completedexact topic subscriptions keep the existing behavior, and
"*"still means subscribe to all topics.closes #908
Behavior
*inside a topic string matches any run of characters, separator-agnostic.examples:
user.*matchesuser.createduser.*matchesuser.profile.updated*.createdmatchesuser.createdandorder.createdorder.*.completedmatchesorder.payment.completedpublished event topics are still exact topic strings. this only changes destination subscription matching/validation.
Validation
if available topics are configured, wildcard patterns must match at least one available topic.
for example, with available topics:
user.createduser.deletedthis is valid:
user.*this is rejected:
order.*if no available topics are configured, wildcard patterns are accepted, same as other destination topics today.
Implementation notes
topic matching is on the delivery hot path, so this avoids regex and avoids compiling/caching patterns.
the matcher uses a small allocation-free wildcard algorithm:
*matches any run of charactersTests
verified with local test infra running:
TESTINFRA=1 go test ./internal/publishmq -run 'TestEventHandler|TestIntegrationPublishMQEventHandler_Concurrency' -count=1TESTINFRA=1 go test ./internal/models ./internal/tenantstore/memtenantstore ./internal/tenantstore/redistenantstore ./internal/apirouter ./internal/publishmq -count=1bench:
TESTINFRA=1 go test ./internal/models -bench 'BenchmarkTopics_MatchTopic' -benchmem -run '^$'result on my machine: