Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cspray/amp-delivery-service

An implementation of DeliveryService using Amp's event reactor
https://github.com/cspray/amp-delivery-service

Last synced: about 1 month ago
JSON representation

An implementation of DeliveryService using Amp's event reactor

Awesome Lists containing this project

README

        

# DeliveryService

An implementation of [DeliveryService](https://github.com/cspray/delivery-service) using the [Amp]() event loop reactor.
It is expected before uing this library you understand how these 2 dependencies operate.

## DeliveryService Hello World

Here we take a look at the official Hello World example for DeliveryService implementations. This is
the bare minimum

```
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.

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