Пример #1
0
 /**
  * @test
  */
 public function it_can_get_and_set()
 {
     $props = new MessageProperties(['foo' => 'bar']);
     $message = new Message('test');
     $message->setBody('test2');
     $message->setRoutingKey('route2');
     $message->setProperties($props);
     $this->assertEquals('test2', $message->getBody());
     $this->assertEquals('route2', $message->getRoutingKey());
     $this->assertSame($props, $message->getProperties());
 }
Пример #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);
 }
 /**
  * @param OutputInterface $output
  * @param Message         $message
  * @param string          $payload
  */
 protected function notify(OutputInterface $output, Message $message, $payload)
 {
     $output->writeln(sprintf('Published message for <info>%s</info>', json_encode($payload)));
     if ($output->getVerbosity() > $output::VERBOSITY_VERBOSE) {
         $output->writeln(sprintf('=> Message body: <comment>%s</comment>', $message->getBody()));
     }
 }