PHP Classes

How to Create a Message Queue and Send Messages From Consumers to Workers Processes Using a PHP Protobuf Example Application Proto x Bus: Manage queues of messages using protocol buffers

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-04-14 (5 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
proto-x-bus 1.0.0The PHP License5Networking, PHP 5, Design Patterns, A...
Description 

Author

This package can manage queues of messages using protocol buffers.

It provides a demonstration package that uses Google Protocol Buffers libraries to perform operations on messages that are sent from consumer tasks to worker task that can perform useful jobs.

Currently, the package can:

- Create a queue of tasks

- Let consumers send messages to a queue

- Let workers receive queued messages

Picture of DeGraciaMathieu
  Performance   Level  
Innovation award
Innovation award
Nominee: 17x

Winner: 2x

 

Instructions

Example

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use
Aws\Sqs\SqsClient;
use
Aws\Exception\AwsException;

$sqsClient = new SqsClient([
   
'version' => 'latest',
   
'region' => 'us-east-1',
   
'endpoint' => 'http://localhost:4566',
]);

$queueUrl = 'http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/testing-queue';

try {

   
$result = $sqsClient->receiveMessage([
       
'QueueUrl' => $queueUrl,
       
'MaxNumberOfMessages' => 1,
       
'VisibilityTimeout' => 0,
       
'WaitTimeSeconds' => 0,
    ]);

   
$messages = $result->get('Messages');

    if (!
$messages) {
       
dd('No messages');
    }

    foreach (
$messages as $message) {

       
$gameDeserialized = new Game();
       
$gameDeserialized->mergeFromString($message['Body']);

        echo
'game found : ' . $gameDeserialized->getName() . PHP_EOL;

       
$sqsClient->deleteMessage([
           
'QueueUrl' => $queueUrl,
           
'ReceiptHandle' => $message['ReceiptHandle'],
        ]);
    }

} catch (
AwsException $e) {
   
dump($e->getMessage());
}


Details

proto-x-bus

qdsqdsqdqsdq

Creating prototypes :

protoc --proto_path=proto/ --php_out=worker/Protos game.proto
protoc --proto_path=proto/ --php_out=consumer/Protos game.proto

Starting bus :

docker run -d -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack

Creating queue :

aws --endpoint-url=http://localhost:4566 --region us-east-1 sqs create-queue --queue-name testing-queue

Usage :

php worker/src/run.php
php consumer/src/run.php

  Files folder image Files (17)  
File Role Description
Files folder imagebus (1 file)
Files folder imageconsumer (3 files, 2 directories)
Files folder imageproto (2 files)
Files folder imageworker (3 files, 3 directories)
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0