justyork / enqueue-client
DI adapter for php-enqueue
v1.1.7
2021-06-28 15:27 UTC
Requires
- php: ^7.3|^8.0
- enqueue/laravel-queue: ^0.10.4
- enqueue/rdkafka: ^0.10.9
README
Publish configs
artisan vendor:publish --provider="Justyork\EnqueueClient\EnqueueClientServiceProvider"
Config
// ./config/enqueue_client.php
return [
'transports' => [
'default' => 'rdkafka',
'rdkafka' => [
'dsn' => 'rdkafka://',
'global' => [
'group.id' => 'app',
'metadata.broker.list' => env('KAFKA_HOST'),
'sasl.mechanisms' => env('KAFKA_MECHANISM'),
'sasl.username' => env('KAFKA_USERNAME'),
'sasl.password' => env('KAFKA_PASSWORD'),
'security.protocol' => env('KAFKA_PROTOCOL'),
],
'class' => Enqueue\RdKafka\RdKafkaContext::class
]
]
];
// ./config/events_map.php
'event_name' => Event::class
Inject in the constructor
PHP 8
public function __construct(protected EnqueueContextClient $context)
{
}
PHP 7.x
protected EnqueueContextClient $context;
public function __construct(EnqueueContextClient $context)
{
$this->context = $context;
}
Usage
Produce
// Create topic
$topic = $this->context->createTopic('default');
// Create message
$message = $this->context->createMessage('New message');
// Produce
$this->context->createProducer()->send($topic, $message);
Consume
run consume:events [topickname]