定制 garlic/bus 二次开发

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

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

garlic/bus

Composer 安装命令:

composer require garlic/bus

包简介

Message Bus Bundle uses for communication among microservices through message bus (by default is RabbitMQ)

README 文档

README

This bundle allow microservices communicate to each other with RabbitMQ transport by providing message bus.

For correct usage the Bundle must be installed on both ends of communication (current and target services)

Installation

Just a couple things are necessary for this bundle works.

Add garlic/bus bundle to your composer.json

composer require garlic/bus

Run processor as a Daemon (add configuration to your supervisor.conf)

[program:garlic_communication]
command=/var/www/bin/console --env=prod --no-debug enqueue:consume --setup-broker
process_name=%(program_name)s_%(process_num)02d
numprocs=4
autostart=true
autorestart=true
tartsecs=0
user=www-data
redirect_stderr=true

Now you can use Garlic Bus

Optional: You can set timeout which will used to wait for response

Set variable REQUEST_TIMEOUT=30 where 30 is seconds

Usage

Common way to use

If you want to get response from current service you have to use 'request' method, like explained below

$data = $this->get('communicator') // Or you can call by class name. Example: $this->get(GarlicBus:class)
    ->request('targetServiceName') // Type of message. So far you can use ->request() or ->command() methods. Command provide mesage type that not need response. 
    ->post()                       // Set one of REST methods (post, put, delete). Bu default set GET 
    ->targetServiceAction(         // CamelCased route where slashes vere changed to upper letter by magic (example: getUser will changed to /get/user)
        array $path = [],          // Path parameters to query (example: ['user' => 1])
        array $query = [],         // Post or Get parameters to the query
        array $headers = []        // Additional headers
    );
    

or the same but using direct rout as a method parameter

$data = $this->get('communicator')
    ->request('targetServiceName')
    ->send(
        string $route, // Route to the target service action (example: /user/get)
        array $path = [], 
        array $query = [],
        array $headers = [] 
    );
    

Making async batch request with parallel processing

$data = $this->get('communicator')
    ->pool(
        'service1', // Target service name
        '/',        // Route to the target service action (example: /user/get)
        [],         // Path parameters to query
        [],         // Post or Get parameters to the query
        []          // Request headers
    )
    ->pool(
        'service1', // Target service name
        '/',        // Route to the target service action (example: /user/get)
        [],         // Path parameters to query
        [],         // Post or Get parameters to the query
        []          // Request headers
        )
    ->fetch();      // Get response from async queries pool

Working with files

make sure you add variables to .env

### host url, will be used by another service to get files from current service
HOST_URL=172.18.1.14

###files will be uploaded to this dir
UPLOAD_DIR = public/upload

###should be same for every service using same bus
SCP_USERNAME=www-data
SCP_PASSWORD=KJLgbJ32PIHDJU4

upload files from Request

 $handler = $this->get('Garlic\Bus\Service\File\FileHandlerService');
 $handler->handleFiles($_FILES['pictures']);

get file from another service

 $uploader = $this->get('Garlic\Bus\Service\File\ScpFileUploadService');
 $uploader->getFile(['host_url' => '172.18.0.1','origin_name' => '1.jpg','path' => 'public/upload/fsdljkahb.jpg']);

garlic/bus 适用场景与选型建议

garlic/bus 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.24k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2017 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「message bus」 「microservices」 「Microservises message bus」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 garlic/bus 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 garlic/bus 我们能提供哪些服务?
定制开发 / 二次开发

基于 garlic/bus 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 7
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-12-11