简体   繁体   中英

Architecture of a Spring Boot Application with ElasticSearch Reactive Streams

I am new to Spring Boot. I am not sure how to architect my app using all these features:

0) External JSON restful api
1) Rest API
2) Reactive Streams
3) ElasticSearch
4) Microservices
5) MongoDB
6) Angular Front End

There is this resource I connect to to retrieve a JSON. Since it's external, I need to retrieve it, store it in my Mongo DB db and from time to times check if there is an update to the external resource JSON and retrieve the updated fields. I then need to pass this JSON to an ElasticSearch server which would return then responses based on some queries made. I want to be able to use reactive streams for this and microservices which include oAuth2, a restful API, a token API Service, a Service which creates a response and then finally in the front end an Angular or React page with a search bar to query the JSON data in the elasticSearch server... Any input or direction on how to structure this would be appreciated...


You must create your @RestController bean class and @Service bean class in order to receive the requests from the Angular front-end;

Once received the request, use a service (you inject it somewhere with @Autowired) to make the http call to the external source in order to get the JSON: this is a service to service call, so your backend service is the client of the request.

When you get the JSON, process it and save into MongoDB using another @Repository service. You must have configured mongo repository using a configuration file. Here you choose if to use Object Relational Mapping with mongo or using directly the Java Mongo Drivers with no more built-in layers.

Before saving the JSON into MongoDB you can check if the data has changed and based on this tringgering a call to the ElasticSearch web server like you've done for the previous call to get the JSON.

If the OAuth2 is on the external server, then when you have to call them, you must add a valid TOKEN. Probably the TOKEN comes from the first request by the Angular Front-End, because the microservices must be stateless. You pass the token in the header of the request.

To get the Token the first time, the Angular Front-End must implement the Oath2 client and there must be an Oauth2 server (the external service maybe?).

Investigate if you have to implement Backend side an Oauth2 client or server, because it depends on the chosen Oauth2 flow: there are many variants of them.

I hope it helps a little!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM