Laravel是否有可能在没有"job"任务的情况下执行Job?有效载荷中的属性? [英] Is it possible for Laravel to execute a Job without the "job" property in the payload?

查看:125
本文介绍了Laravel是否有可能在没有"job"任务的情况下执行Job?有效载荷中的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用Laravel通过RabbitMQ队列驱动程序来消耗来自外部服务的作业.

I'm trying to use Laravel to consume jobs from an external service, using RabbitMQ queue driver.

每个作业有效负载基本上都是一个序列化的对象.

Each job payload is basically a serialized object.

但是,在我看来,Laravel要求job具有一个名为"job"的属性,该属性映射到完全限定的类名(FQCN).但是我不能这样做,因为这些作业是在甚至不了解我的Laravel应用程序的服务上创建的.

However, it seems to me that Laravel requires jobs to have a property called "job" that maps to a fully qualified class name (FQCN). But I can't do that since these jobs are created on a service which doesn't even know my Laravel app.

我是否可以在没有此属性的情况下消费和执行工作?

Is it possible for me to consume and execute a job without having this property?

示例:

Laravel是否有可能执行包含此有效负载的作业:

Is it possible for Laravel to execute a job containing this payload:

{
    "fooBar": "abc-123",
    "baz": false,
    "bazBar": 1
}

代替此:

{
    "job": "Acme\\\\Jobs\\\\FooJob",
    "data": {
        "fooBar": "abc-123",
        "baz": false,
        "bazBar": 1
    }
}

推荐答案

否,并非不重写Laravel作业分配器中的某些方法. Laravel的队列系统仅设计用于Laravel,因此进入队列的有效负载的结构就是它期望的格式.如果要使用其他框架使用排队的作业,则有很多选择.

No, not without overriding some of the methods within Laravel's job dispatcher. Laravel's queue system is designed only to be used with Laravel, so the structure of the payload into the queue is the format it expects. If you want to consume the queued job with another framework you have a number of options.

1)忽略作业有效负载中的FQCN.但是,您会把自己束缚在Laravel的工作负载结构上,并且如果这种情况发生变化,它可能会破坏您的应用程序.

1) Ignore the FQCN in the job payload. However, you'll be tying yourself to the structure of Laravel's job payload and it could break your app if this ever changes.

2)覆盖Laravel的工作分配器,以更改传递给队列的数据结构.这似乎比它值得的麻烦.

2) Override Laravel's job dispatcher to change the data structure it passes off to the queue. This seems like more hassle than it's worth.

3)编写您自己的作业调度程序,并使用您自己的类与队列系统进行交互.这样可以完全控制队列的使用方式.

3) Write your own job dispatcher and interact with the queue system with your own classes. This gives you complete control over how you use the queue.

这篇关于Laravel是否有可能在没有"job"任务的情况下执行Job?有效载荷中的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