On Github Domraider / phptour2016-slides
Copier coller le sous titre
/** * @param float $amount * @param string $user_id * @param string $auction_id */ class AuctionRaiseCommand extends Command { public static $handlers = [ AddUserToAuction::class, CheckBidAmount::class, NotifyParticipants::class ]; public function __construct(array $attributes = []) { // Validation parent::__construct($attributes); } }
class AddUserToAuction { protected $auction; public function __construct(AuctionRepository $auction) { $this->auction = $auction; } public function handle(AuctionRaiseCommand $command) { } }
$bus = new SimpleBus(); $bus->handle(new AuctionRaiseCommand([ 'user_id'=> '', 'auction_id'=>'', 'amount' => '' ]));
class AuctionCommand implements RetryOnFail, IsHandledAsynchronously { public function getMaxRetry(); public function getWorker(); public function getRetryDelay($tried); }via des middleware simplement ajoutés au bus
$bus = new SimpleBus(); $bus->appendMiddleware(new AsynchronousMiddleware()); $bus->appendMiddleware(new RetryOnFailMiddleware());Plusieurs librairies dispo des plus simples : tactician et simplebus aux plus complexes : broadway et prooph
class Worker extends Console { protected $signature = 'worker {--bind=tcp://0.0.0.0:25001 listen on}'; public function handle(Httpd $httpd) { $httpd->route('POST', '/', function(Request $request, Response $response) { $response->send("OK") ->subscribeCallback(null, null, function() { SyncBus::handle($request->getCommand()); }); }) $httpd->listen($this->option('bind')); } }Plusieurs librairies dispo des plus simples : tactician et simplebus aux plus complexes : broadway et prooph
$push = $zmq->push("tcp://pusher.svc.domraider.com:23499"); $push->send(new AuctionRaisedEvent());
$pull = $zmq->pull("tcp://0.0.0.0:23499"); $pull->subscribeCallback(function(AuctionRaisedEvent $event) { foreach($this->webSocket->sessions as $session) { $session->send($event); } });et pour la websocket allez voir thruway :)
kubectl scale --replicas=5 rc AuctionWorker
Sasha Gitry
composer install cp docker/worker/Dockerfile . cp docker/worker/.dockerignore . docker build -t worker:$version . docker tag latest worker:$version docker push worker:$version docker push worker:latestUn codebase donne x builds dockers qui vont donner eux mêmes y replication controller dans kubernetes Besoin d'un build automatisé avec versionning une image docker par version, le build ne donne pas forcément lieu à un déploiement jenkins docker , circle ci