Exemplo n.º 1
0
 /**
  * @test
  */
 public function it_can_get_and_set_headers()
 {
     $message = new Message('test');
     $this->assertSame([], $message->getHeaders());
     $this->assertFalse($message->getHeader('foo'));
     $message->setHeader('foo', 'bar');
     $this->assertSame(['foo' => 'bar'], $message->getHeaders());
     $this->assertSame('bar', $message->getHeader('foo'));
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function publish(Message $message, \DateTime $date = null, $flags = ExchangeInterface::NOPARAM)
 {
     if ($date instanceof \DateTime) {
         $delay = $date->getTimestamp() - time();
         if ($delay < 0) {
             throw new \OutOFBoundsException('You cannot publish a message in the past');
         }
         // set delay in milliseconds
         $message->setHeader(MessageProperties::KEY_DELAY, $delay * 1000);
     }
     $body = $message->getBody();
     $route = $message->getRoutingKey();
     $props = $message->getProperties()->toArray();
     return $this->exchange->publish($body, $route, $flags, $props);
 }