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

Auto register consumer for amqp-job #721

Merged
merged 10 commits into from
Oct 12, 2024
Merged

Conversation

huangdijia
Copy link
Contributor

@anhao
Copy link

anhao commented Oct 12, 2024

我测试的时候,直接 make JobConsumer 消费完消息后 Process 会重启,通过创建匿名类就是正常的

@anhao
Copy link

anhao commented Oct 12, 2024

我测试的时候,直接 make JobConsumer 消费完消息后 Process 会重启,通过创建匿名类就是正常的

8fab06b

@huangdijia huangdijia marked this pull request as ready for review October 12, 2024 04:38
@huangdijia huangdijia merged commit ca415e9 into main Oct 12, 2024
15 checks passed
@huangdijia huangdijia deleted the support-auto-register-consumer branch October 12, 2024 04:38
@huangdijia huangdijia mentioned this pull request Oct 12, 2024
@huangdijia
Copy link
Contributor Author

我测试的时候,直接 make JobConsumer 消费完消息后 Process 会重启,通过创建匿名类就是正常的

8fab06b

我测试没有遇到这个问题哦,你安装 dev-main 试试看

composer r friendsofhyperf/amqp-job:dev-main

@anhao
Copy link

anhao commented Oct 12, 2024

我测试的时候,直接 make JobConsumer 消费完消息后 Process 会重启,通过创建匿名类就是正常的

8fab06b

我测试没有遇到这个问题哦,你安装 dev-main 试试看

composer r friendsofhyperf/amqp-job:dev-main

image

消费完还是会 stop ,然后再 start

@huangdijia
Copy link
Contributor Author

huangdijia commented Oct 12, 2024

QQ_1728712628298

<?php

declare(strict_types=1);

namespace App\Job;

use FriendsOfHyperf\AmqpJob\Annotation\AmqpJob;
use FriendsOfHyperf\AmqpJob\Job;
use Hyperf\Contract\StdoutLoggerInterface;

#[AmqpJob(
    exchange: 'hyperf',
    routingKey: 'hyperf',
    queue: 'hyperf',
    consumerProcessNums: 3,
)]
class FooJob extends Job
{
    public function __construct()
    {
        $this->setJobId(uniqid());
    }

    public function handle()
    {
        di(StdoutLoggerInterface::class)->info('FooJob#' . $this->getJobId());
    }
}

并未出现重启的情况

@anhao
Copy link

anhao commented Oct 12, 2024

Hyperf 版本是多少呢,我的,这是个最新的:

PHP 8.2.16 (cli) (built: Mar  8 2024 06:31:15) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.16, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.16, Copyright (c), by Zend Technologies
friendsofhyperf/amqp-job           dev-main c5a146b The amqp job for Hyperf.
friendsofhyperf/support            3.1.41           Another support component for Hyperf.
hyperf/amqp                        3.1.42           A amqplib for hyperf.
hyperf/cache                       3.1.43           A cache component for hyperf.
hyperf/code-parser                 3.1.42           A code parser component for Hyperf.
hyperf/codec                       3.1.42           A codec component for Hyperf.
hyperf/collection                  3.1.42           Hyperf Collection package which come from illuminate/collections
hyperf/command                     3.1.42           Command for hyperf
hyperf/conditionable               3.1.42           Hyperf Macroable package which come from illuminate/conditionable
hyperf/config                      3.1.42           An independent component that provides configuration container.
hyperf/constants                   3.1.42           A constants component for hyperf.
hyperf/context                     3.1.42           A coroutine/application context library.
hyperf/contract                    3.1.42           The contracts of Hyperf.
hyperf/coordinator                 3.1.42           Hyperf Coordinator
hyperf/coroutine                   3.1.42           Hyperf Coroutine
hyperf/database                    3.1.43           A flexible database library.
hyperf/db-connection               3.1.43           A hyperf db connection handler for hyperf/database.
hyperf/devtool                     3.1.42           A Devtool for Hyperf.
hyperf/di                          3.1.42           A DI for Hyperf.
hyperf/dispatcher                  3.1.42           A HTTP Server for Hyperf.
hyperf/engine                      2.11.0           Coroutine engine provided by swoole.
hyperf/engine-contract             1.10.1           Contract for Coroutine Engine
hyperf/event                       3.1.42           an event manager that implements PSR-14.
hyperf/exception-handler           3.1.42           Exception handler for hyperf
hyperf/framework                   3.1.42           A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.
hyperf/guzzle                      3.1.42           Swoole coroutine handler for guzzle
hyperf/http-message                3.1.42           microservice framework base on swoole
hyperf/http-server                 3.1.42           A HTTP Server for Hyperf.
hyperf/logger                      3.1.42           A logger component for hyperf.
hyperf/macroable                   3.1.42           Hyperf Macroable package which come from illuminate/macroable
hyperf/memory                      3.1.42           An independent component that use to operate and manage memory.
hyperf/model-listener              3.1.42           A model listener for Hyperf.
hyperf/pipeline                    3.1.42           Hyperf Macroable package which come from illuminate/pipeline
hyperf/pool                        3.1.42           An independent universal connection pool component.
hyperf/process                     3.1.42           A process component for hyperf.
hyperf/redis                       3.1.42           A redis component for hyperf.
hyperf/serializer                  3.1.42           A serializer component for Hyperf.
hyperf/server                      3.1.42           A base server library for Hyperf.
hyperf/stdlib                      3.1.42           A stdlib component for Hyperf.
hyperf/stringable                  3.1.43           Hyperf Stringable package which come from illuminate/support
hyperf/support                     3.1.42           A support component for Hyperf.
hyperf/tappable                    3.1.42           Hyperf Macroable package which come from illuminate/tappable
hyperf/testing                     3.1.42           Testing for hyperf
hyperf/utils                       3.1.42           A tools package that could help developer solved the problem quickly.

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 5.1.0
Built => Jun 12 2024 09:22:54
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 3.0.2 15 Mar 2022
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_fiber_mock => Off => Off
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

