Skip to content

Commit 0770c73

Browse files
authored
Enhance queueable handlers documentation with connection and queue specification methods (#345)
1 parent b33e15d commit 0770c73

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/consuming-messages/queueable-handlers.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ class Handler implements HandlerContract, ShouldQueue
3030
As you can see on the `__invoke` method, queued handlers does not have access to a `MessageConsumer` instance when handling the message,
3131
because it's running on a laravel queue and there are no actions that can be performed asynchronously on Kafka message consumer.
3232

33+
You can specify which queue connection and queue name to use for your handler by implementing the `onConnection` and `onQueue` methods:
34+
35+
```php
36+
use Illuminate\Contracts\Queue\ShouldQueue;
37+
use Junges\Kafka\Contracts\Handler as HandlerContract;
38+
use Junges\Kafka\Contracts\KafkaConsumerMessage;
39+
40+
class Handler implements HandlerContract, ShouldQueue
41+
{
42+
public function __invoke(KafkaConsumerMessage $message): void
43+
{
44+
// Handle the consumed message.
45+
}
46+
47+
public function onConnection(): string
48+
{
49+
return 'sqs'; // Specify your queue connection
50+
}
51+
52+
public function onQueue(): string
53+
{
54+
return 'kafka-handlers'; // Specify your queue name
55+
}
56+
}
57+
```
58+
3359
After creating your handler class, you can use it just as a normal handler, and `laravel-kafka` will know how to handle it under the hoods 😄.
3460

3561

0 commit comments

Comments
 (0)