Skip to content

Commit

Permalink
Document subscribing to topics using regex (#239)
Browse files Browse the repository at this point in the history
* Get metadata after each message consumed

This ensure that consumer will automatically subscribe to topics that matches the regex pattern

* Add docs

* Revert "Get metadata after each message consumed"

This reverts commit 8aae773.
  • Loading branch information
mateusjunges authored Jan 24, 2024
1 parent 0970261 commit dcdc2ed
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Using regex to subscribe to kafka topics
weight: 2
---

Kafka allows you to subscribe to topics using regex, and regex pattern matching is automatically performed for topics prefixed with `^` (e.g. `^myPfx[0-9]_.*`).

The consumer will see the new topics on its next periodic metadata refresh which is controlled by the `topic.metadata.refresh.interval.ms`

To subscribe to topics using regex, you can simply pass the regex you want to use to the `subscribe` method:

```php
\Junges\Kafka\Facades\Kafka::createConsumer()
->subscribe('^myPfx_.*')
->withHandler(...)
```

This pattern will match any topics that starts with `myPfx_`.

0 comments on commit dcdc2ed

Please sign in to comment.