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

Asynchronous Laravel Package

simple-bus/asynchronous

Generic PHP classes and interfaces for processing messages asynchronously with a SimpleBus MessageBus. Provides building blocks to queue, publish, and handle messages outside the request cycle; integrates with SimpleBus components and documented usage guides.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven Fit: The package excels in Laravel applications requiring asynchronous messaging, event-driven workflows, or decoupled microservices. It aligns well with Laravel’s event system (e.g., Illuminate\Events) but provides a more generic, bus-based alternative for complex workflows.
  • CQRS/ES Potential: Ideal for Command Query Responsibility Segregation (CQRS) or Event Sourcing (ES) patterns where commands/messages must be processed asynchronously without blocking the main request flow.
  • Laravel Integration: While Laravel has built-in queue workers (queue:work), this package offers higher-level abstractions (e.g., message dispatching, retries, middleware) that could reduce boilerplate for multi-step async processes.

Integration Feasibility

  • Laravel Compatibility:
    • Works with Laravel’s PSR-15 middleware and PSR-11 container (via Laravel’s service container).
    • Can integrate with Laravel’s queue system (e.g., database, redis, beanstalkd) as the underlying transport layer.
    • No native Laravel integration: Requires manual setup (e.g., binding interfaces to implementations in AppServiceProvider).
  • PHP Version: Supports PHP 8.0+ (Laravel 9+), ensuring compatibility with modern Laravel versions.
  • Database/Queue Backend: Relies on a message queue (e.g., RabbitMQ, Redis, SQS) or database-backed queue (e.g., Laravel’s queue:table). No built-in persistence layer—must be configured separately.

Technical Risk

  • Learning Curve:
    • SimpleBus ecosystem is niche compared to Laravel’s native queues. Team familiarity with message buses (e.g., SimpleBus\MessageBus) may be required.
    • Middleware vs. Laravel Queues: Developers accustomed to Laravel’s dispatch() + HandleJobs may need to adapt to message handlers and bus middleware.
  • Error Handling:
    • Retries and dead-letter queues must be explicitly configured (not as plug-and-play as Laravel’s queue failures).
    • No built-in monitoring: Unlike Laravel Horizon, this package lacks native dashboards for queue metrics.
  • Performance Overhead:
    • Serialization: Messages must be serializable (e.g., json_encode/json_decode). Complex objects (e.g., Eloquent models) may require custom serialization.
    • Transaction Boundaries: Async processing breaks database transactions by default (must use Saga pattern or compensating transactions for ACID guarantees).

Key Questions

  1. Why Async Bus Over Laravel Queues?
    • Does the team need advanced routing (e.g., message filtering, dynamic handlers) beyond Laravel’s queue:listen?
    • Is message correlation (e.g., tracking related commands/events) a requirement?
  2. Queue Backend Choice
    • Will the app use Laravel’s database queue (simpler) or a dedicated broker (e.g., RabbitMQ for scalability)?
  3. Error Recovery Strategy
    • How will failed messages be handled? (e.g., retries, dead-letter queues, alerts)
  4. Monitoring & Observability
    • Are there plans to integrate with Laravel Scout, Prometheus, or custom metrics?
  5. Team Expertise
    • Does the team have experience with message buses (e.g., SimpleBus, Symfony Messenger) or will this require upskilling?

Integration Approach

Stack Fit

  • Laravel Core: Complements Laravel’s events, jobs, and queues but provides a more flexible messaging layer.
    • Example: Replace event(new OrderCreated()) with bus->dispatch(new OrderCreatedMessage()) for async processing.
  • Microservices: Ideal for service-to-service communication where Laravel acts as a message producer/consumer.
  • Legacy Systems: Useful for decoupling Laravel from monolithic systems via message queues.

