@@ -174,6 +174,72 @@ class MyExampleSubscriber extends Command
174
174
}
175
175
```
176
176
177
+ ### Kafka Subscribers ###
178
+
179
+ For subscribers which use the ` php-pubsub-kafka ` adapter, you'll likely want to change the ` consumer_group_id ` per
180
+ subscriber.
181
+
182
+ To do this, you need to use the ` PubSubConnectionFactory ` to create a new connection per subscriber. This is because
183
+ the ` consumer_group_id ` cannot be changed once a connection is created.
184
+
185
+ Here is an example of how you can do this:
186
+
187
+ ``` php
188
+ <?php
189
+
190
+ namespace App\Console\Commands;
191
+
192
+ use Illuminate\Console\Command;
193
+ use Superbalist\LaravelPubSub\PubSubConnectionFactory;
194
+ use Superbalist\PubSub\PubSubAdapterInterface;
195
+
196
+ class MyExampleKafkaSubscriber extends Command
197
+ {
198
+ /**
199
+ * The name and signature of the subscriber command.
200
+ *
201
+ * @var string
202
+ */
203
+ protected $signature = 'subscriber:name';
204
+
205
+ /**
206
+ * The subscriber description.
207
+ *
208
+ * @var string
209
+ */
210
+ protected $description = 'PubSub subscriber for ________';
211
+
212
+ /**
213
+ * @var PubSubAdapterInterface
214
+ */
215
+ protected $pubsub;
216
+
217
+ /**
218
+ * Create a new command instance.
219
+ *
220
+ * @param PubSubConnectionFactory $factory
221
+ */
222
+ public function __construct(PubSubConnectionFactory $factory)
223
+ {
224
+ parent::__construct();
225
+
226
+ $config = config('pubsub.connections.kafka');
227
+ $config['consumer_group_id'] = self::class;
228
+ $this->pubsub = $factory->make('kafka', $config);
229
+ }
230
+
231
+ /**
232
+ * Execute the console command.
233
+ */
234
+ public function handle()
235
+ {
236
+ $this->pubsub->subscribe('channel_name', function ($message) {
237
+
238
+ });
239
+ }
240
+ }
241
+ ```
242
+
177
243
## Adding a Custom Driver
178
244
179
245
Please see the [ php-pubsub] ( https://github.com/Superbalist/php-pubsub ) documentation ** Writing an Adapter** .
0 commit comments