Giter Site home page Giter Site logo

CMQ多个队列支持 about laravel-queue-cmq HOT 6 CLOSED

freyo avatar freyo commented on May 27, 2024
CMQ多个队列支持

from laravel-queue-cmq.

Comments (6)

freyo avatar freyo commented on May 27, 2024 1

是支持多个队列的。

如果是 相同地域 和 账号,可以直接指定队列名称;

如果是 不同地域 或 账号,需要在 config/queue.php 里新增连接:

'connections' => [
	//...
	'your-connection-name' => [
		'driver' => 'cmq',
		'secret_key' => 'your-secret-key',
		'secret_id'  => 'your-secret-id',
		'queue' => 'your-queue-name',
		'options' => [
			'queue' => [
				'host'                 => 'https://cmq-queue-region.api.qcloud.com',
				'name'                 => 'your-queue-name',
				'polling_wait_seconds' => 0, // 0-30seconds
			],
			'topic' => [
				'enable' => false,
				'filter' => 'routing', //routing or msgtag
				'host'   => 'https://cmq-topic-region.api.qcloud.com',
				'name'   => '',
			],
		],
	];
	//...
];

分派 Job 时指定连接和队列

Job::dispatch()->onConnection('your-connection-name')->onQueue('queue-name-1');
Job::dispatch()->onConnection('your-connection-name')->onQueue('queue-name-2');

dispatch((new Job)->onConnection('your-connection-name')->onQueue('queue-name-1'));
dispatch((new Job)->onConnection('your-connection-name')->onQueue('queue-name-2'));

Job 内指定连接和队列

<?php

namespace App\Jobs;

class ProcessPodcast implements ShouldQueue
{
    /**
     * The name of the connection the job belongs to.
     */
    protected $connectionName = 'your-connection-name';

    /**
     * The name of the queue the job belongs to.
     *
     * @var string
     */
    protected $queue = 'your-queue-name';
}

处理指定的连接和队列


php artisan queue:work {connection-name} --queue={queue-name}

from laravel-queue-cmq.

freyo avatar freyo commented on May 27, 2024 1

.env 中的 CMQ_QUEUE 配置项只是 默认队列名称,实际使用中是可以通过 onQueue 方法或 $queue 属性动态指定的,默认连接名cmq

$payload 目前为 Laravel 默认的格式,按照此格式生成都是可以解析的,但跨语言可能比较麻烦

{
    "displayName":"App\\Jobs\\TestJob",
    "job":"Illuminate\\Queue\\CallQueuedHandler@call",
    "maxTries":null,
    "timeout":null,
    "data":{
        "commandName":"App\\Jobs\\TestJob",
        "command":"O:16:\"App\\Jobs\\TestJob\":4:{s:6:\"*job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:5:\"delay\";N;}"
    }
}

后续会支持自定义 payload

from laravel-queue-cmq.

327 avatar 327 commented on May 27, 2024

感谢您的回复,几个队列都在一个账号、同一地域下,唯有 queue name 不同
你说:“如果是 相同地域 和 账号,可以直接指定队列名称;”
能否给个示例?是在 env 文件中指定多个CMQ_QUEUE吗?

from laravel-queue-cmq.

327 avatar 327 commented on May 27, 2024

还是指:php artisan queue:work {connection-name} --queue={queue-name}
执行此命令时,指定不同 --queue 参数即可?

from laravel-queue-cmq.

327 avatar 327 commented on May 27, 2024

上面的问题已经解决,感谢您。
有个新问题,向 CMQ 写入消息的生产者,并不使用 laravel 框架,甚至是别的语言,如果继续用laravel 作为消费者,那消息的 payload 是不是要按照特定的格式生成?

from laravel-queue-cmq.

327 avatar 327 commented on May 27, 2024

感谢,后来琢磨出来了,laravel 会默认调用CallQueuedHandler 的 fire 函数,像上面如果指定了 call 函数,那CallQueuedHandler必须声明一个 call 函数

多谢指点,已经顺利运行

from laravel-queue-cmq.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.