Exemplo n.º 1
0
 public static function castEnvelope(\AMQPEnvelope $c, array $a, Stub $stub, $isNested, $filter = 0)
 {
     $prefix = Caster::PREFIX_VIRTUAL;
     if (!($filter & Caster::EXCLUDE_VERBOSE)) {
         $a += array($prefix . 'body' => $c->getBody());
     }
     $a += array($prefix . 'routingKey' => $c->getRoutingKey(), $prefix . 'deliveryTag' => $c->getDeliveryTag(), $prefix . 'deliveryMode' => new ConstStub($c->getDeliveryMode() . (2 === $c->getDeliveryMode() ? ' (persistent)' : ' (non-persistent)'), $c->getDeliveryMode()), $prefix . 'exchangeName' => $c->getExchangeName(), $prefix . 'isRedelivery' => $c->isRedelivery(), $prefix . 'contentType' => $c->getContentType(), $prefix . 'contentEncoding' => $c->getContentEncoding(), $prefix . 'type' => $c->getType(), $prefix . 'timestamp' => $c->getTimestamp(), $prefix . 'priority' => $c->getPriority(), $prefix . 'expiration' => $c->getExpiration(), $prefix . 'userId' => $c->getUserId(), $prefix . 'appId' => $c->getAppId(), $prefix . 'messageId' => $c->getMessageId(), $prefix . 'replyTo' => $c->getReplyTo(), $prefix . 'correlationId' => $c->getCorrelationId(), $prefix . 'headers' => $c->getHeaders());
     return $a;
 }
Exemplo n.º 2
0
 public function retrieveHeaders(\AMQPEnvelope $envelope)
 {
     $headers = $envelope->getHeaders();
     if ($envelope->getReplyTo() !== '' && !isset($headers[HeaderTypeEnum::REPLY_TO_ADDRESS])) {
         $headers[HeaderTypeEnum::REPLY_TO_ADDRESS] = $envelope->getReplyTo();
     }
     if ($envelope->getCorrelationId() !== '') {
         $headers[HeaderTypeEnum::CORRELATION_ID] = $envelope->getCorrelationId();
     }
     if ($envelope->getType() !== '' && !isset($headers[HeaderTypeEnum::ENCLOSED_CLASS])) {
         $headers[HeaderTypeEnum::ENCLOSED_CLASS] = $envelope->getType();
     }
     return $headers;
 }
Exemplo n.º 3
0
 public function fromEnvelope(\AMQPEnvelope $envelope)
 {
     $this->setAppId($envelope->getAppId());
     $this->setBody($envelope->getBody());
     $this->setContentEncoding($envelope->getContentEncoding());
     $this->setContentType($envelope->getContentType());
     $this->setCorrelationId($envelope->getCorrelationId());
     $this->setDeliveryMode($envelope->getDeliveryMode());
     $this->setDeliveryTag($envelope->getDeliveryTag());
     $this->setExchangeName($envelope->getExchangeName());
     $this->setExpiration($envelope->getExpiration());
     $this->setHeaders($envelope->getHeaders());
     $this->setMessageId($envelope->getMessageId());
     $this->setPriority($envelope->getPriority());
     $this->setReplyTo($envelope->getReplyTo());
     $this->setRoutingKey($envelope->getRoutingKey());
     $this->setTimeStamp($envelope->getTimeStamp());
     $this->setType($envelope->getType());
     $this->setUserId($envelope->getUserId());
     $this->setRedelivery($envelope->isRedelivery());
     return $this;
 }
Exemplo n.º 4
0
 /**
  * @param \AMQPEnvelope $envelope
  * @return string
  */
 public static function envelopeToString(\AMQPEnvelope $envelope)
 {
     $m = '';
     $m .= 'AppId: ' . $envelope->getAppId() . "\n";
     $m .= 'Body: ' . $envelope->getBody() . "\n";
     $m .= 'ContentEncoding: ' . $envelope->getContentEncoding() . "\n";
     $m .= 'ContentType: ' . $envelope->getContentType() . "\n";
     $m .= 'CorrelationId: ' . $envelope->getCorrelationId() . "\n";
     $m .= 'DeliveryTag: ' . $envelope->getDeliveryTag() . "\n";
     $m .= 'ExchangeName: ' . $envelope->getExchangeName() . "\n";
     $m .= 'Expiration: ' . $envelope->getExpiration() . "\n";
     $m .= 'Headers: ' . json_encode($envelope->getHeaders()) . "\n";
     $m .= 'MessageId: ' . $envelope->getMessageId() . "\n";
     $m .= 'Priority: ' . $envelope->getPriority() . "\n";
     $m .= 'ReplyTo: ' . $envelope->getReplyTo() . "\n";
     $m .= 'RoutingKey: ' . $envelope->getRoutingKey() . "\n";
     $m .= 'TimeStamp: ' . $envelope->getTimeStamp() . "\n";
     $m .= 'Type: ' . $envelope->getType() . "\n";
     $m .= 'UserId: ' . $envelope->getUserId() . "\n";
     $m .= 'isRedelivery: ' . $envelope->isRedelivery() . "\n";
     $m .= "\n";
     return $m;
 }
Exemplo n.º 5
0
 /**
  * Convert AMQP message to internal message format
  *
  * @param \AMQPEnvelope $envelope
  *
  * @return BaseMessage
  */
 public static function convert(\AMQPEnvelope $envelope)
 {
     $message = new BaseMessage();
     $message->setPayload($envelope->getBody())->setDeliveryMode($envelope->getDeliveryMode())->setHeaders($envelope->getHeaders())->setProperties(['content_type' => $envelope->getContentType(), 'content_encoding' => $envelope->getContentEncoding(), 'app_id' => $envelope->getAppId(), 'correlation_id' => $envelope->getCorrelationId(), 'delivery_tag' => $envelope->getDeliveryTag(), 'message_id' => $envelope->getMessageId(), 'priority' => $envelope->getPriority(), 'reply_to' => $envelope->getReplyTo(), 'routing_key' => $envelope->getRoutingKey(), 'exchange_name' => $envelope->getExchangeName(), 'timestamp' => $envelope->getTimeStamp(), 'type' => $envelope->getType(), 'user_id' => $envelope->getUserId()]);
     return $message;
 }
 /**
  * @param \AMQPEnvelope $message
  * @throws \Exception
  */
 protected function processFailedSubscription(\AMQPEnvelope $message)
 {
     if (!$this->connection->isConnected()) {
         $this->connection->connect();
     }
     $attempt = $message->getHeader('redelivery_counter') ? $message->getHeader('redelivery_counter') : 1;
     if ($attempt < 3) {
         $headers = $message->getHeaders();
         $headers['redelivery_counter'] = ++$attempt;
         $attributes = array_merge($this->messageAttributes, ['content_type' => $message->getContentType(), 'headers' => $headers]);
         $this->getExchange()->publish($message->getBody(), $message->getRoutingKey(), AMQP_NOPARAM, $attributes);
     }
     $this->getQueue()->ack($message->getDeliveryTag());
 }
Exemplo n.º 7
0
 /**
  * @param \AMQPEnvelope                    $message
  * @param MessageEncodeDecodeStrategy|null $decodeStrategy
  *
  * @return static
  * @throws \yii\base\InvalidConfigException
  */
 public static function createFromRaw(\AMQPEnvelope $message, $decodeStrategy = null)
 {
     return \Yii::createObject(['class' => static::class, 'body' => $message->getBody(), 'routingKey' => $message->getRoutingKey(), 'deliveryTag' => $message->getDeliveryTag(), 'deliveryMode' => $message->getDeliveryMode(), 'exchangeName' => $message->getExchangeName(), 'redelivery' => $message->isRedelivery(), 'contentType' => $message->getContentType(), 'contentEncoding' => $message->getContentEncoding(), 'type' => $message->getType(), 'timestamp' => $message->getTimeStamp(), 'priority' => $message->getPriority(), 'expiration' => $message->getExpiration(), 'userId' => $message->getUserId(), 'appId' => $message->getAppId(), 'messageId' => $message->getMessageId(), 'replyTo' => $message->getReplyTo(), 'correlationId' => $message->getCorrelationId(), 'headers' => $message->getHeaders(), 'decodeStrategy' => $decodeStrategy]);
 }
Exemplo n.º 8
0
 /**
  * @inheritdoc
  */
 public function getHeaders()
 {
     return $this->delegate->getHeaders();
 }