定制 mmi/mmi-event-consumer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

mmi/mmi-event-consumer

Composer 安装命令:

composer require mmi/mmi-event-consumer

包简介

MMi Event Consumer with MMi Framework

README 文档

README

PHP library providing a message consumer abstraction for AMQP-compatible message brokers (RabbitMQ), built on the MMi Framework.

Features

  • Clean MessageConsumerInterface for consuming messages
  • AMQP implementation (AmqpMessageConsumer) using php-amqplib
  • Null implementation (NullMessageConsumer) for testing/disabling
  • PHP-DI integration with environment variable configuration

Requirements

  • PHP 8.4 or 8.5
  • Composer
  • ext-amqp PHP extension

Installation

composer require mmi/mmi-event-consumer

Quick Start

  1. Include the DI configuration in your application:
// In your PHP-DI config
return [
    // ... your config
    ...include 'vendor/mmi/mmi-event-consumer/src/MmiEventConsumer/di.consumer.php',
];
  1. Set environment variables:
MMI_CONSUMER_QUEUE_ENABLED=true
MMI_CONSUMER_QUEUE_HOST=rabbitmq
MMI_CONSUMER_QUEUE_PORT=5672
MMI_CONSUMER_QUEUE_VHOST=/
MMI_CONSUMER_QUEUE_USERNAME=guest
MMI_CONSUMER_QUEUE_PASSWORD=guest
  1. Inject and use:
use MmiEventConsumer\MessageConsumerInterface;

class MyService
{
    public function __construct(
        private MessageConsumerInterface $consumer
    ) {}

    public function start(): void
    {
        $this->run(function ($message) {
            // Process message
        });
    }
}

Configuration

Variable Default Description
MMI_CONSUMER_QUEUE_ENABLED false Enable/disable the AMQP consumer
MMI_CONSUMER_QUEUE_HOST localhost RabbitMQ host
MMI_CONSUMER_QUEUE_PORT 5672 RabbitMQ port
MMI_CONSUMER_QUEUE_VHOST '' RabbitMQ virtual host
MMI_CONSUMER_QUEUE_USERNAME '' RabbitMQ username
MMI_CONSUMER_QUEUE_PASSWORD '' RabbitMQ password

Development

Setup

git clone <repository-url>
cd mmi-event-consumer
composer install

Docker

docker build --build-arg PHP_VERSION=8.5 -t mmi-event-consumer .
docker run mmi-event-consumer sh -c "composer test:all"

Testing

# Run all checks (security, PHPCS, PHPStan, PHPMD, PHPUnit)
composer test:all

# Run PHPUnit only
composer test:phpunit

# Static analysis (level 8)
composer test:phpstan

# Code style check
composer test:phpcs

# Mess detection
composer test:phpmd

# Security check
composer test:security-checker

Code Fixing

# Run all fixers
composer fix:all

# PHP Code Beautifier
composer fix:phpcbf

# PHP-CS-Fixer
composer fix:php-cs-fixer

Reports

# Generate PHPMetrics HTML report
composer report:metrics
# Output: web/build/metrics/

Coverage reports are generated in:

  • HTML: web/build/phpunit/
  • Clover: .phpunit.coverage.clover.xml

Code Quality Standards

  • Coding Standard: PSR2 (PHP_CodeSniffer)
  • Static Analysis: PHPStan level 8
  • Mess Detection: PHPMD (Clean Code, Code Size, Design, etc.)
  • Security: Dependency vulnerability checking

CI/CD

GitHub Actions runs on pull requests and pushes:

  • Tests against PHP 8.4 and 8.5
  • Builds Docker image and runs composer test:all

Project Structure

src/MmiEventConsumer/
├── AmqpMessageConsumer.php      # RabbitMQ consumer implementation
├── MessageConsumerInterface.php # Consumer interface
├── NullMessageConsumer.php      # Null object implementation
└── di.consumer.php              # PHP-DI configuration

tests/
└── Unit/MmiEventConsumer/
    └── NullMessageConsumerTest.php

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固