How to use RabbitMQ message as a "Rest Api" to find entities?

Viewed 1863

I'm having a problem to solve in an application. I'll show an example about it.

I have a rabbitmq queue on a system that is responsable to return Orders, called by another systems (the communication among these systems is only throught message). Until then, the only possible Order search was by the order code.

It works well. When I search by order code, I also filter by the order with contracts and deleted (logically). So, if the order has no contracts or it was deleted, the query doesn't return registers.

Now, one of that systems needs to find Orders without contracts and/or deleted.

Basically, I believe I need to build the same logic used in an API rest like this one, but using a queue message:

/api/orders?id=123455?deleted=true&hasContracts=true

Do that it's easy with message. I just need send a message with this format.

{
    "code": 123,
    "deleted": true,
    "hasContract": true
}

Mapping the values for Long and Boolean classes. If the information was null, this filter will be ignored by the query, except the code that's mandatory.

The doubt is: is this makes sense? I didn't find anything about this subject on the Internet. Create a queue for each case is not an option, because it will be hard for us to implement many queues.

1 Answers

It makes sense to me; using RPC with RabbitMQ is like RPC with HTTP/gRPC/..., so you have many options here:

  • if you need a great flexibility, you can
    • create your own query language (like in the example above)
    • use something like GraphQL
  • if your use cases are limited, you can choose to segregate the API endpoints with several routing keys (REST-over-AMQP).

Hope this helps.

Related