/** * Appends a new event to rabbitmq message queue * @throws LoggerException If the publish message fails. */ public function append(LoggerLoggingEvent $event) { if ($this->connection && $this->layout !== null && $this->append == true) { try { $this->channel->access_request($this->virtual_host, false, false, true, true); $message = $this->getLayout()->format($event); $msgObject = new AMQPMessage(json_encode($message), array('content_type' => 'text/plain')); $this->channel->basic_publish($msgObject, $this->exchange, $this->routing_key); } catch (LoggerException $e) { } } }
public function submitInput($type, InputMessage $inputMessage) { $this->declareQueue($type); if (is_null($this->replyQueueName)) { list($this->replyQueueName, , ) = $this->channel->queue_declare('', false, false, true, false); $replyCallbackCapture = function (AMQPMessage $amqpMessage) { $outputMessage = new OutputMessage($amqpMessage->body); $id = $amqpMessage->get('correlation_id'); $this->outputMessages[$id] = $outputMessage; $channel = $amqpMessage->delivery_info['channel']; $channel->basic_ack($amqpMessage->delivery_info['delivery_tag']); }; $this->channel->basic_qos(null, 1, null); $this->channel->basic_consume($this->replyQueueName, '', false, false, true, false, $replyCallbackCapture); } $id = Uuid::uuid4()->toString(); $amqpMessage = new AMQPMessage($inputMessage->getData(), ['reply_to' => $this->replyQueueName, 'correlation_id' => $id]); $this->channel->basic_publish($amqpMessage, $this->getExchangeName($type)); return new InputMessageIdentifier($id); }
/** * Publish an event * * @param Imbo\EventManager\EventInterface $event The current event */ public function publishEvent(EventInterface $event) { $request = $event->getRequest(); $routeName = (string) $request->getRoute(); $methodName = strtolower($request->getMethod()); $eventName = $routeName . '.' . $methodName; // Don't publish for messages we don't subscribe to if (!in_array('*', $this->events) && !in_array($eventName, $this->events)) { return; } // Collect data and construct the message body $body = $this->constructMessageBody($eventName, $event->getRequest(), $event->getResponse(), $event); // Construct the message $msg = new AMQPMessage(json_encode($body), ['content_type' => 'application/json', 'delivery_mode' => $this->persistentDelivery ? self::DELIVERY_MODE_PERSISTENT : self::DELIVERY_MODE_NON_PERSISTENT]); $this->initConnection(); $this->channel->basic_publish($msg, $this->exchangeConfig['name']); $this->closeConnections(); }
/** * Basic publish AMQP Message * @param $message * @param string $exchange * @param string $routingKey */ public function basicPublish($message, $exchange = '', $routingKey = '') { $message = new AMQPMessage($message, ['delivery_mode' => 2]); $this->channel->basic_publish($message, $exchange, $routingKey); }
/** * Process event - send AMQ message * * @param array $event */ protected function processEvent(&$event){ $msg = new AMQPMessage(json_encode($event), array('content_type' => 'text/json')); $this->amqChannel->basic_publish($msg, $this->config['amqp']['exchange']); }