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  
Name: DeGraciaMathieu <contact>
Classes: 23 packages by
Country: France France
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

  Files folder image Files (17)  /  bus  
File Role Description
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (17)  /  consumer  
File Role Description
Files folder imageProtos (1 file, 1 directory)
Files folder imagesrc (1 file)
  Accessible without login Plain text file composer.json Data Auxiliary data
  Accessible without login Plain text file composer.lock Data Auxiliary data
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (17)  /  consumer  /  Protos  
File Role Description
Files folder imageGPBMetadata (1 file)
  Plain text file Game.php Class Class source

  Files folder image Files (17)  /  consumer  /  Protos  /  GPBMetadata  
File Role Description
  Plain text file Game.php Class Class source

  Files folder image Files (17)  /  consumer  /  src  
File Role Description
  Accessible without login Plain text file run.php Example Example script

  Files folder image Files (17)  /  proto  
File Role Description
  Accessible without login Plain text file game.proto Data Auxiliary data
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (17)  /  worker  
File Role Description
Files folder imageProtos (1 file, 1 directory)
Files folder imagesrc (1 file)
Files folder imagevendor (1 file)
  Accessible without login Plain text file composer.json Data Auxiliary data
  Accessible without login Plain text file composer.lock Data Auxiliary data
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (17)  /  worker  /  Protos  
File Role Description
Files folder imageGPBMetadata (1 file)
  Plain text file Game.php Class Class source

  Files folder image Files (17)  /  worker  /  Protos  /  GPBMetadata  
File Role Description
  Plain text file Game.php Class Class source

  Files folder image Files (17)  /  worker  /  src  
File Role Description
  Accessible without login Plain text file run.php Example Example script

  Files folder image Files (17)  /  worker  /  vendor  
File Role Description
  Accessible without login Plain text file autoload.php Aux. Configuration script

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