Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Symfony Messenger Pubsub Bundle Laravel Package

cedricziel/symfony-messenger-pubsub-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle

    composer require cedricziel/symfony-messenger-pubsub-bundle
    
  2. Configure Messenger Transport Add the DSN to your .env:

    MESSENGER_TRANSPORT_DSN=pubsub://your-project-id/your-topic?subscription=your-subscription
    

    Ensure your config/packages/messenger.yaml includes the transport:

    framework:
        messenger:
            transports:
                pubsub: '%env(MESSENGER_TRANSPORT_DSN)%'
    
  3. First Use Case: Send a Message Dispatch a message via CLI:

    php bin/console messenger:send MyMessageClass
    

    Verify the message appears in your Pub/Sub topic.


Where to Look First

  • Bundle Docs: GitHub README (minimal but clear).
  • Symfony Messenger Docs: Official Guide for core concepts.
  • Pub/Sub CLI: Use gcloud pubsub topics list to validate topic/subscription names.

Implementation Patterns

Workflows

  1. Push vs. Pull

    • Push: Configure HTTP endpoint via routes.xml (auto-generated by the bundle). Useful for real-time processing.
      # config/routes.yaml
      _pubsub_push:
          resource: '@GoogleCloudPubSubMessengerBundle/Resources/config/routes.xml'
      
    • Pull: Default CLI-based polling (configured via MESSENGER_TRANSPORT_DSN). Use for batch processing.
  2. Message Handling

    • Symfony Message Classes: Extend Symfony\Component\Messenger\Message or use DTOs.
      class MyMessage implements MessageInterface {
          public string $content;
      }
      
    • Handlers: Register handlers in config/packages/messenger.yaml:
      framework:
          messenger:
              handlers:
                  my_handler:
                      type: MyMessage
                      handler: App\MessageHandler\MyHandler
      
  3. Retry Logic Leverage Symfony’s retry strategy for transient failures:

    transports:
        pubsub:
            dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
            retry_strategy:
                max_retries: 3
                delay: 1000
    

Integration Tips

  • Google Cloud Auth: Ensure your service account has pubsub.publisher and pubsub.subscriber roles.
  • Environment Separation: Use different DSNs for dev/staging/prod (e.g., pubsub://project-dev/topic).
  • Monitoring: Integrate with Stackdriver or Cloud Logging for message tracking.

Gotchas and Tips

Pitfalls

  1. DSN Format

    • Incorrect Format: pubsub://project/topic?subscription=sub is required. Omitting subscription causes silent failures.
    • Debugging: Use php bin/console debug:messenger to validate transport configuration.
  2. Push Endpoint

    • CORS Issues: If using push, ensure your HTTP endpoint accepts POST requests from Google’s IPs (check Pub/Sub docs).
    • Route Conflict: Prefix _pubsub_push routes to avoid clashes with existing routes.
  3. Message Size Limits

    • Pub/Sub enforces a 10MB message limit. For larger payloads, use Cloud Storage or compress data.

Debugging

  • Logs: Enable debug mode (APP_DEBUG=1) to see transport errors.
  • CLI Testing: Simulate messages with:
    php bin/console messenger:consume pubsub -vv
    
  • Pub/Sub UI: Verify messages in Google Cloud Console.

Extension Points

  1. Custom Middleware Add middleware to transform messages before sending:

    framework:
        messenger:
            transports:
                pubsub:
                    dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                    middleware:
                        - App\Middleware\PubSubSerializer
    
  2. Async Processing Use Symfony’s async workers for high-throughput topics:

    php bin/console messenger:consume pubsub -w --limit=100
    
  3. Event Listeners Hook into MESSENGER_MESSAGE_SENT/MESSENGER_MESSAGE_FAILED events for auditing:

    // config/services.yaml
    App\EventListener\PubSubLogger:
        tags:
            - { name: kernel.event_listener, event: MESSENGER_MESSAGE_SENT, method: onMessageSent }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky