Api integration guidelines

Are there any recommendations, guidelines, or good articles on providing integration hooks?
Let's say I'm developing a network-based ordering system. In the end, I would like my client to be able to write some code, pack it in a jar, upload it to the classpath, and change the behavior of the software.
For example, if an order arrives, the code
1. can send email or sms
2. can write some additional data to the database
3. can change the data in the database or decide that the order should not be stored in the database (cancel saving data)

Point 3 is pretty dangerous because it interferes with data integrity too much, but if we want the integration to be so flexible, is this possible?

Options so far
1. provide hooks for specific actions, for example. if this happens already, call this method, the client will write an implementation for this method, this is too tough, although
2. A mechanism similar to servlet filters, there is code before the actual action is performed and after it the code is not quite sure how this could be developed, although

We use Struts2 if that matters.
This integration should be able to detect a โ€œstate changeโ€, and not just a โ€œfinal stateโ€ after the main action.
For example, if an order changes state from In Progress to Paid, then it will do something, but if it changes from Draft to Paid, it should not do anything.
The main action in this case will be loading the order object from the database, changing the state to Paid and saving it again (or performing an sql update).

+4
source share
1 answer

Many options, including:

  • Workflow tool
  • AOP
  • posts
  • DB layer intercepts

The simplest (for me at that time) was a message-based approach. I made a kind of declaration using Struts 2 hooks, but a cleaner approach would be to use Spring and / or JMS.

While the relevant information is contained in the message, it is almost completely closed. Availability of a system accessible through services / etc. means that messages can return to the main application in a way you did not expect.

If you want this to work without rebooting the system, another option would be to implement handlers in a dynamic language (e.g. Groovy). Functionality can be stored in the database. Using the Spring factory makes this pretty fun and reduces some of the complexity of a message-based approach.

One problem with the synchronous approach, however, is that the handler blocks or takes a lot of time; this may affect this stream at a minimum, or the system as a whole in some circumstances.

+2
source

Source: https://habr.com/ru/post/1384825/


All Articles