承接 niladalia/rabbit-messenger-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

niladalia/rabbit-messenger-bundle

Composer 安装命令:

composer require niladalia/rabbit-messenger-bundle

包简介

A simple Symfony bundle that says 'Hello, World!'

README 文档

README

This repository contains a simple template for building event-driven microservices using the Rabbit Messenger Bundle.

Requirements

You need to have a running RabbitMQ configuration or a Docker setup to use this bundle effectively.

Installation

To integrate the Rabbit Messenger Bundle into your project, run the following command:

composer update niladalia/rabbit-messenger-bundle

Usage

Domain Events

Create Domain Events

Your domain event classes should extend the DomainEvent class provided by the bundle:

namespace RabbitMessengerBundle\Domain\Event;

class YourDomainEvent extends DomainEvent {
    // Your event properties and methods
}

Publishing Events

To publish events, inject the DomainEventPublisherInterface into the classes where you need to publish events. Call the publish method as shown below:

use RabbitMessengerBundle\Domain\Event\DomainEventPublisherInterface;

class YourService {
private $eventPublisher;

    public function __construct(DomainEventPublisherInterface $eventPublisher) {
        $this->eventPublisher = $eventPublisher;
    }

    public function someMethod() {
        $event = new YourDomainEvent(/* event data */);
        $this->eventPublisher->publish($event);
    }
}

Configuration

Messenger Configuration

In the messenger.yaml file of both your sender application and listener, specify the serializer as follows:

  serializer: RabbitMessengerBundle\Infrastructure\Serializer\MessengerSerializer

Event Listener Configuration

Implement the Domain Event Mapper

Your listener or receiver micro should implement the DomainEventMapperInterface.

This interface is responsible for mapping event types to the corresponding event classes in your microservice.

Your implementation must return an array with the following keys:

$map = [
    'aggregateId'
    'eventId'
    'attributes'
    'occurredOn'
];

It will also need to return a string with the full path for the domain event class of the recieved event from Rabbit.

Service Configuration

In the services.yaml file, specify the implementation for the DomainEventMapperInterface and ensure it is public:

App\Shared\Infrastructure\Event\DomainEventMapper:
    public: true  # Ensure the mapper is accessible

RabbitMessengerBundle\Domain\Event\Mapper\DomainEventMapperInterface: '@App\Shared\Infrastructure\Event\DomainEventMapper'

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-10-29