Hi Brandon, I also had to handle a case where input messages come in different rate than output messages - a game where input comes from player keystrokes (which appear in random intervals), and output consists of strictly ticked frames (e.g. 20 per seconds).
Two simple ways of decoupling input rate from output rate are Flow.conflate and Flow.expand methods: http://doc.akka.io/docs/akka/current/scala/stream/stream-rate.html#Rate_transformation Conflate lets you handle input faster than output, and expand handles input slower than output. To handle input which may be either faster or slower than output, it's possible to use DetachedStage and Flow.transform. Here's an example from my game: https://github.com/bartekkalinka/caves/blob/master/src/main/scala/websockets/GameFlow.scala I can't find DetachedStage example in newest documentation, it could have been replaced with GraphStage. I based my implementation on version 1.0 docs: http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0/scala/stream-customize.html#Using_DetachedStage And my code still works in 2.4.2 Bartek Kalinka W dniu niedziela, 6 marca 2016 20:11:45 UTC+1 użytkownik Brandon Bradley napisał: > > Rafal, > > Thanks for your response. I'm using the example for webSocketClientFlow > shown here > <http://doc.akka.io/docs/akka/2.4.2/scala/http/client-side/websocket-support.html>. > > I believe your statements and example will help. I haven't really used > streams much yet. > > Brandon > > On Saturday, March 5, 2016 at 7:08:39 PM UTC-6, Rafał Krzewski wrote: >> >> Hi Brandon, >> >> I guess you are using the following method to respond WebSocket handshake: >> >> UpgradeToWebSocket.handleMessagesWith(handlerFlow: Graph >> <http://doc.akka.io/api/akka/2.4.2/akka/stream/Graph.html>[FlowShape >> <http://doc.akka.io/api/akka/2.4.2/akka/stream/FlowShape.html>[Message >> <http://doc.akka.io/api/akka/2.4.2/akka/http/javadsl/model/ws/Message.html> >> , Message >> <http://doc.akka.io/api/akka/2.4.2/akka/http/javadsl/model/ws/Message.html>], >> >> _]): HttpResponse >> <http://doc.akka.io/api/akka/2.4.2/akka/http/javadsl/model/HttpResponse.html> >> >> In this case, the flow is indeed one-to-one. For each incoming message >> only a single outgoing message is produced. However there other over >> variants that take a pair of streams: >> >> UpgradeToWebSocket.handleMessagesWith(inSink: Graph >> <http://doc.akka.io/api/akka/2.4.2/akka/stream/Graph.html>[SinkShape >> <http://doc.akka.io/api/akka/2.4.2/akka/stream/SinkShape.html>[Message >> <http://doc.akka.io/api/akka/2.4.2/akka/http/javadsl/model/ws/Message.html>], >> >> _], outSource: Graph >> <http://doc.akka.io/api/akka/2.4.2/akka/stream/Graph.html>[SourceShape >> <http://doc.akka.io/api/akka/2.4.2/akka/stream/SourceShape.html>[Message >> <http://doc.akka.io/api/akka/2.4.2/akka/http/javadsl/model/ws/Message.html>], >> >> _]): HttpResponse >> <http://doc.akka.io/api/akka/2.4.2/akka/http/javadsl/model/HttpResponse.html> >> >> This allows you to implement a many-to-one, one-to-many, unidirectional >> reader / writer or any arbitrary communication scheme you can think of. You >> could implement the logic in an Actor and then use a pair of ActorSubcriber >> + ActorPublisher helpers to complete the required plumbing. >> >> Here's an example of WebSocket usage in my toy project >> https://github.com/rkrzewski/akka-cluster-etcd/tree/master/examples/cluster-monitor/src/main/scala/pl/caltha/akka/cluster/monitor/frontend >> >> (here the input and output channels serve different purposes and are >> independent of one another) >> >> Cheers, >> Rafał >> >> W dniu sobota, 5 marca 2016 18:24:43 UTC+1 użytkownik Brandon Bradley >> napisał: >>> >>> Hello, >>> >>> I have a websockets connection that continuously sends messages after I >>> send a particular message. I've followed the websockets client example. >>> But, I only get one message back. I believe this is because streams are >>> one-to-one. Is there a way to process messages received after sending an >>> initial message with akka-http? Or is this the wrong tool for the job. >>> >>> Cheers! >>> Brandon Bradley >>> >> -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
