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

[FEATURE] 希望在ConsumerMessage里加一个getNums()实现注解@Consumer(nums=1) 相同效果 #4442

Closed
maimake opened this issue Jan 11, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@maimake
Copy link

maimake commented Jan 11, 2022

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

amqp 的消费者运行数量希望能够通过 配置文件/中心/环境变量 获取数量配置,就像getEnable()那样允许自定义

Describe the solution you'd like
A clear and concise description of what you want to happen.

namespace Hyperf\Amqp;

class ConsumerManager
{
    public function run()
    {
        $classes = AnnotationCollector::getClassesByAnnotation(ConsumerAnnotation::class);
        /**
         * @var string $class
         * @var ConsumerAnnotation $annotation
         */
        foreach ($classes as $class => $annotation) {
            // ...
            //$nums = $annotation->nums; 
            ! is_null($annotation->nums) && $instance->setNums($annotation->nums);
            $process = $this->createProcess($instance);
            $process->nums = $instance->getNums(); // 通过 getter 能够自定义数量
            // ...  
        }
    }
namespace Hyperf\Amqp\Message;

abstract class ConsumerMessage extends Message implements ConsumerMessageInterface
{
    /**
     * @var int 
     */
    protected $nums = 1;

    /**
     * @return int
     */
    public function getNums(): int
    {
        return $this->nums;
    }

    /**
     * @param int $nums
     */
    public function setNums(int $nums): self
    {
        $this->nums = $nums;
        return $this;
    }
}

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@maimake maimake added the enhancement New feature or request label Jan 11, 2022
@limingxinleo
Copy link
Member

感觉还可以

@huangzhhui

@huangzhhui
Copy link
Member

嗯,看起来可以

@limingxinleo
Copy link
Member

提个pr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants