谁能帮我在 krakend 中设置 rabbitmq,当我尝试从队列中获取 kraken 中的消息并将其传递给客户端时,我遇到了一个大问题?
方案如下:
- 客户端-> API 网关(krakend)-> 队列(rabbitmq)-> 服务
回答时反之亦然:
- 服务 -> 队列 (rabbitmq) -> API 网关 (krakend) -> 客户端
例如,我们收到一个来自客户端的请求—— “从某个服务获取产品列表”,api 网关(krakend)接受它并将其发送到队列(rabbitmq),最后,监听的服务queue接收消息并发送产品列表以响应另一个queue,并且kraken应该将这些数据传输到客户端(这里我不知道kraken应该如何将数据传输到我们的客户端)。
链接到文档https://www.krakend.io/docs/backends/amqp/
我尝试通过两种方式实现这一点,但没有得到我需要的结果
第一种方式
- 我的生产者(在这里我得到带有 url 参数的请求帖子。Reply_to 参数是新队列的名称,我将在其中等待 krakend 的答案)在这里我将请求放在队列中。
{
"endpoint": "/api/v1.0/goodsList/{reply_to}/{mess_id}/{route}",
"method": "POST",
"headers_to_pass": ["Content-Type"],
"backend": [
{
"host": [
"amqp://guest:guest@rabbitMQ:5672/"
],
"sd": "static",
"encoding": "json",
"disable_host_sanitize": true,
"extra_config": {
"github.com/devopsfaith/krakend-amqp/produce": {
"name": "queue",
"exchange": "exchange",
"durable": true,
"delete": false,
"exclusive": false,
"no_wait": true,
"mandatory": true,
"immediate": false,
"reply_to_key":"Reply_to",
"msg_id_key":"Mess_id",
"routing_key":"Route"
}
}
}
]
},
- 我的消费者在这里我想为一个新队列提供一个名称和路由,以便创建它并开始监听(消费)并根据请求向客户端提供数据
{
"endpoint": "/api/v1.0/consumer/{queue_name}/{route}",
"method": "GET",
"backend": [
{
"host": [
"amqp://guest:guest@rabbitMQ:5672/"
],
"sd": "static",
"encoding": "json",
"disable_host_sanitize": true,
"extra_config": {
"github.com/devopsfaith/krakend-amqp/consume": {
"name": "Queue_name",
"exchange": "exchange2",
"durable": false,
"delete": false,
"exclusive": true,
"internal": false,
"no_wait": true,
"no_local": false,
"routing_key": "Route",
"prefetch_count": 10
}
}
}
]
}
第二种方式
{
"endpoint": "/api/v1.0/goodsList",
"method": "POST",
"output_encoding": "json",
"extra_config": {
"github.com/devopsfaith/krakend/proxy": {
"sequential": false
}
},
"backend": [
{
"host": [
"amqp://guest:guest@rabbitMQ:5672/"
],
"url_pattern": "/",
"encoding": "json",
"sd": "static",
"disable_host_sanitize": true,
"extra_config": {
"github.com/devopsfaith/krakend-amqp/consume": {
"name": "queue",
"exchange": "exchange",
"durable": true,
"delete": false,
"exclusive": false,
"no_wait": true,
"no_local": false,
"routing_key": [
"#"
],
"prefetch_count": 10
},
"github.com/devopsfaith/krakend-amqp/produce": {
"exchange": "exchange2",
"durable": true,
"delete": false,
"exclusive": false,
"no_wait": true,
"mandatory": true,
"immediate": false,
"name": "queue2"
}
}
}
]
}
使用 amqp(rabbitMQ) 在 krakend 中实现客户端和服务器之间交换的正确方法是什么?
谢谢您的帮助。