[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rpc dot path generator #3626

Merged
merged 4 commits into from
May 30, 2021
Merged

Add Rpc dot path generator #3626

merged 4 commits into from
May 30, 2021

Conversation

huangzhhui
Copy link
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,
        ]);
    }
}

value(function () {
if (class_exists(ServiceManager::class)) {
return RegisterServiceListener::class;
}
return null;
}),
}) => intval(2147483647 / 2),
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
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