akka-http | The Streaming-first HTTP server/module of Akka | HTTP library
kandi X-RAY | akka-http Summary
kandi X-RAY | akka-http Summary
The Streaming-first HTTP server/module of Akka
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of akka-http
akka-http Key Features
akka-http Examples and Code Snippets
Community Discussions
Trending Discussions on akka-http
QUESTION
I am new to akka and still trying to understand the different akka and streaming concepts. For some new feature i need to add a http call to already existing stream which is working on an internal object. Something like this -
...ANSWER
Answered 2022-Mar-08 at 07:51I ended up using the approach mentioned in the question because i couldn't find anything better after looking around. Adding this step decreased the throughput of my application as expected, but there are approaches to increase that can be used. Check these awesome blogs by Colin Breck -
- https://blog.colinbreck.com/maximizing-throughput-for-akka-streams/
- https://blog.colinbreck.com/partitioning-akka-streams-to-maximize-throughput/
To summarize -
- Use Asynchronous Boundaries for flows which are blocking.
- Use Futures if possible and add callbacks to futures. There are several ways to do that.
- Use Buffers. There are several types of buffers available, choose what suits your needs.
Other than these, you can use inbuilt flows like -
- Use "Broadcast" to broadcast your events to multiple consumers.
- Use "Partition" to partition your stream into multiple streams based on some condition.
- Use "Balance" to partition your stream when there is no logical way to partition your events or they all could have different work loads.
You could use any one or multiple things from above options.
QUESTION
I just want to skip the cert verification (basically the same as curl --insecure).
versions
: scala 2.12, akka-http 10.2.4
I have tried these but neither worked:
- https://gist.github.com/iRevive/4a3c7cb96374da5da80d4538f3da17cb
- https://doc.akka.io/docs/akka-http/current/client-side/client-https-support.html#disabling-hostname-verification
Custom SSLContext
...ANSWER
Answered 2022-Feb-22 at 16:55I tried your "Custom SSLContext" reproducer. Besides timing out, it also produced the following stack track in the logging:
QUESTION
I want to extract a token either from the query parameter or the Authorization header.
For that, I created this directive:
...ANSWER
Answered 2022-Feb-02 at 09:23I believe it is because when parameter("token".optional) is rejected, it automatically returns a 401 Unauthorized response.
I believe it's the opposite. You made "token" parameter optional, that means when it's absent it still will be accepted and the directive after |
never evaluated. If you drop the .optional
and token
parameter is not there it will be rejected and directive after |
will be evaluated.
QUESTION
TLDR:
- Is committing produced message's offset as consumed (even if it wasn't) expected behavior for auto-commit enabled Kafka clients? (for the applications that consuming and producing the same topic)
Detailed explanation:
I have a simple scala application that has an Akka actor which consumes messages from a Kafka topic and produces the message to the same topic if any exception occurs during message processing.
...ANSWER
Answered 2022-Jan-31 at 17:58As far as Kafka is concerned, the message is consumed as soon as Alpakka Kafka reads it from Kafka.
This is before the actor inside of Alpakka Kafka has emitted it to a downstream consumer for application level processing.
Kafka auto-commit (enable.auto.commit = true
) will thus result in the offset being committed before the message has been sent to your actor.
The Kafka docs on offset management do (as of this writing) refer to enable.auto.commit
as having an at-least-once semantic, but as noted in my first paragraph, this is an at-least-once delivery semantic, not an at-least-once processing semantic. The latter is an application level concern, and accomplishing that requires delaying the offset commit until processing has completed.
The Alpakka Kafka docs have an involved discussion about at-least-once processing: in this case, at-least-once processing will likely entail introducing manual offset committing and replacing mapAsyncUnordered
with mapAsync
(since mapAsyncUnordered
in conjunction with manual offset committing means that your application can only guarantee that a message from Kafka gets processed at-least-zero times).
In Alpakka Kafka, a broad taxonomy of message processing guarantees:
- hard at-most-once:
Consumer.atMostOnceSource
- commit after every message before processing - soft at-most-once:
enable.auto.commit = true
- "soft" because the commits are actually batched for increased throughput, so this is really "at-most-once, except when it's at-least-once" - hard at-least-once: manual commit only after all processing has been verified to succeed
- soft at-least-once: manual commit after some processing has been completed (i.e. "at-least-once, except when it's at-most-once")
- exactly-once: not possible in general, but if your processing has the means to dedupe and thus make duplicates idempotent, you can have effectively-once
QUESTION
I am getting the following runtime error in my akka application (using both akka typed and classic)
...java.lang.UnsupportedOperationException: Unsupported access to ActorContext from the outside of Actor[akka://my-classic-actor-system/user/ChatServer#1583147696]. No message is currently processed by the actor, but ActorContext was called from Thread[my-classic-actor-system-akka.actor.default-dispatcher-5,5,run-main-group-0].
ANSWER
Answered 2022-Jan-14 at 22:15You are not allowed to use context
outside of an actor. And you do it in callback of your future.
QUESTION
Asking this question because I am trying to figure out the framework which is most widely used for integration testing akka-http. How to automate those tests in Jenkins? Probably a rookie question but ideas are appreciated. Thanks
EDIT from comments: What have you tried so far? So far I tried implementing 1. Jest 2. Using Testkit, IntegrationPatience Where are you stuck? Both the approaches doesn't look like standard to me and since I have app deployed in multiple locations, I am trying to understand if there is any framework out there which I can use to setup. The app is deployed to multiple data centers which may have different environment variables.
...ANSWER
Answered 2022-Jan-14 at 05:08There are a bunch of ways to test a microservice developed using akka-http:
- Unit testing
- Functional / Integration testing
- E2E testing
- Load testing
Unit testing using route-testkit (https://doc.akka.io/docs/akka-http/current/routing-dsl/testkit.html)
Functional testing & E2E testing using Akka HTTP client API (https://doc.akka.io/docs/akka-http/current/client-side/index.html) with API contracts you can validate the status codes and response body.
Load testing can be achieved using a bunch of tools, specifically in Scala you can take a look at Gatling.
QUESTION
I'm receiving an ajax POST request and need to process the body data as a ByteBuffer and respond with an Array[Byte] using Http4s (0.23.7). This is as far I have been able to put things together, although it's not working yet:
...ANSWER
Answered 2021-Dec-26 at 18:42The following code is written on top of my head and following the docs, since I can't test it right now.
(thus it may have some typos / errors; if you find one please feel free to edit the answer and thanks!)
QUESTION
I connected to my websocket service using this sample code client, but currently it just connects and then shutsdown.
How can I keep this connection open and never close it?
Once I make a connection, I want it to remain open until I shutdown the application.
...ANSWER
Answered 2021-Oct-19 at 10:28The Akka docs call out your situation:
The Akka HTTP WebSocket API does not support half-closed connections which means that if either stream completes the entire connection is closed (after a “Closing Handshake” has been exchanged or a timeout of 3 seconds has passed).
In your case, outgoing
(being a Source.single
) completes as soon as it has emitted the TextMessage
. The webSocketFlow
receives the completion message and then tears down the connection.
The solution is to delay when outgoing
completes, perhaps even delaying it forever (or at least until the application is killed).
Two standard sources are potentially useful for delaying completion in the scenario where you don't want to send messages through the websocket.
Source.maybe
materializes as aPromise
which you can complete with an optional terminating message. It will not complete unless and until the promise is completed.Source.never
never completes. You could achieve this by just not completingSource.maybe
, but this is less overhead than that.
So what would it look like in code?
QUESTION
I am trying to send couple of hundreds http requests from akka actor however I am getting
...ANSWER
Answered 2021-Oct-22 at 07:52Using context
asynchronously inside a Future
is a bad idea. context
it is only valid during calls to the actor.
The bug is that context.become(run(openRequests - 1))
uses the value of openRequests
at the time the Future
is created, not the value when it is called. So when the first request completes it will call context.become(run(-1))
(which is clearly bogus) even though there may be 15 outstanding requests.
The solution is to send a private message to yourself in the foreach
rather than calling context.become
directly. When the actor handles that message it decrements the current request count and sends a new request if necessary.
QUESTION
In akka-http, how do we extract a list of query parameters of varying length from incoming request?
Request url can be like this:
...ANSWER
Answered 2021-Oct-11 at 18:40Got it working as:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install akka-http
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page