Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function push2($queue = null, $data = null, $permanent = false, $params = array())
- {
- // We check if the queue is not empty then we declare the queue
- if(empty($queue)) {
- rabbitmq_client_output('You did not specify the [queue] parameter', 'error', 'x');
- throw new Exception("You did not specify the [queue] parameter");
- }
- // We declare the queue
- $this->channel->queue_declare($queue, false, $permanent, false, false, false, null, null);
- // If the information given are in an array, we convert it in json format
- $data = (is_array($data)) ? json_encode($data) : $data;
- // Create a new instance of message then push it into the selected queue
- //$item = new PhpAmqpLib\Message\AMQPMessage($data, $params);
- // Publish to the queue
- //$this->channel->basic_publish($item, '', $queue);
- //Set Publish Attributes
- $attributes = array(
- 'correlation_id' => '1',
- 'reply_to' => $queue
- );
- $rpcQueue = 'rpc_queue';
- $channel = new PhpAmqpLib\Channel\AMQPChannel($this->connexion);
- //$channel->setPrefetchCount(1);
- //$channel->exchange_declare()
- $channel->exchange_declare('tasks', 'fanout', false, false, false);
- //$exchange = new PhpAmqpLib\Wire\AMQPExchange($channel);
- /* $channel->publish(
- $data,
- $this->rpcQueue,
- PhpAmqpLib\Message\AMQP_NOPARAM,
- $attributes
- ); */
- $callback = function(PhpAmqpLib\Message\AMQPEnvelope $message, PhpAmqpLib\Message\AMQPQueue $q) {
- if($message->getCorrelationId() == $this->corrId) {
- //echo sprintf("CorrelationID: %s",$message->getCorrelationId()), PHP_EOL;
- //echo sprintf("Response: %s",$message->getBody()), PHP_EOL;
- $this->response = $message->getBody();
- $q->nack($message->getDeliveryTag());
- return false;
- }
- };
- $this->queue->consume($callback);
- //Return RPC Results
- return $this->response;
- // Output
- // ($this->show_output) ? rabbitmq_client_output('Pushing "'.$item->body.'" to "'.$queue.'" queue -> OK', null, '+') : true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement