/**
  * @test
  */
 public function it_logs_messages_when_rejecting_a_message()
 {
     $context = [];
     $context['correlation_id'] = new StringLiteral('my-correlation-id-123');
     $this->logger->expects($this->at(0))->method('info')->with('received message with content-type application/vnd.cultuurnet.udb3-events.dummy-event+json', $context);
     $this->logger->expects($this->at(1))->method('error')->with('Deserializerlocator error', $context + ['exception' => new \InvalidArgumentException('Deserializerlocator error')]);
     $this->logger->expects($this->at(2))->method('info')->with('message rejected', $context);
     $this->deserializerLocator->expects($this->once())->method('getDeserializerForContentType')->with(new StringLiteral('application/vnd.cultuurnet.udb3-events.dummy-event+json'))->willThrowException(new \InvalidArgumentException('Deserializerlocator error'));
     $this->channel->expects($this->once())->method('basic_reject')->with('my-delivery-tag');
     $messageProperties = ['content_type' => 'application/vnd.cultuurnet.udb3-events.dummy-event+json', 'correlation_id' => 'my-correlation-id-123'];
     $messageBody = '';
     $message = new AMQPMessage($messageBody, $messageProperties);
     $message->delivery_info['channel'] = $this->channel;
     $message->delivery_info['delivery_tag'] = 'my-delivery-tag';
     $this->eventBusForwardingConsumer->consume($message);
 }
 /**
  * @param AMQPMessage $message
  */
 public function consume(AMQPMessage $message)
 {
     $context = [];
     if ($message->has('correlation_id')) {
         $context['correlation_id'] = $message->get('correlation_id');
     }
     if ($this->logger) {
         $this->logger->info('received message with content-type ' . $message->get('content_type'), $context);
     }
     $contentType = new StringLiteral($message->get('content_type'));
     try {
         $deserializer = $this->deserializerLocator->getDeserializerForContentType($contentType);
         $domainMessage = $deserializer->deserialize(new StringLiteral($message->body));
         // If the deserializer did not return a DomainMessage yet, then
         // consider the returned value as the payload, and wrap it in a
         // DomainMessage.
         if (!$domainMessage instanceof DomainMessage) {
             $domainMessage = new DomainMessage(UUID::generateAsString(), 0, new Metadata($context), $domainMessage, DateTime::now());
         }
         $this->delayIfNecessary();
         if ($this->logger) {
             $this->logger->info('passing on message to event bus', $context);
         }
         $this->eventBus->publish(new DomainEventStream([$domainMessage]));
     } catch (\Exception $e) {
         if ($this->logger) {
             $this->logger->error($e->getMessage(), $context + ['exception' => $e]);
         }
         $message->delivery_info['channel']->basic_reject($message->delivery_info['delivery_tag'], false);
         if ($this->logger) {
             $this->logger->info('message rejected', $context);
         }
         return;
     }
     $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);
     if ($this->logger) {
         $this->logger->info('message acknowledged', $context);
     }
 }