Description
В данной статье рассматриваются способы отправки API запросов через RabbitMQ.
Для идентификации запросов посылается уникальный параметр request_id.
Queues
Во время работы с АPI в RabbitMQ используются две очереди:
- api_req - очередь для входящих запросов;
- api_resp - очередь, в которую попадают ответы на запросы (только если указан request_id)
Structure of the sent JSON message
Parameter | Type | Example | Required | Required | |
---|---|---|---|---|---|
request_id | string | "abcd1234" | Yes, if the response to to request is necessary | Request ID | |
request | string | api/v1.1/campaigns/triggers/import_and_start_batch | Yes | API request path | |
body | JSON object |
| Yes | API request body |
Structure of the received JSON message
Parameter | Type | Example | Required | |
---|---|---|---|---|
body | JSON object |
| Request ID | |
request_id | string | "abcd1234" | Идентификатор запроса |
How to send API requests in Go
You can send an API request using a script that calls RabbitMQ:
- Write and execute a script
- After executing the script, go to RabbitMQ → Queues
- Choose api_resp and get a response to the API request
How to send API requests via RabbitMQ Management Plugin
You can send an API request directly to RabbitMQ via api_req:
- Go to RabbitMQ → the Queues tab. Then select api_req and Publish message.
- After the request is sent, you can see its result in the same way as in the first method.