1

I am working on a project that is making a REST call to another Service to save DATA on the DB. The Data is very important so we can't afford losing anything.

If there is a problem in the network this message will be lost, which can't happen. I already searched about Spring Retry and I saw that it is designed to handle temporary network glitches, which is not what I need.

I need a method to put the REST calls in some kind of Queue (Like Active MQ) and preserve the order (this is very important because I receive Save, Delete and Update REST calls.)

Any ideas? Thanks.

José Mendes
  • 950
  • 2
  • 14
  • 30
  • What is wrong with ActiveMQ? Why can't you use it? – StanislavL Aug 07 '17 at 14:33
  • We are exploring a way to use REST calls because of many internal reasons of the company, ActiveMQ can't be used in this project unless there is no other option. – José Mendes Aug 07 '17 at 14:35
  • using an external broker like activeMQ is the most efficient and secure way of doing this, you can scale and make it highly available without affecting other services. that's the beauty of it. once you recieve the confirmation of storing the message in the queue, you can be sure its there. but make sure its presistent on disk to avoid any loss – nafas Aug 07 '17 at 14:43

2 Answers2

0

If a standalone installation of ActiveMQ is not desirable, you can use an embedded in-memory broker. http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html

Not sure if you can configure the in-memory broker to use KahaDB. Of course the scope of persistence will be limited to your application process i.e. messages in the queue will not be available if the application is restarted . This is probably the most important reason why in-memory or vanilla code based approaches are no good.

If you must reinvent the wheel, then have a look at this topic, which talks about using Executors and BlockingQueue to implement your own pseudo-MQ. Producer/Consumer threads using a Queue.

On a side note, retry mechanism is not something provided by the MQ broker. It is the client that implements it. Be it ActiveMQs bundled client library or other Messaging libraries such as Camel.

You can also retrospect your current tech-stack to see if any of the existing components have JMS capabilities. For example: Oracle database bundles an MQ called Oracle AQ

Monish Sen
  • 1,773
  • 3
  • 20
  • 32
0

Have your service keep its own internal queue of jobs, and only move onto the next REST call until the previous one returns a success code.

There are many better ways to do this but the limitation will come down to what your company will let you do.

UserF40
  • 3,533
  • 2
  • 23
  • 34