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

Barbeq Bundle Laravel Package

ano/barbeq-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle Add to your composer.json:

    composer require ano/barbeq-bundle
    

    Enable in config/bundles.php:

    return [
        // ...
        Ano\BarbeQBundle\AnoBarbeQBundle::class => ['all' => true],
    ];
    
  2. Configure BarbeQ Update config/packages/ano_barbeq.yaml (auto-generated after installation):

    ano_barbeq:
        connection: 'amqp://user:pass@localhost:5672/%2f'
        exchange: 'your_exchange'
        queue: 'your_queue'
        routing_key: 'your.routing.key'
    
  3. First Use Case: Publishing a Message Inject the BarbeQPublisher service and publish a message:

    use Ano\BarbeQBundle\Publisher\BarbeQPublisher;
    
    class SomeService
    {
        public function __construct(private BarbeQPublisher $publisher)
        {
        }
    
        public function sendMessage()
        {
            $this->publisher->publish('your.message', ['data' => 'example']);
        }
    }
    

Implementation Patterns

Core Workflows

  1. Publishing Messages

    • Use BarbeQPublisher to send messages to RabbitMQ:
      $this->publisher->publish('event.name', ['payload' => $data]);
      
    • Supports serialization (default: JSON) via BarbeQPublisher::setSerializer().
  2. Consuming Messages

    • Create a consumer service implementing Ano\BarbeQBundle\Consumer\ConsumerInterface:
      use Ano\BarbeQBundle\Consumer\ConsumerInterface;
      
      class MyConsumer implements ConsumerInterface
      {
          public function consume($message)
          {
              $data = json_decode($message, true);
              // Process $data
          }
      }
      
    • Register the consumer in services.yaml:
      services:
          App\Consumer\MyConsumer:
              tags:
                  - { name: 'ano_barbeq.consumer', routing_key: 'your.routing.key' }
      
  3. Error Handling

    • Implement Ano\BarbeQBundle\Consumer\ErrorHandlerInterface for custom error logic:
      class MyErrorHandler implements ErrorHandlerInterface
      {
          public function handleError($message, \Exception $e)
          {
              // Log or retry logic
          }
      }
      
    • Bind it in services.yaml:
      services:
          App\ErrorHandler\MyErrorHandler:
              tags: ['ano_barbeq.error_handler']
      
  4. Dynamic Routing

    • Use BarbeQPublisher::publishWithRoutingKey() for dynamic routing:
      $this->publisher->publishWithRoutingKey('dynamic.key', ['data' => 'value']);
      

Integration Tips

  • Symfony Events: Trigger message publishing in event listeners:

    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class MessageSubscriber implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return ['event.name' => 'onEvent'];
        }
    
        public function onEvent()
        {
            $this->publisher->publish('event.processed', []);
        }
    }
    
  • Dependency Injection:

    • Prefer constructor injection for BarbeQPublisher and consumers to ensure testability.
  • Configuration Overrides:

    • Override bundle config per environment (e.g., config/packages/dev/ano_barbeq.yaml).

Gotchas and Tips

Pitfalls

  1. Connection Issues

    • Symptom: Messages silently fail to publish.
    • Fix: Verify ano_barbeq.connection in config matches your RabbitMQ setup. Test with:
      php bin/console debug:container --parameter=ano_barbeq.connection
      
  2. Consumer Not Triggering

    • Symptom: Messages arrive in the queue but consumers don’t process them.
    • Fix: Ensure:
      • The consumer service is tagged with ano_barbeq.consumer.
      • The routing_key in the tag matches the published message’s routing key.
      • RabbitMQ user has permissions to access the queue/exchange.
  3. Serialization Errors

    • Symptom: Non-serializable objects break publishing.
    • Fix: Implement JsonSerializable or use a custom serializer:
      # config/packages/ano_barbeq.yaml
      ano_barbeq:
          serializer: 'App\Serializer\CustomSerializer'
      
  4. Duplicate Consumers

    • Symptom: Multiple instances of the same consumer process messages.
    • Fix: Use prefetch count in RabbitMQ or implement idempotency in your consumer logic.

Debugging

  1. Check Queue Status Use RabbitMQ management UI (http://localhost:15672) to verify:

    • Messages are enqueued.
    • Consumers are connected.
  2. Enable Logging Add to config/packages/monolog.yaml:

    handlers:
        ano_barbeq:
            type: stream
            path: "%kernel.logs_dir%/ano_barbeq.log"
            level: debug
            channels: ["ano_barbeq"]
    

    Then configure the bundle to use the channel:

    # config/packages/ano_barbeq.yaml
    ano_barbeq:
        logging_channel: "ano_barbeq"
    
  3. Test Locally Use a Dockerized RabbitMQ for development:

    docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:management
    

Extension Points

  1. Custom Serializers Implement Ano\BarbeQBundle\Serializer\SerializerInterface and bind it in services.yaml:

    services:
        App\Serializer\ProtobufSerializer:
            tags: ['ano_barbeq.serializer']
    
  2. Middleware Pipeline Add processing steps before/after message handling:

    use Ano\BarbeQBundle\Consumer\Middleware\ConsumerMiddlewareInterface;
    
    class LoggingMiddleware implements ConsumerMiddlewareInterface
    {
        public function handle($message, callable $next)
        {
            \Log::info('Processing message', ['message' => $message]);
            return $next($message);
        }
    }
    

    Register in services.yaml:

    services:
        App\Middleware\LoggingMiddleware:
            tags: ['ano_barbeq.consumer_middleware']
    
  3. Retry Logic Extend Ano\BarbeQBundle\Consumer\ConsumerInterface to implement retries:

    class RetryConsumer implements ConsumerInterface
    {
        private $retries = 0;
        private $maxRetries = 3;
    
        public function consume($message)
        {
            try {
                // Business logic
            } catch (\Exception $e) {
                if ($this->retries++ < $this->maxRetries) {
                    throw $e; // Requeue automatically
                }
                throw new \RuntimeException('Max retries exceeded');
            }
        }
    }
    
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
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
spatie/mailcoach-vapor