0

We have rabbitmq consumer where we get image urls from where we:

  1. download the image through this url.
  2. resize the image to our standard aspect ratio
  3. upload on our server at the path specified by the client.

The input to this consumer is:

{
  "imageUrl": "xyz.jpg", //url of the existing image
  "path": "/stock/123", //server path where we need to store this image,
  "team": "teamA" //team that sends this image.
}

The consumer first downloads the images, upload this to the server at given path. Post this, we need to store this image in our database to indicate its ready to be used i.e. in this case, we will save it in mysql through "teamA-stored-procedure".

We have teams from "teamA" to "teamZ" and every team has different database table where they dump the image information i.e. its host-url, its path etc.

We have put lots of if-elseif checks in the consumer i.e. if "module" is "teamA", we will hit "teamA-StoredProcedure"...similarly for teamB-teamZ.

To remove these checks, we can:

  1. Instead of calling respective team's stored procedure in the consumer, we can expose APIs for each team and the API URL can be passed as input to the consumer. Once, image download/resize/upload is done, it hits the respective team's API.
  2. Create a Topic based exchange and host separate consumer for each team. Each consumer would listen to respective team's messages only. This looks like a perfect use case for "topic based exchange" but there is the overhead of hosting multiple consumers instead of one.

Is it perfect use case for using "Topic based Exchange" OR using "Direct exchange" with single consumer and delegating rest to respective API is fine?

Sahil Sharma
  • 3,847
  • 6
  • 48
  • 98
  • How different are the params for each stored-procedure? if the params are the same and the only problem is if-elseif jungle, you could have a config/map file that maps the module name to the stored-procedure name. – Mark Shehata Aug 04 '17 at 19:13
  • there is significant difference..in parameters – Sahil Sharma Aug 04 '17 at 19:14
  • I would go with option 1, and instead of having APIs you could organize if-elseif jungle into a factory. This will make it simple and avoid overhead of managing/monitory many consumers & many API endpoints. So, in summary refactor the code and avoid adding extra resources. – Mark Shehata Aug 04 '17 at 19:23
  • yes, I understand we can do that. Then what is topic based exchange for? Since by factory or API approach, we can always do this segregation and take different steps based on input – Sahil Sharma Aug 04 '17 at 19:28
  • One benefit i see with using factory here is that in case of failure, these message would be pushed to dead letter queue, but in case of API, we will loose this benefit – Sahil Sharma Aug 04 '17 at 19:29

0 Answers0