Ddd\Infrastructure\Application\Notification\AmqpMessageProducer::send PHP Method

send() public method

public send ( $exchangeName, $notificationMessage, $notificationType, $notificationId, DateTime $notificationOccurredOn )
$notificationOccurredOn DateTime
    public function send($exchangeName, $notificationMessage, $notificationType, $notificationId, DateTime $notificationOccurredOn)
    {
        $this->exchange->publish($notificationMessage, null, AMQP_NOPARAM, ['type' => $notificationType, 'timestamp' => $notificationOccurredOn->getTimestamp(), 'message_id' => $notificationId]);
    }

Usage Example

 /**
  * @test
  */
 public function itShouldBeAbleToSendMessagesToAnAmqpExchange()
 {
     if (!class_exists('AMQPConnection')) {
         $this->markTestSkipped('The AMQP extension is not available');
     }
     $this->exchange = $this->prophesize('AMQPExchange');
     $self = $this;
     $this->exchange->publish(Argument::cetera())->will(function ($args) use($self) {
         $self->publishedMessages[] = $args[0];
     });
     $loop = Factory::create();
     $this->messageProducer = new AmqpMessageProducer($this->exchange->reveal(), $loop);
     $this->messageProducer->send('exchange-test', 'This is a test1', 'test', 1, (new DateTime())->modify('+1 second'));
     $this->messageProducer->send('exchange-test', 'This is a test2', 'test', 2, (new DateTime())->modify('+5 second'));
     $this->messageProducer->send('exchange-test', 'This is a test3', 'test', 3, (new DateTime())->modify('+10 second'));
     sleep(1);
     $loop->tick();
     $this->assertCount(3, $this->publishedMessages);
 }