public function testSetResource() { $resource = $this->prophesize(AMQPChannel::class); $channel = new Channel(); $channel->setResource($resource->reveal()); static::assertSame($resource->reveal(), $channel->getResource()); }
/** * Publish a message to an exchange. * * Publish a message to the exchange represented by the Exchange object. * * @param string $message The message to publish. * @param string $routingKey The optional routing key to which to * publish to. * @param bool $mandatory Mandatory * @param bool $immediate Immediate * @param array $attributes One of content_type, content_encoding, * message_id, user_id, app_id, delivery_mode, * priority, timestamp, expiration, type * or reply_to, headers. * * @return $this */ public function publish($message, $routingKey = null, $mandatory = false, $immediate = false, array $attributes = []) { if (null === $routingKey) { $routingKey = ''; } $options = $this->options; $AMQPMessage = new AMQPMessage($message, $attributes); $this->channel->getResource()->basic_publish($AMQPMessage, $options->getName(), $routingKey, $mandatory, $immediate); return $this; }
/** * Consume messages from a queue (blocking function). * * @param callback|ConsumerInterface|null $callback A callback function to which the * consumed message will be passed. * @param bool $noLocal * @param bool $autoAck * @param bool $exclusive * @param string $consumerTag A string describing this consumer. Used * for canceling subscriptions with cancel(). * @return $this */ public function consume(callable $callback = null, $noLocal = false, $autoAck = false, $exclusive = false, $consumerTag = null) { if (null === $consumerTag) { $consumerTag = ''; } $queue = $this->getOptions()->getName(); $consumerCallback = null; if ($callback) { $consumerCallback = new ConsumerCallback($callback, $this); $consumerCallback->setMessageMapper($this->getMessageMapper()); } $this->channel->getResource()->basic_consume($queue, $consumerTag, $noLocal, $autoAck, $exclusive, false, $consumerCallback); while (count($this->channel->getResource()->callbacks)) { $this->channel->getResource()->wait(); } return $this; }