yii2-amqp icon indicating copy to clipboard operation
yii2-amqp copied to clipboard

Sample doesn't work in topic mode

Open Biktop opened this issue 10 years ago • 5 comments

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?

Biktop avatar Feb 15 '15 09:02 Biktop

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

webtoucher avatar Feb 15 '15 09:02 webtoucher

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?

Biktop avatar Feb 15 '15 09:02 Biktop

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 avatar Feb 15 '15 13:02 webtoucher

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

webtoucher avatar Feb 15 '15 13:02 webtoucher

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.

Biktop avatar Feb 15 '15 13:02 Biktop