2017 © Pedro Peláez
 

library amp-delivery-service

Send intra-process messages using Amp event reactor`.

image

cspray/amp-delivery-service

Send intra-process messages using Amp event reactor`.

  • Thursday, September 24, 2015
  • by cspray
  • Repository
  • 1 Watchers
  • 1 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

DeliveryService

An implementation of DeliveryService using the Amp event loop reactor. It is expected before uing this library you understand how these 2 dependencies operate., (*1)

DeliveryService Hello World

Here we take a look at the official Hello World example for DeliveryService implementations. This is the bare minimum, (*2)

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Cspray\DeliveryService;
use Cspray\DeliveryService\Amp\ReceiptPromisorFactory;
use Cspray\DeliveryService\Amp\Mediator;

$reactor = new Amp\NativeReactor();
$promisorFactory = new ReceiptPromisorFactory();
$transmitter = new DeliveryService\Transmitter($promisorFactory);
$receiver = new DeliveryService\Receiver();
$mediator = new Mediator($reactor, $transmitter, $receiver);

$message = new DeliveryService\GenericMessage('foobar', 'the payload');
$messagePromise = $transmitter->send($message);
$messagePromise->delivered(function() {
    echo "after listeners\n";
});

$receiver->listen('foobar', function(DeliveryService\Message $message) {
    echo "{$message->getType()}\n";
    echo "{$message->getPayload()}\n";
});

$mediator->startSendingMessages();

$reactor->tick();
$reactor->tick();

//--EXPECT--
foobar
the payload
after listeners

Two-tick delivery

The 2 ticks in the above example is not a mistake. We intentionally invoke message listeners the tick after it gets removed from the queue. This is done so that listeners run within the event loop and are invoked concurrently., (*3)

--------|------------------|------------------|---------------|---
 dequeue message     invoke listeners   invoke listeners      .
 queue listeners     dequeue message    dequeue message       .
                     queue listeners    queue listeners       .

The Versions

24/09 2015

dev-master

9999999-dev

Send intra-process messages using Amp event reactor`.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/09 2015

0.2.0

0.2.0.0

Send intra-process messages using Amp event reactor`.

  Sources   Download

MIT

The Requires

 

The Development Requires

19/09 2015

0.1.1

0.1.1.0

Send intra-process messages using Amp event reactor`.

  Sources   Download

MIT

The Requires

 

The Development Requires

07/09 2015

0.1.0

0.1.0.0

Send intra-process messages using Amp event reactor`.

  Sources   Download

MIT

The Requires

 

The Development Requires