/** * @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')); }
/** * @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())); } }