我正在尝试建立一个API,该API使用另一台服务器上的队列系统来处理请求。让我开始尝试在没有队列系统的情况下要完成的工作(无权使其保持简单):例如,使用Postman对URL https://example.com/products进行GET请求,将返回JSON字符串,例如
[
{
"id": 1,
"name": "some name",
...
},
{
"id": 2,
"name": "some other name",
...
}.
...
]
Run Code Online (Sandbox Code Playgroud)
route / api.php中的代码将类似于:
<php
Route::get('/products', ProductController@index');
Run Code Online (Sandbox Code Playgroud)
以及app / Http / Controllers / ProductController.php中的代码:
<?php
namespace App\Http\Controllers;
class ProductController extends Controller
{
/**
* Return the products.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
// Logic to get the products.
return $products->toJson();
}
}
Run Code Online (Sandbox Code Playgroud)
我要完成的工作是,所有业务逻辑都在另一台运行多个工作程序的服务器上进行处理。以下是我对此的推理。
这就是我所看到的工作流程:
所有的免费工人都在不停地轮询队列中的工作
下面是一幅小图,用于清除一切。
User …Run Code Online (Sandbox Code Playgroud)