Migration Path

  1. Pilot Phase:
    • Start with non-critical async workflows (e.g., sending emails, logging analytics).
    • Replace dispatch(new SendEmailJob()) with bus->dispatch(new EmailMessage()).
  2. Incremental Adoption:
    • Step 1: Integrate SimpleBus alongside Laravel queues (e.g., use SimpleBus for complex workflows, queues for simple tasks).
    • Step 2: Migrate event listeners to message handlers where async processing is needed.
    • Step 3: Replace custom queue jobs with SimpleBus messages for consistency.
  3. Queue Backend Setup:
    • Configure a message transport (e.g., Redis, RabbitMQ) and bind it to SimpleBus:
      $bus = new SimpleBus\Asynchronous\MessageBus(
          new SimpleBus\Asynchronous\Redis\RedisMessageStorage($redis),
          new SimpleBus\Asynchronous\Redis\RedisQueue($redis),
          new SimpleBus\MessageBus\MessageBus(
              new SimpleBus\MessageBus\Middleware\CreateBus(new SimpleBus\MessageBus\Middleware\MiddlewareStack([]))
          )
      );
      
    • Alternatively, use Laravel’s database queue as a fallback:
      $queue = new SimpleBus\Asynchronous\Database\DatabaseQueue(
          new Illuminate\Database\DatabaseManager()
      );
      

Compatibility

  • Laravel Services:
    • Events: Convert Event::dispatch() to bus->dispatch() for async events.
    • Jobs: Replace dispatch(new Job()) with bus->dispatch(new Message()) where async is required.
    • Commands: Use for long-running CLI commands (e.g., artisan process:async).
  • Third-Party Packages:
    • Laravel Horizon: Can monitor SimpleBus queues if they use the same backend (e.g., Redis).
    • Symfony Messenger: If the team uses both, consider unifying on one to avoid complexity.

Sequencing

  1. Define Message Contracts:
    • Create DTOs (e.g., OrderCreatedMessage) for all async operations.
    • Example:
      class OrderCreatedMessage implements SimpleBus\Message\Message {
          public function __construct(public int $orderId) {}
      }
      
  2. Implement Handlers:
    • Register message handlers as Laravel service providers:
      $bus->subscribeTo(OrderCreatedMessage::class, new HandleOrderCreated());
      
  3. Configure Middleware:
    • Add retry logic, logging, or validation via SimpleBus middleware:
      $middlewareStack = new SimpleBus\MessageBus\Middleware\MiddlewareStack([
          new SimpleBus\MessageBus\Middleware\RetryMiddleware(),
          new SimpleBus\MessageBus\Middleware\LogMiddleware(),
      ]);
      
  4. Deploy Queue Workers:
    • Run SimpleBus workers alongside Laravel’s queue workers:
      php artisan simplebus:consume
      
    • Or integrate with Laravel’s queue:work if using the same backend.

Operational Impact

Maintenance

  • Boilerplate Reduction:
    • Pros: Less custom queue job boilerplate (no HandleJobs, just message handlers).
    • Cons: Additional interface definitions and message classes to maintain.
  • Dependency Management:
    • SimpleBus is MIT-licensed and actively maintained (last release: ~2023).
    • No Laravel-specific updates: Requires manual syncing with Laravel versions (e.g., PHP 8.2 features).
  • Testing:
    • Easier to mock: Message buses can be stubbed for unit tests.
    • Integration tests: Require a real queue backend (e.g., SQLite for testing).

Support

  • Debugging:
    • Complexity: Async message flows are harder to debug than synchronous code.
    • Tools: Leverage Laravel’s queue:failed table + SimpleBus logs.
  • Community:
    • Limited Laravel-Specific Support: Most SimpleBus docs assume a generic PHP setup.
    • Workarounds: May need to create Laravel-specific middleware or queue listeners.
  • Vendor Lock-in:
    • Low: SimpleBus follows PSR standards, so migrating to other buses (e.g., Symfony Messenger) is feasible.

Scaling

  • Horizontal Scaling:
    • Queue Workers: Scale SimpleBus consumers like Laravel queue workers (e.g., Kubernetes pods, EC2 auto-scaling).
    • Broker Choice: RabbitMQ or Redis clusters support millions of messages/sec.
  • Performance:
    • Latency: Async processing adds network + serialization overhead (~50–200ms per message).
    • Throughput: Depends on queue backend (e.g., Redis: ~10K msg/sec; RabbitMQ: ~1M msg/sec).
  • Resource Usage:
    • Memory: Message handlers must be stateless (no shared memory between workers).
    • Database: Heavy async workloads may
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
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