I have scenario wherein I want to have a customised rate limiting logic in spring cloud gateway which is based on request header received. Can anyone share a sample implementation how it can achieved.
Tried using the RequestRateLimiter but with that I can achieve rate limiting on API end point level but I want it to be customer level based on API request header. As per my understanding this filter that comes with enough features to implement this.
Related
I’m using Java Spring Boot and I have a hexagonal / ports and adaptors structure to my code.
Im trying to set up correlation IDs in my logging. My understanding is that my API gateway should generate a unique ID for each request then pass that in the API call. I need to then make sure all subsequent internal API calls also pass this correlation ID around and include it in all logging.
But since the port and adapters are split in the code, how can I pass this ID from the port side to the adaptor side without changing all the interim business logic to include this ID in all method calls?
Spring-cloud-starter-sleuth is available which supports this out of the box,just add this dependency and then you would have traceId-common across all services and gateway and spanId - unique correlation is per microservice. You can read more about it in topic distributed tracing.
Using Spring-boot-actuator API I need to count the number of API hits per clientID. How can I achieve this? Another challenge is my application is deployed on AWS and Azure. At any time I want to know the total API hit count across all environments.
There are multiple ways to do it. You have use tools like newrelic to capture that.
It uses java agent to bound to each API call.
Another option is you can use logging system to push logs and then accumulate and show using splunk, kibana. there you can create dashboard based on logs to check API hit.
You can implement your own approach, as an API interceptor/ControllerAdvice to send request hit in a separate async thread.But then you have to implement real time aggregration of these hits.
I would like to send one API request on the Google Compute Engine, instead of sending 100 requests, in order to reduce HTTP traffic.
Here is a description of how to do this when using plain HTTP calls. I am interested in achieving the same goal using Google's Java API client library
I am also aware of creating groups of instances using templates, but I didn't find a way to attach extra disks that are not read-only.
I must create a small IOT platform based on Spring Boot/Java 8.
Context: Devices send some various informations to the platform. I must save them and after consume them in an analysis algorithm.
Constraint: I want it all be async and the platform must be based on Java8/Spring technologies or must be easily integrated in a spring boot app.
What I imagine? I thought send devices' informations to Async Spring REST controller and save them async in Mongodb.
I have already the analysis algorithm based on Google Guava Event Bus.
To resume, I have datas from devices in Mongodb database and an algorithm based on Java POJO and the last part which is missing is transform datas from devices to Java POJO.
With which technologies can I do that? Spring Reactor? RxJava? Something else? And how can I put this in place?
I search something simple to put in place which can easily scale by instance duplication for example. For the moment, I thought that Spring Cloud technologies is a bit too big for my purpose.
You should have a look at Spring XD engine.
Spring XD Enables Different Sources (HTTP, FTP, MQTT, File etc), Transformers, Filters, Sinks (HTTP, FTP, MQTT, File etc).
Please check this post on a small IoT Project based on Spring XD and Twitter API.
I am using spring MVC. I want to make a email notification system. Its job will be notify user about any activity happend. like facebook, twitter does.
What are the best approach considering huge number of email notification. I was thinking to use #Async. but will it be a good approach for such kind of email notification services.
You can use Spring Email library
The Spring Framework provides a helpful utility library for sending
email that shields the user from the specifics of the underlying
mailing system and is responsible for low level resource handling on
behalf of the client.
Huge number of emails should not be a problem, because email is neither cached in memory nor is high cpu consuming activity. Even if you are sending few hundreds of emails concurrently it should not be a problem. But don't believe my words, simply try doing it and use a profiler to confirm the performance.
If you plan to send huge number of emails, good option is to use some external services for that. It will require to do some work integrating them into your application, but if you're using Spring it shouldn't be too hard.
For example, consider Amazon SES, it has Java SDK with support of asynchronious operations, free tier and a sandbox for testing.