File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,32 @@ class Handler implements HandlerContract, ShouldQueue
30
30
As you can see on the ` __invoke ` method, queued handlers does not have access to a ` MessageConsumer ` instance when handling the message,
31
31
because it's running on a laravel queue and there are no actions that can be performed asynchronously on Kafka message consumer.
32
32
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
+
33
59
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 😄.
34
60
35
61
You can’t perform that action at this time.
0 commit comments