Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • SensioLabs Professional services to help you with Symfony
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by
  1. Home
  2. Documentation
  3. Symfony: The Fast Track
  4. German
  5. RabbitMQ als Message-Broker nutzen

RabbitMQ als Message-Broker nutzen

RabbitMQ ist ein sehr beliebter Message-Broker den Du als Alternative zu PostgreSQL nutzen kannst.

Von PostgreSQL zu RabbitMQ wechseln

Um RabbitMQ anstelle von PostgreSQL als Message-Broker zu nutzen:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
--- a/config/packages/messenger.yaml
+++ b/config/packages/messenger.yaml
@@ -5,10 +5,7 @@ framework:
         transports:
             # https://symfony.com/doc/current/messenger.html#transport-configuration
             async:
-                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
-                options:
-                    use_notify: true
-                    check_delayed_interval: 60000
+                dsn: '%env(RABBITMQ_URL)%'
                 retry_strategy:
                     max_retries: 3
                     multiplier: 2

Wir müssen auch RabbitMQ-Unterstützung für Messenger hinzufügen:

1
$ symfony composer req amqp-messenger

Füge RabbitMQ zum Docker-Stack hinzu

Wie Du sicherlich schon erraten hast, müssen wir RabbitMQ auch in den Docker Compose-Stack aufnehmen:

1
2
3
4
5
6
7
8
9
10
11
12
13
--- a/compose.yaml
+++ b/compose.yaml
@@ -24,6 +24,10 @@ services:
     image: redis:5-alpine
     ports: [6379]

+  rabbitmq:
+    image: rabbitmq:3-management
+    ports: [5672, 15672]
+
 volumes:
 ###> doctrine/doctrine-bundle ###
   database_data:

Neustarten der Docker Dienste

Um Docker Compose zu zwingen den RabbitMQ-Container zu berücksichtigen, stoppe den Container und starte ihn neu:

1
2
$ docker compose stop
$ docker compose up -d
1
$ sleep 10

Die RabbitMQ Web-Verwaltungs-Oberfläche erkunden

Wenn Du die Queues und Nachrichten sehen willst, die durch RabbitMQ verwaltet werden, öffne seine Web-Verwaltungs-Oberfläche:

1
$ symfony open:local:rabbitmq

Oder mit der Web-Debug-Toolbar:

/

Nutze guest/guest als Login für die RabbitMQ Verwaltungs-Oberfläche:

/

RabbitMQ deployen

Man kann RabbitMQ auf dem Produktivsystem aktivieren, indem man es zu der Liste der Dienste hinzufügt:

1
2
3
4
5
6
7
8
9
10
11
--- a/.platform/services.yaml
+++ b/.platform/services.yaml
@@ -19,3 +19,8 @@ files:

 rediscache:
     type: redis:5.0
+
+queue:
+    type: rabbitmq:3.7
+    disk: 1024
+    size: S

Verweise auch darauf in der Web-Container-Konfiguration und aktiviere die amqp-PHP-Erweiterung:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
--- a/.platform.app.yaml
+++ b/.platform.app.yaml
@@ -8,6 +8,7 @@ dependencies:

 runtime:
     extensions:
+        - amqp
         - apcu
         - blackfire
         - ctype
@@ -42,6 +43,7 @@ mounts:
 relationships:
     database: "database:postgresql"
     redis: "rediscache:redis"
+    rabbitmq: "queue:rabbitmq"
     
 hooks:
     build: |

Wenn der RabbitMQ-Dienst in einem Projekt installiert ist, kannst Du auf die Web-Verwaltungs-Oberfläche über einen Tunnel zugreifen:

1
2
3
4
5
$ symfony cloud:tunnel:open
$ symfony open:remote:rabbitmq

# when done
$ symfony cloud:tunnel:close

Weiterführendes

  • RabbitMQ-Dokumentation.
Previous page Nutze Redis um Sessions zu speichern
Next page Was kommt als Nächstes?
This work, including the code samples, is licensed under a Creative Commons BY-NC-SA 4.0 license.
TOC
    Version

    Symfony 6.4 is backed by

    Code consumes server resources. Blackfire tells you how

    Code consumes server resources. Blackfire tells you how

    The life jacket for your team and your project

    The life jacket for your team and your project

    Version:
    Locale:
    ebook

    This book is backed by:

    see all backers

    Symfony footer

    Avatar of NickSdot, a Symfony contributor

    Thanks NickSdot for being a Symfony contributor

    2 commits • 90 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • What is Symfony?
      • Symfony at a Glance
      • Symfony Components
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • Symfony Community
      • SymfonyConnect
      • Events & Meetups
      • Projects using Symfony
      • Contributors
      • Symfony Jobs
      • Backers
      • Code of Conduct
      • Downloads Stats
      • Support
    • Blog

      • All Blog Posts
      • A Week of Symfony
      • Case Studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Living on the edge
      • Releases
      • Security Advisories
      • Symfony Insight
      • Twig
      • SensioLabs Blog
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Powered by

    Follow Symfony