/** * @param QueueTemplate $queueTemplate */ public function declareQualityOfService(QueueTemplate $queueTemplate) { // Create or reuse existing channel. The channel ID should be set, use queue name if the channel has no id. // We don't want the channel to be recreated over and over. $channel = $queueTemplate->channel(); /* * don't dispatch a new message to a worker until it has processed and * acknowledged the previous one. Instead, it will dispatch it to the * next worker that is not still busy. */ $channel->basic_qos(null, 1, true); }
/** * @test */ public function shouldSentNackSignal() { // Create message $message = $this->queueTemplate->createMessage(['msg' => 'blaat']); $message->delivery_info = ['channel' => $this->queueTemplate->channel(), 'delivery_tag' => 123]; // Create a failing consumer instance. This instance will return false. A nack signal should be sent. $consumer = new CleanFailConsumer($this->queueTemplate); // Execute consumer call_user_func($consumer, $message); // Assert that the ack signal was sent $this->assertEquals(1, $this->basicNackInvocations->getInvocationCount()); // Create a failing consumer instance. This instance will return false. A nack signal should be sent. $consumer = new FailWithExceptionConsumer($this->queueTemplate); // Execute consumer try { call_user_func($consumer, $message); } catch (\Exception $e) { // Make sure no exception is thrown here. } // Assert that the ack signal was sent $this->assertEquals(1, $this->basicNackInvocations->getInvocationCount()); }
/** * @return bool */ public function isBusy() { return count($this->queueTemplate->channel()->callbacks) > 0; }
/** * @return AMQPChannel */ public function getChannel() { // Create channel or reuse the existing one... return $this->queueTemplate->channel(); }