This channel is available for all Akka enthusiasts—newbies as well as gurus—for the exchange of knowledge and the coordination of efforts around Akka. For more info see: http://bit.ly/akka-gitter
I've written code that uses Akka.io to make TCP connections. This code has been running in production for three years or so, and has been performing well. Suddenly, with just a few days notice, I'm told that I need to use TCP with TLS (with no SSL certificate required). I'd like to make a small change to the existing code, but I don't see any documentation about how to do TLS with akka.io. Instead I see suggestions about switching to Streams.
I'd much prefer making a small change in existing code to re-implementing in Streams. Is there any way I can modify my existing akka.io TCP code to make a TLS connection? Perhaps by copying code from Akka 2 2.x, which did support TCP with TLS in akka.io? My production code is using Akka version 2.5.32.
Path.Slash(Path.Segment(seg1, Path.Slash(Path.Segment(seg2, ....))))
works but...
Hello akka-community,
what is the reason that the WebsocketClientBlueprint.handshake
-BidiFlow drops the entity of the websocket handshake GET
-Request in the following lines?
case ResponseStart(status, protocol, attributes, headers, entity, close) =>
val response = new HttpResponse(status, headers, attributes, HttpEntity.Empty, protocol)
Is there a way the access this entity?
:point_up: Edit: Hello akka-community,
what is the reason that the WebsocketClientBlueprint.handshake
-BidiFlow drops the entity of the websocket handshake GET
-Response in the following lines?
case ResponseStart(status, protocol, attributes, headers, entity, close) =>
val response = new HttpResponse(status, headers, attributes, HttpEntity.Empty, protocol)
Is there a way the access this entity?
In the context of akka/akka-stream-contrib#93
If I do not know the initial page token, how to use PagedSource
(or any other source operator)? (I like PagedSource
, it is clean approach :) )
For example, our 3rd party REST API provides a token after first invocation, with which we need to use to iterate it until the token is null
/ None
. I could not come up with any nice solution apart from the following (and Option[Option[T]]
), do you have any suggestions?
I feel this is common use case, do you have already something in the library for this use case?
case class Page[T, K](items: immutable.Iterable[T], nextKey: Option[K])
final class PagedSourceStageAsync[T, K](initial: Option[K], f: Option[K] => Future[Page[T, K]])
extends GraphStage[SourceShape[T]] {
import scala.concurrent.ExecutionContext.Implicits.global
val outlet: Outlet[T] = Outlet("PagedSourceStageAsync.out")
override def createLogic(inheritedAttributes: Attributes): GraphStageLogic =
new GraphStageLogic(shape) with OutHandler {
private[this] var state: Option[K] = initial
private[this] var asyncHandler: Try[Page[T, K]] => Unit = _
override def preStart(): Unit = {
val ac = getAsyncCallback[Try[Page[T, K]]] {
case Failure(ex) => fail(outlet, ex)
case Success(Page(items, None)) =>
push(outlet, items)
complete(outlet)
case Success(Page(items, Some(nextKey))) =>
push(outlet, items)
state = Some(nextKey)
}
asyncHandler = ac.invoke
}
def onPull(): Unit = f(state).onComplete(asyncHandler)
setHandler(outlet, this)
}
override def shape: SourceShape[T] = SourceShape(outlet)
}
I have a question about reading entities in with akka-http. I am creating a REST API and have a data model that includes 2 parent models that can have several children models that link them together. For example:
case class ParentA(id: String)
case class ParentB(id: String)
case class Child(idA: String, idB: String, ...other fields)
The "other fields" all have default values, so I would like to create an endpoint that allows creating multiple of these children entities providing only the non-default parent B ID with the paretn A ID coming from the URL path, for example:
POST https://so-cool-api.com/parentA/<parentA_id>
BODY:
{
"parentBIds": ["idB1", "idB2", ...]
}
This would then create several Child
instances for each parentBId
provided, all with idA = <parentA_id>
.
However, I would also like to allow default values to be overriden:
POST https://so-cool-api.com/parentA/<parentA_id>
BODY:
{
"children": [
{ "idB": "idB1", ...other fields },
{ "idB": "idB2", ...other fields }
]
}
Is this possible without doing custom JSON handling in the endpoint and relying solely on implicit marshalling? Is this even a good idea? I believe the form of the body in the first example will be used most and is therefore convenient to allow, but maybe it's better to only allow the second type of request, and just omit fields that I want to rely on default values for?
Thanks for any advice!
I am attempting to keep websocket connection open in combination with a webSocketClientFlow
, and am having a fair bit of difficulty.
My top-level flow looks something like this (pseudocode). Imagine for certain messages, I want to proxy them somewhere else, other message types I simply want to return a default message to the client:
Flow[Message].flatMapConcat({
case msg: T => proxy(msg)
case msg: U => Source.single(TextMessage(""))
})
The proxy
function is something like the following, I'm attempting to keep the connection open with how this is described in the docs:
Source.single(msg).concatMat(Source.maybe)(Keep.right).via(out)
Where the connected Flow is simply something like:
val out = Http().webSocketClientFlow(WebSocketRequest(uri)).mapAsync(1)(transformMessage)
I'm passing to an echo ws:// endpoint as a test, and while the first message gets echoed back to me, following messages do not get sent. So, curious what I'm missing here.
Hello, could anyone assist to compose these two Directives. One Directive depends on the value provided by the other one, and I'm trying to compose them into one directive:
def firstDirective(): Directive1[String] = {
...
}
def secondDirective(valueFromFirst: String): Directive0 = {
...
}
def composedFirstAndSecond = firstDirective().tmap(x => secondDirective(x))
This compiles, but when using the composedFirstAndSecond
directive, it fails to compile:
type mismatch;
[error] found : akka.http.scaladsl.server.StandardRoute
[error] required: akka.http.scaladsl.server.Directive[Unit] => (akka.http.scaladsl.server.RequestContext => scala.concurrent.Future[akka.http.scaladsl.server.RouteResult])
Hey there,
im building a local cluster which uses one jvm and I need to send a message from one actor to another on a different node as soon as all nodes are up. Im listening to the up events and would like to send the message as soon as ai recognize a specific node is up. However, I need an actorref to that actor and since I´m in a Behaviour of MemberEvent, I cannot use the ask pattern properly because I have to catch the reponse inside this behaviour.
I use a structure similiar to the cluster system described here: https://developer.lightbend.com/guides/akka-sample-cluster-scala/
Is it possible, to get the actorref by using the members adress of the node?
Or is it possible to implement it anyway with the ask pattern?
I would really appreciate your feedback
Hey there, I'm trying to read a query parameter in an REST Api I'm building with Akka-http and having trouble unmarshalling it to a domain object. This is my route definition:
override lazy val getManyRoute: Route = (pathEndOrSingleSlash & get & parameters("userId".as[UserId].?)) { maybeUserId =>
complete {
eventService.getEventsBy(maybeUserId)
}
}
Everything compiles fine, so I am assuming the necessary unmarshalling implicits are in scope. Using curl to test the endpoint, I get the following error:
➜ ~ curl "localhost:8080/events?userId=6be0f45e-084e-41db-9e5b-e6bc8d208b54"
The query parameter 'userId' was malformed:
expected whitespace or eof got 'be0f45...' (line 1, column 2)%
It seems like it's reading just the first character ('6') from the UUID, and for some reason is not including the rest of the string in the parameter. However, if I change the Route definition to read a String and manually "unmarshall" it, it works fine. Something like the following:
override lazy val getManyRoute: Route = (pathEndOrSingleSlash & get & parameters("userId".?)) { maybeUserId =>
// ^ no more unmarshalling
complete {
eventService.getEventsBy(maybeUserId.map(methodToUnmarshallStringToUserId))
}
}
Any ideas? Is there something I'm missing in the original route definition?
Request : HttpRequest(HttpMethod(GET),http://localhost:8080/events/?userId=6be0f45e-084e-41db-9e5b-e6bc8d208b54&,List(Timeout-Access: <function1>, Host, User-Agent: curl/7.64.1, Accept: */*),HttpEntity.Strict(none/none,0 bytes total),HttpProtocol(HTTP/1.1))
Response: Rejected(List(MalformedQueryParamRejection(userId,expected whitespace or eof got 'be0f45...' (line 1, column 2),None), TransformationRejection(akka.http.scaladsl.server.directives.BasicDirectives$$Lambda$1058/0x0000000800799840@412742fd), MethodRejection(HttpMethod(POST))))