<?php
use Pheanstalk\Pheanstalk;
// Configuration
$pheanstalk = new Pheanstalk('127.0.0.1');
// Publisher
$pheanstalk
->useTube('order')
->put("order product #1234 from supplier #5");
// Subscriber
$job = $pheanstalk
->watch('order')
->reserve();
// Process order
$data = $job->getData();
// Delete job from the queue
$pheanstalk->delete($job);
<?php
// Configuration
$producer = ...;
$consumer = ...;
$queue = ...;
// Publisher (== producer)
$producer->produce(
new Message\DefaultMessage('Order', [
'product_id' => 1234,
'supplier_id' => 5,
]),
$queue->getName()
);
// Subscriber (== consumer)
$consumer->consume($queue);
<?php
declare(strict_types=1);
final class Order
{
private $productId;
private $supplierId;
public function __construct(int $productId, int $supplierId)
{
$this->productId = $productId;
$this->supplierId = $supplierId;
}
public function getProductId() : int
{
return $this->productId;
}
public function getSupplierId() : int
{
return $this->supplierId;
}
}
final class OrderHandler
{
// some dependencies
public function handle(Order $command)
{
// do something
}
}
<?php
// Configuration
$commandBus = ...;
$consumer = ...;
$queue = ...;
// Producer
$command = new Order(1234, 5);
$commandBus->handle($command);
// Consumer
$consumer->consume($queue);