@huangdijia
Copy link
Contributor Author

我的也是最新版呢

@anhao
Copy link

anhao commented Oct 12, 2024

我的也是最新版呢

我重新创建了一个新项目也是这样,会自动重启

@huangdijia
Copy link
Contributor Author

看看你的 Job 是怎么写的?

@anhao
Copy link

anhao commented Oct 12, 2024

看看你的 Job 是怎么写的?

和你上面发的是一样的

@huangdijia
Copy link
Contributor Author

那就太奇怪了,你再分析看看,确定是 bug 再提个 PR

@anhao
Copy link

anhao commented Oct 12, 2024

我不同的环境都试了,都是用最新版本hyperf,都会出现重启,

通过这种方式创建就是正常的

private function createConsumerMessage(AmqpJobAnnotation $amqpJob): JobConsumer
    {
        return new class($this->container, $amqpJob) extends JobConsumer {
            public function __construct(ContainerInterface $container, AmqpJobAnnotation $amqpJob)
            {
                $this->routingKey = $amqpJob->routingKey;
                $this->container = $container;
                $this->nums = $amqpJob->nums;
                $this->enable = $amqpJob->enable;
                $this->exchange = $amqpJob->exchange;
                $this->poolName = $amqpJob->pool;
                $this->queue = $amqpJob->routingKey;
            }
        };
    }

@huangdijia
Copy link
Contributor Author

@anhao
Copy link

anhao commented Oct 13, 2024

https://github.com/friendsofhyperf/components/blob/main/src/amqp-job/src/JobConsumerManager.php#L33-L34

同样都是匿名类

所以挺奇怪的,没有找到原因

@huangdijia
Copy link
Contributor Author

我后面再试试看

@huangdijia
Copy link
Contributor Author

我也用一个全新的项目测试了,也没有复现重启问题

QQ_1728867674202

@anhao
Copy link

anhao commented Oct 14, 2024

那不清楚了,我这边通过构造函数初始化那些参数就不会重启,amqp 我试过自建和阿里云的, amqp 日志提示是客户端断掉了连接

@huangdijia
Copy link
Contributor Author

那不清楚了,我这边通过构造函数初始化那些参数就不会重启,amqp 我试过自建和阿里云的, amqp 日志提示是客户端断掉了连接

可否提供 amqp 自建脚本?

@anhao
Copy link

anhao commented Oct 14, 2024

那不清楚了,我这边通过构造函数初始化那些参数就不会重启,amqp 我试过自建和阿里云的, amqp 日志提示是客户端断掉了连接

可否提供 amqp 自建脚本?

通过 Docker 构建的 ,https://hub.docker.com/r/bitnami/rabbitmq 最新版本

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