How could Zuul be used to aggregate results of two endpoints? i.e.
Suppose /api/notes request being made.
Zuul is suuposed to invoke /notes/from/source/1 and/notes/from/source/2 endpoints
Aggregate results receied fom both the endpoints
Send aggregated results to client who initiated the results
Can this be done easily with Zuul? If not, I don't see any other facility that Zuul provides other than providing a filter chain.
It can't be done automatically. You need to write a zuul filter to do this.
Related
I am trying to use the Google Cloud monitoring REST APIs to get timeseries data of my project. I have been looking at the documentation here: https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/list
I do not see any API where I can query for multiple timeseries (with different filters each) using one single REST call. Is that possible with the available APIs ?
For example, for a given timerange, I might want to get the kubernetes/cpu/usage metric with certain filters and the kubernetes/memory/usage metric with a different set of filters in one single REST API call.
I really like the way Spring cloud function decouples the business logic from the runtime target (local or cloud) and makes it easy to integrate with serverless providers.
I plan to use SCF with AWS Lambda behind an API gateway to design the backend of a system.
However, I am not completely clear on what is the recommended way to handle REST related parameters such as Query params, headers, path etc. inside the Spring cloud functions.
As per our initial analysis, we could derive two possible approaches:
When enabling “Lambda proxy integration” in API Gateway, Query params and other information are available as Message headers inside the SCF.
We can use “Mapping templates” in API Gateway to map all the required information into a JSON body and deserialize as a POJO to take input directly into the SCF.
This way, the SCF does not need to bother about how the required data is passed to the API.
What is the recommended way to achieve this? Are we missing something that enables to do this in a better way?
I don't think you are missing anything featurewise, except perhaps that it might also be convenient to work with composite functions - e.g. marshal|transform, where marshal is a Function<Message<?>, ?> and transform is the business logic. The marshal function could be generic (and convert to some sort of canonical form), and be provided as an autoconfiguration in a shared library (for instance).
I'm looking for design pattern/library to combine multiple different endpoint to be visible as one.
Let's say I have 3 endpoints, each of them returns the same type of objects, of course objects are different and have unique id. I want to create an endpoint which calls all of them, combine results, filter & sort & page, then return results.
There can be many objects, so it could be good to have caching, to call those three endpoints only when something has changed (let's say I somehow know if I need to refresh cache).
I imagine there's a library which can connect multiple endpoint into one, cache results and deliver filter & sort & page. Some sort of, let's say, Spring repository: however data are not read from database, but from cache, which gathers them from REST endpoints.
I was looking at Gateway design pattern like Spring Gateway or Zuul Proxy, but it seems to be only a wrapper, no possibility process data.
Of course I can do such things manually:
create controller
call three endpoints (if needed to refresh)
fill cache
read data from cache sort, filter, page, and return them
but if I need to do that multiple times, I'm looking for library to do that.
You can implement the GatewayFilterFactory with aggregation and caching in Spring Cloud Gateway. But it looks like the creation of a controller.
I have a url path that looks like this:
/{identifier}/rest/of/resource/path
If the identifier is A then the request should go to service_I. If the identifier is B then the request should also go to service_I. If the identifier is C, then the request should go to service_II, and so on.
Later on a new identifiers M and N is added to the system and their requests should be routed to service_IV.
Is it possible to dynamically configure a Spring cloud zuul proxy to perform the tasks described above?
Edit
This question offered contains a different way to examine the question.
In it Zuul has the following configuration:
zuul:
routes:
<service_id>:
path: /path/**
Zuul will collaborate with Eureka to find the service-id and return the host parameters so that the service can be accessed. What if instead of /path we have /{userID} and the userID instances are distributed across several service_id hosts?
Can Zuul / the DiscoveryClient query Eureka for both the service_id and the userID to figure out which host is hosting the particular userID?
You would need to write a custom ZuulFilter to accomplish this. Take a look at the PreDecorationFilter for some hints as this is the filter responsible for handling /path where the path is a service-id (among other things).
I am working on a REST service and so far all the queries are retrieved using a GET request.
Right now we are using a sort of routing rule like this one:
API/Person/{id} GET
http://api.com/person/1
Now, what if I want to ask to the REST API "Give me a Person with FisrtName = 'Pippo'"
I have a complex DTO that I called PersonQueryDTO that can be sent to the REST method to interview the database using the query criterias.
Is this a good way to do it or should I build complex queries in a different way?
For me it's important to keep the REST principles.
If you want to stick with REST principles, then the way to do something like that is to supply additional parameters in the URL e.g.
GET API/Person?FirstName=SomeName
REST is all about identifying resources, API/Person identifies your collection of Person and the additional parameters are nothing but meta data which the service can use internally to determine what sort of result to return.