Architecture of complex web applications by Adel F

Architecture of complex web applications by Adel F

Author:Adel F [Adel F]
Language: eng
Format: epub
Publisher: leanpub.com
Published: 2019-03-12T00:00:00+00:00


Queues

Second problem - request execution time. Application should respond as fast as possible. Poll creation contains some heavy operations like sitemap update and external API calling. Common solution - postpone some actions using queues. Instead of executing some heavy action in the web request, the application can create a task to execute this action and put it to a queue. A queue can be a database table, Redis list or special queue solutions, like RabbitMQ. Laravel suggests several ways to work with queues. One of them: jobs. As I said before, usually there is one main action and some secondary actions. The main action here is creating a Poll object and it can’t be executed without filtering texts. All post-actions can be executed later. Actually, in some rare cases when it takes too long, the whole application layer action can be executed in a queued job. But this is not our case.

final class SitemapGenerationJob implements ShouldQueue { public function handle() { // Call sitemap generator } } final class NotifyExternalApiJob implements ShouldQueue {} use Illuminate\Contracts\Bus\Dispatcher; final class PollService { /** @var Dispatcher */ private $dispatcher; public function __construct(..., Dispatcher $dispatcher) { ... $this->dispatcher = $dispatcher; } public function create(PollCreateDto $request) { $filteredRequest = $this->filterRequest($request); $poll = new Poll(); $this->connection->transaction(...); $this->dispatcher->dispatch( new SitemapGenerationJob()); $this->dispatcher->dispatch( new NotifyExternalApiJob($poll->id)); } }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.