1. Go to this page and download the library: Download byjg/message-queue-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/ */
byjg / message-queue-client example snippets
// Register the connector and associate with a scheme
ConnectorFactory::registerConnector(MockConnector::class);
// Create a connector
$connector = ConnectorFactory::create(new Uri("mock://local"));
// Create a queue
$pipe = new Pipe("test");
$pipe->withDeadLetter(new Pipe("dlq_test"));
// Create a message
$message = new Message("Hello World");
// Publish the message into the queue
$connector->publish(new Envelope($pipe, $message));
// Register the connector and associate with a scheme
ConnectorFactory::registerConnector(MockConnector::class);
// Create a connector
$connector = ConnectorFactory::create(new Uri("mock://local"));
// Create a queue
$pipe = new Pipe("test");
$pipe->withDeadLetter(new Pipe("dlq_test"));
// Connect to the queue and wait to consume the message
$connector->consume(
$pipe, // Queue name
function (Envelope $envelope) { // Callback function to process the message
echo "Process the message";
echo $envelope->getMessage()->getBody();
return Message::ACK;
},
function (Envelope $envelope, $ex) { // Callback function to process the failed message
echo "Process the failed message";
echo $ex->getMessage();
return Message::REQUEUE;
}
);
interface ConnectorInterface
{
public function setUp(Uri $uri);
public function getDriver();
public function publish(Envelope $envelope);
public function consume(Pipe $pipe, \Closure $onReceive, \Closure $onError, $identification = null);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.