PHP code example of justyork / enqueue-client

1. Go to this page and download the library: Download justyork/enqueue-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

justyork / enqueue-client example snippets

injectablephp
// ./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
        ]
    ]
];
injectablephp
public function __construct(protected EnqueueContextClient $context)
{
}
injectablephp
protected EnqueueContextClient $context;

public function __construct(EnqueueContextClient $context)
{
    $this->context = $context;
}
injectablephp
// Create topic
$topic = $this->context->createTopic('default');

// Create message
$message = $this->context->createMessage('New message');

// Produce
$this->context->createProducer()->send($topic, $message);