PHPackages                             tzmudz/rabbitmq\_rpc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. tzmudz/rabbitmq\_rpc

ActiveLibrary[Queues &amp; Workers](/categories/queues)

tzmudz/rabbitmq\_rpc
====================

Very simple RabbitMQ RPC message handler. Based on RPC example.

v1.0.7(6y ago)556MITPHPPHP ^7.2

Since Nov 5Pushed 6y ago2 watchersCompare

[ Source](https://github.com/zmudzinski/rabbitmq_rpc)[ Packagist](https://packagist.org/packages/tzmudz/rabbitmq_rpc)[ Docs](https://github.com/zmudzinski/rabbitmq_rpc)[ RSS](/packages/tzmudz-rabbitmq-rpc/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

RabbitMQ RPC message
====================

[](#rabbitmq-rpc-message)

[![stable](https://camo.githubusercontent.com/8af43093c3540c177b9c422a938955cd29409b9c6ec67b1055d0a548f087bde7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f7a6d75647a696e736b692f7261626269746d715f7270633f6c6162656c3d737461626c65267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/8af43093c3540c177b9c422a938955cd29409b9c6ec67b1055d0a548f087bde7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f7a6d75647a696e736b692f7261626269746d715f7270633f6c6162656c3d737461626c65267374796c653d666c61742d737175617265)

This package makes ready to use implementation of RabbitMQ RPC tutorial published on: It implements both server side and client.

**Thanks to this package you will be able to send a message to RabbtiMQ, then receive this message (on the server side) handle it and finally send the response to the client (Producer).**

**Unlike tutorial this package is set to save the queue and messages after RabbtiMQ server reboot.**

Installation
------------

[](#installation)

Installation of the package by Composer:

```
composer require tzmudz/rabbitmq_rpc

```

Package uses an *Environment Variables* delivered by `vlucas/phpdotenv` package. You have to create an `.env` file in the root folder containing variables:

```
RABBTIMQ_PORT=5672
RABBTIMQ_HOST=localhost
RABBTIMQ_USERNAME=guest
RABBTIMQ_PASSWORD=guest
```

Thus if you are using e.g. Laravel all you have to do is to put this variables in your `.env`app file. **Notice** If your application doesn’t use `.env` files, don't forget to load them by executing the code:

```
$dotenv = Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
```

You can find more information here:

Usage
-----

[](#usage)

Package comes with two classes: `Producer` and `Consumer`.

### Producer

[](#producer)

The `Producer` class is responsible for delivering messages to RabbtiMQ. In your application create a new instance of `Tzm\Rpc\Producer()`. As a parameter you can set the queue name (by default the name is `default`):

```
$producer = new Tzm\Rpc\Producer('long_task_queue_name');
```

Otherwise you can set the queue name by calling the `setQueueName()`.

```
$producer = new Tzm\Rpc\Producer();
$producer->setQueueName('long_task_queue_name');
```

Finally you have to call the method `call()` with message as parameter:

```
$producer = new Tzm\Rpc\Producer();
$producer->setQueueName('long_task_queue_name')->call($message);
```

Where `$message` is a **string** of data that should be send to the RabbtiMQ server. Actually RPC sends a message and waits for the response given from server. But, if you don't want to wait for server’s response you can use `withoutWaiting()`:

```
$producet = new Tzm\Rpc\Producer();
$producer->withoutWaiting()->call($message);
```

### Consumer

[](#consumer)

To process the queued message you need `Consumer` class. This class is abstract. You have to create a new class that inherits from `Consumer` abstract class. Then you have to implement several methods.

#### handleMessage()

[](#handlemessage)

This method is responsible for process the message. It accepts `$message` as a parameter e.g.

```
public function handleMessage($message)
{
    echo $message;
}
```

#### handleError()

[](#handleerror)

Generally it's not necessary, but it handles the error. If the method `handleMessage()` thrown an error it will be passed to the `handleError()` method. So that you can handle the error however you want. e.g. in Laravel you can log the error message:

```
public function handleError(\Exception $e)
{
    Log::error($e->getMessage());
}
```

#### setResults()

[](#setresults)

After the message is handled RabbitMQ returns a response message. Initially it returns true. But if you want you can use `setResult()` method to set the data you want to return. E.g.:

```
public function handleMessage($message)
{
    $this->setResult('this_will_be_returned_to_Producer');
}
```

#### Run Consumer

[](#run-consumer)

Your inherited class of consumer of `Consumer` should look like this:

```
namespace Tzm\Rpc;

class EchoMessage extends Consumer
{
    protected function handleMessage($message)
    {
        echo $message;
    }

    protected function handleError(\Exception $e)
    {
        \Log::error($e->getMessage()); // In Laravel Log exception message
    }
}
```

Then you can run the Consumer:

```
$consumer = new EchoMessage();
$consumer->run();
```

Just like a `Producer` class this one also has a `setQueueName()` method. So you can set the queue name
when new instance is being created or later by using method.

#### Console information

[](#console-information)

Additionally there are two methods:

##### consoleMessage($req)

[](#consolemessagereq)

It's used to display message in a console. It has one parameter `$req` - containing all the info about the recievied message. By default this method returns string: `New request` so if a new message will be delivered the console should print:

```
[04.11 11:03:49] [NEW] New request
[04.11 11:03:49] [OK] New request

```

Whole message could be changed by overriding `consoleInfo()` method. **ATTENTION!**Don't forget to run Consumer class first (it will create the queue on RabbitMQ server)

License
-------

[](#license)

MIT

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Total

4

Last Release

2256d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/30274239?v=4)[Tomek Żmudziński](/maintainers/zmudzinski)[@zmudzinski](https://github.com/zmudzinski)

---

Top Contributors

[![zmudzinski](https://avatars.githubusercontent.com/u/30274239?v=4)](https://github.com/zmudzinski "zmudzinski (26 commits)")

---

Tags

brokermessagemessage-queuephpphp7queuerabbit-mqrabbitmqrabbitmq-clientrabbitmq-consumerrabbitmq-producerrabbitmq-rpcrabbitmq-serverrpcrpc-clientrpc-servermessagerpcqueuerabbitmqbroker

### Embed Badge

![Health badge](/badges/tzmudz-rabbitmq-rpc/health.svg)

```
[![Health](https://phpackages.com/badges/tzmudz-rabbitmq-rpc/health.svg)](https://phpackages.com/packages/tzmudz-rabbitmq-rpc)
```

###  Alternatives

[php-amqplib/rabbitmq-bundle

Integrates php-amqplib with Symfony &amp; RabbitMq. Formerly emag-tech-labs/rabbitmq-bundle, oldsound/rabbitmq-bundle.

1.3k20.1M64](/packages/php-amqplib-rabbitmq-bundle)[kdyby/rabbitmq

Integrates php-amqplib with RabbitMq and Nette Framework

30693.1k4](/packages/kdyby-rabbitmq)[convenia/pigeon

3233.0k](/packages/convenia-pigeon)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
