Skip to content

Latest commit

 

History

History
140 lines (91 loc) · 2.71 KB

README.md

File metadata and controls

140 lines (91 loc) · 2.71 KB

Tutorial for using the Symfony Messenger component

image

image

image

Steps

1. Clone the repo

> git clone [email protected]:makomweb/symfony-messenger-tutorial.git

2. Composer install

> cd <symfony-messenger-tutorial>
> composer install

3. Set up the database

php bin/console doctrine:database:create
php bin/console doctrine:schema:update --force

4. Start RabbitMQ via docker

> docker-composer up -d

5. Start Symfony Development Server

> symfony server:start -d

6. Start the message consumer

> php bin/console messenger:consume async -vv

7. Access the app

Your app is running locally under https://127.0.0.1:8000

8. Access the RabbitMQ admin console

Your app is running locally under http://guest:[email protected]:15672

Learnings

Create a new project with dependency to Messenger

> symfony new messenger-tutorial
> symfony server:start
> composer require symfony/messenger

Create a new controller

> composer req maker --dev
> composer req annotations
> symfony console make:controller FileUploadController

Configure an async transport

Add persistence

> composer require symfony/orm-pack
> composer require --dev symfony/maker-bundle

Create a new entity "FileUpload"

> php bin/console make:entity

With the properties:

  • name | string | 255 | not null
  • status | string | 255 | not null

Create the database + create migration + run migration

php bin/console doctrine:database:create
php bin/console make:migration
php bin/console doctrine:migrations:migrate

Show file uploads

# to install TWIG view rendering engine
> composer require twig 

Consume message asynchronously

symfony console messenger:consume async -vv

Add RabbitMQ

RabbitMQ is part of the docker-compose inside this repo.

You can start a docker container with docker-compose up -d.

After the container is up you can access the webfrontend via http://guest:guest@localhost:15672.


Fileupload

Migrations

  • php bin/console make:migration
  • php bin/console doctrine:migrations:migrate

Create DB + create Schema

  • php bin/console doctrine:database:create
  • php bin/console doctrine:schema:create
  • php bin/console doctrine:schema:update --force