Java: best practice to update data online when internet can be interrupted

SlimenTN :


I have 2 applications:

  • desktop (java)
  • web (symfony)

I have some data in the desktop app that must be consistent with the data in the web app.
So basically I send a POST request from the desktop app to the web app to update online data.

But the problem is that the internet cannot always be available when I send my request and in the same time I can't prevent the user from updating the desktop data
So far, this is what I have in mind to make sure to synchronize data when the internet is available.

enter image description here Am I on the right direction or not ?
If not, I hope you guys put me in the right path to achieve my goal in a professional way.
Any link about this kind of topics will be appreciated.

zappee :

This is a typical scenario when you want to send a message to an un-transactional external system in a transaction and you need to garantee that data will be transfered to the external system as soon as possible without losing it.

2 solutions come up in my mind, maybe the second fits better to your architecture.

Use case 1)

You can use message queue + redelivery limit setting with dead letter pattern. In t that case you need to have an application server.

Here you can read details about the Dead letter pattern.

This document explain how redelivery limit works on Weblogic server.

Use case 2)

You can create an interface table in the database of the destop application. Then insert your original data into database and insert a new record into the interface table as well (all in same transaction). The data what you want to POST needs to be inserted into the interface table as well. The status flag of the new record in the interface table can be "ARRIVED". Then create an independent timer in your desktop app which search periodically for records in the interface table with status "ARRIVED". This timer controlled process will try to POST data to webservice. If the HTTP response is 200 then update the status of the record to "SENT".

Boot can work like a charm.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=71372&siteId=1