Skip to content

Add Rpc dot path generator#3626

Merged
limingxinleo merged 4 commits intomasterfrom
rpc-dot-path-generator
May 30, 2021
Merged

Add Rpc dot path generator#3626
limingxinleo merged 4 commits intomasterfrom
rpc-dot-path-generator

Conversation

@huangzhhui
Copy link
Copy Markdown
Member

@huangzhhui huangzhhui commented May 27, 2021

  • Add 「dot」 style path generator for RPC, allow the method of rpc service using FooSerivce.Bar style to instead of URL Style /foo/bar
  • The default priority of listeners is 1, so user could create an new listener to replace the data of protocol manager

How to use:
Create an Listener like below

<?php

namespace App\Listener;


use Hyperf\Di\Annotation\Inject;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Framework\Event\BootApplication;
use Hyperf\Rpc\PathGenerator\DotPathGenerator;

/**
 * @Listener(priority=0)
 */
class RpcProtocolRegister implements ListenerInterface
{

    /**
     * @Inject()
     * @var \Hyperf\Rpc\ProtocolManager
     */
    protected $protocolManager;

    public function listen(): array
    {
        return [
            BootApplication::class,
        ];
    }

    public function process(object $event)
    {
        $this->protocolManager->registerOrAppend('jsonrpc-http', [
            'path-generator' => DotPathGenerator::class,
        ]);
    }
}

}
return null;
}),
}) => intval(2147483647 / 2),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认的权重不就是一半么?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认权重是 1,我觉得这里还是默认吧。。。用户只需要设置成 0,就能覆盖官方的监听器了

@limingxinleo limingxinleo merged commit 2c40ec0 into master May 30, 2021
@limingxinleo limingxinleo deleted the rpc-dot-path-generator branch May 30, 2021 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants