How to do multiple http request using akka HttpRequest? - akka-http

I am new in akka and I need to do a process that sends multiple API request, defined by a concrete TPS (Transactions per second).
I have read aboud Akka HttpRequest but I don't know how to launch multiple request in parallel.
Thank you everybody.

Related

Are REST streaming APIs implemented using HTTP Keep-Alive header packets?

If I were to send out a HTTP GET request to e.g. the Shodan REST streaming API, is this implemented on the server side by periodically sending out HTTP Keep-Alive messages to the client in case there is no new data to be sent out?
Or are there other options/techniques available for implementing REST streaming API endpoints?
There is no such thing as an http keepalive message.
The API you link to simply doesn't tell the client in advance how long the response body is, so a client can keep reading the newline-separated messages from what counts as one response until either side decides they're done.

Is using RPC with Masstransit best practice if you are trying to get a response from a queue

I thought using RPC is bad practice but all the resources I am finding point to using RPC in order to get a response from a queue after publishing a request. Are there any other ways of doing it? Is it the best practice?
Thanks
MassTransit has built-in support for producing requests (which can be published, or sent directly to a specific endpoint). The request client can be created manually or added to a dependency injection container, and one or more response types can be handled.
MassTransit uses the bus endpoint to receive responses by default.
To register the request client in the container, the AddRequestClient method is used as shown below.
services.AddMassTransit(x =>
{
// configure transport/host/etc.
x.AddRequestClient<CheckOrderStatus>();
});
RPC is a common pattern, and producing requests when a response is required, it a regularly used approach. Another option is combining a command with an event, and observing the event separate from the request producer. However, if a linear programmatic flow is required, using RPC via the request client is an easy solution.

correct pattern of Ktor's HttpClient usage

What's the correct pattern of usage for HttpClient in KTOR. Should I use it like singleton per app lifecycle, or should I create it per each request?
I would say that you may have more than one client per app if you need to connect to more than one logical services.
But if you are dealing with one single HTTP server it's better to have one client because it establishes and holds a connection with server. It also allocates the following resources: prepared threads, coroutines and connections. If you have multiple clients you can potentially run out of these resources.
Should I use it like singleton per app lifecycle, or should I create it per each request
Creation of a http client instance is usually a bit resource intensive, hence you should not create an instance of client for every request. You should create just one http client instance per app's lifecycle, injected wherever required in your app, ensuring that
you have used the right http client configurations like the thread pool size, timeouts etc
you are releasing the resources upon the app's shutdown.
The client can be configured with HttpClientEngineConfig(doc) or any of its inheritors. More details in the documentation here.
It is better to reuse the HttpClient instance for performance reasons if the requests can be performed using the same configuration/settings.
But in some cases you have to create separate instances because the features of a HttpClient are determined by the engine and the plugins specified when creating the instance.
For example when using bearer authentication the HttpClient instances can be reused only when sending requests to the same resource server (with the same authorization configuration).
Similarly, if two requests should use different timeouts then they can be performed only by different HttpClients.
To summarize, a HttpClient instance should be created per "feature set", determined by the required engine and plugins.

HTTP Request processing in ABAP system

I have a very basic question in how a external HTTP request is processed in an ABAP (S/4 system).
Are the requests handled by per process or per thread. (terms taken more from the java http world). ?
By threads will mean which already have the objects initialised in memory by the previous request.
By process will mean that the objects are initialised in memory every time which is obviously time consuming and non performant.
In case of a clustered system the request can be load balanced to a new systems which is a separate topic.
Best Regards,
Saurav
Internet Communication Manager (ICM) handle request and forward it to your class which is extend from IF_HTTP_EXTENSION interface by url (configure it in SICF).
SAP need authorization for accept http request. Web logon screen set cookie to client for tracking it. If you configure static user to your service on t-code SICF, you can add cookies to client (with http header in response) for tracking and checking it.
There is no cache for object in this interface, but you can create your own with static class attributes and other general function caching capabilities from ABAP. Please check below rest service api for sample project:
https://github.com/pacroy/abap-rest-api
Load balancers has cookie based route capabilities (session based) for finding correct system.

receive http requests in rabbitmq

API sends to my app message via http POST method.
To prevent data loss while my controller is off I want to use rabbit.
how to receive http POST requests in rabbitmq?
is possible at all?
No. There has to be some component which converts the requests. You also have to consider that the HTTP request requires a response. Do you respond with status 200/201 all the time, indicating "OK"/"Created"? What about errors you only discover later, when your controller is online again?
In your situation you might want to ask your users to send the data directly using RabbitMQ instead of using HTTP.