Comments (1)
In order to support direct
and topic
exchanges while assuring that messages are not lost. We should figure out a way to bind a queue to an exchange specifying a binding key
and to publish a message with a matching routing key
.
Messages can be lost in the case where a producer is publishes messages to an exchange while there are no queue bound to that exchange yet.
Since a routing key
is required on the producer side, and a matching binding key
on the consumer's side, we should somehow provide a way to map the routing key
to its corresponding binding key
by either:
1- Leave it as the users responsibility.
2- Declaring the queues and exchanges on both the producer and consumer's side alike.
Producer
public function __construct(Connection $connection, $exchangeName, $exchangeType, $queueName, $routingKey, $passive = false, $durable = true, $autoDelete = false, $deliveryMode = 2)
{
$this->connection = $connection;
$this->exchangeName = $exchangeName;
$this->exchangeType = $exchangeType;
$this->queueName = $queueName;
$this->passive = $passive;
$this->durable = $durable;
$this->autoDelete = $autoDelete;
$this->deliveryMode = $deliveryMode;
$this->routingKey = $routingKey; //Since these should match
$this->bindingKey = $routingKey; //Since these should match
}
public function publish($data)
{
$this->connection->getChannel()->exchange_declare($this->exchangeName, $this->exchangeType, $this->passive, $this->durable, $this->autoDelete);
$this->connection->getChannel()->queue_declare($this->queueName, $this->passive, $this->durable, false, $this->autoDelete);
$this->connection->getChannel()->queue_bind($this->queueName, $this->exchangeName, $this->bindingKey);
$msg = new AMQPMessage($data, ['delivery_mode' => $this->deliveryMode]);
$this->connection->getChannel()->basic_publish($msg, $this->exchangeName, $this->routingKey);
}
Consumer
public function __construct(Connection $connection, $exchangeName, $exchangeType, $queueName, $bindingKey, $passive = false, $durable = true, $autoDelete = false, $deliveryMode = 2)
{
$this->connection = $connection;
$this->exchangeName = $exchangeName;
$this->exchangeType = $exchangeType;
$this->queueName = $queueName;
$this->passive = $passive;
$this->durable = $durable;
$this->autoDelete = $autoDelete;
$this->deliveryMode = $deliveryMode;
$this->bindingKey = $bindingKey;
}
public function listenToQueue($handlerClass, ExceptionHandler $exceptionHandler)
{
$this->connection->getChannel()->exchange_declare($this->exchangeName, $this->exchangeType, $this->passive, $this->durable, $this->autoDelete);
$this->connection->getChannel()->queue_declare($this->queueName, $this->passive, $this->durable, false, $this->autoDelete);
$this->connection->getChannel()->queue_bind($this->queueName, $this->exchangeName, $this->bindingKey);
$handler = new $handlerClass;
$callback = function ($msg) use ($handler, $exceptionHandler) {
//
};
$this->connection->getChannel()->basic_qos(null, 1, null);
$this->connection->getChannel()->basic_consume($queue_name, '', false, false, false, false, $callback);
while (count($this->connection->getChannel()->callbacks)) {
$this->connection->getChannel()->wait();
}
}
the above implementation example doesn't account for DLX.
from bowler.
Related Issues (20)
- Consider using queue interprop as abstraction for queues
- Support worker queues HOT 1
- Vinelab\Bowler\Exceptions\Handler::__construct() Invalid Argument HOT 2
- Broken pipe or closed connection HOT 4
- Look into Memory exhausted in StreamIO.php
- Throw unhandled errors
- Separate fetchQueueConsumers from Connection class
- Make timeout variables configurable
- ErrorException : Undefined index: driver HOT 5
- Support for vhost
- bowler:consume HOT 4
- php-amqplib/php-amqplib HOT 4
- bowler:consume HOT 2
- Corrupted JSON response when producing a message HOT 4
- Use of undefined constant SOCKET_EAGAIN - assumed 'SOCKET_EAGAIN' HOT 5
- Deprecation: `assertAttributeEquals` HOT 1
- Invalid PHPDoc for Subscriber() Method in Registrator Facade
- Add support to reconnect to server
- How to make tenant aware for multi tenant application? HOT 3
- Support for laravel 10 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bowler.