承接 leberknecht/amqp-rpc-transporter-bundle 相关项目开发

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

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

leberknecht/amqp-rpc-transporter-bundle

最新稳定版本:v1.0.0

Composer 安装命令:

composer require leberknecht/amqp-rpc-transporter-bundle

包简介

The bundle implements RPC functionality for AMQP protocol to the messenger component

README 文档

README

A workaround bundle to bring RPC functionality to the AMQP transporter of the Symfony messenger component

What it does

This bundle introduces ampqp-rpc transporter, which is identical to the normal amqp transporter, except that it will use reply_to and correlation_id headers. On receive, the content of the HandledStamp will be published to the queue identified in the reply_to field. On send, a random queue name will be generated and after publishing the original message, we will wait for a response on that queue, then adding ResponseStamp with the result to the envelope.

Installation

composer require leberknecht/amqp-rpc-transporter-bundle

Usage

# messenger.yaml
framework:
    messenger:
        transports:
            rpc_calls:
                dsn: 'amqp-rpc://user:password@rabbit-mq-host/%2f/rpc_calls'
        routing:
            # Route your messages to the transports
            'App\Message\RpcCallMessage': rpc_calls

Then use it like this:

    // send
    $rpcCallMessage = new RpcCallMessage();

    $envelope = $this->messageBus->dispatch($rpcCallMessage);
    /** @var ResponseStamp $response */
    $response = $envelope->last(ResponseStamp::class);
    $result = $response->getResult();

To set the result from the handler, just return something:

    final public function __invoke(RpcCallMessage $message): void
    {
        [...]
        return 42;
    }

Remarks

This is a work-in-progress, as a first-shot workaround. It would be much more elegant to override the messenger.transport.amqp.factory service and add rpc: true and rpc_queue_name to the messenger config, so we extend the existing transporter instead of bringing in this new one. Also note: in this state, we will always generate a exclusive queue with a random name for the response. This is sub-optimal for heavy loaded queues, see https://www.rabbitmq.com/tutorials/tutorial-six-python.html

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2020-03-29