Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/walkor/rabbitmq
Asynchronous rabbitmq client for PHP based on workerman.
https://github.com/walkor/rabbitmq
Last synced: 4 days ago
JSON representation
Asynchronous rabbitmq client for PHP based on workerman.
- Host: GitHub
- URL: https://github.com/walkor/rabbitmq
- Owner: walkor
- Created: 2020-10-10T03:32:48.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-06-14T09:47:57.000Z (5 months ago)
- Last Synced: 2024-10-29T10:23:36.796Z (16 days ago)
- Language: PHP
- Size: 31.3 KB
- Stars: 35
- Watchers: 6
- Forks: 8
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rabbitmq
Asynchronous rabbitmq client for PHP based on [workerman](https://github.com/walkor/workerman).# Install
```
composer require workerman/rabbitmq
```# Examples
receive.php
```php
onWorkerStart = function() {
(new Client())->connect()->then(function (Client $client) {
return $client->channel();
})->then(function (Channel $channel) {
return $channel->queueDeclare('hello', false, false, false, false)->then(function () use ($channel) {
return $channel;
});
})->then(function (Channel $channel) {
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
$channel->consume(
function (Message $message, Channel $channel, Client $client) {
echo " [x] Received ", $message->content, "\n";
},
'hello',
'',
false,
true
);
});
};
Worker::runAll();
```
Run command `php receive.php start`.send.php
```php
onWorkerStart = function() {
(new Client())->connect()->then(function (Client $client) {
return $client->channel();
})->then(function (Channel $channel) {
return $channel->queueDeclare('hello', false, false, false, false)->then(function () use ($channel) {
return $channel;
});
})->then(function (Channel $channel) {
echo " [x] Sending 'Hello World!'\n";
return $channel->publish('Hello World!', [], '', 'hello')->then(function () use ($channel) {
return $channel;
});
})->then(function (Channel $channel) {
echo " [x] Sent 'Hello World!'\n";
$client = $channel->getClient();
return $channel->close()->then(function () use ($client) {
return $client;
});
})->then(function (Client $client) {
$client->disconnect();
});
};
Worker::runAll();
```Run command `php send.php start`.