webtoucher / yii2-amqp

Yii 2 extension wrapper to communicate with RabbitMQ server via AMQP.
https://packagist.org/packages/webtoucher/yii2-amqp
BSD 3-Clause "New" or "Revised" License
60 stars 41 forks source link

Sample doesn't work in topic mode #5

Open Biktop opened 9 years ago

Biktop commented 9 years ago

I tried to run sample and command ./yii rabbit throw exception: AMQPProtocolChannelException with message 'NOT_FOUND - no exchange 'my-exchange' in vhost '/'.

I found if comment if ($type == Amqp::TYPE_DIRECT) then receiver works well.

 public function listen($exchange, $routing_key, $callback, $type = self::TYPE_TOPIC)
    {
        list ($queueName) = $this->channel->queue_declare();
        if ($type == Amqp::TYPE_DIRECT) {
            $this->channel->exchange_declare($exchange, $type, false, true, false);
    }
    ...

Is it bug in sources?

webtoucher commented 9 years ago

There is no exchange you need. Sender must init this exchange before sending messages

Biktop commented 9 years ago

But how is it possible? In my use case I run receiver as daemon (./yii rabbit) and after that my Web application sends requests to daemon. What I can do in my case?

webtoucher commented 9 years ago

Using of topic exchange means one sender and one or more receiver(s). Sender runs first and creates exchange. Then it can send messages. Sender don't know about any receivers. Receiver(s) know about sender and describe to this created exchange.

If your sender know about receiver and you will nerer use more than one receivers use dierect exchange.

webtoucher commented 9 years ago

Using of direct exchange means sending the mesages for reciving answers from daemon. Topic is for informing only.

Biktop commented 9 years ago

Related topic and direct modes that's ok. Are there any problems to call exchange_declare for receiver in topic mode? Because I still don't understand how run receiver after senders.