akka-stream

Scala read continuous http stream

天大地大妈咪最大 提交于 2021-02-19 04:27:05
问题 How can I connect to and read a continuous (chunked) http stream in scala? For example, if I have this simple service written in python/bottle: from gevent import monkey; monkey.patch_all() import gevent from bottle import route, run @route('/stream') def stream(): while True: yield 'blah\n' gevent.sleep(1) run(host='0.0.0.0', port=8100, server='gevent') I'm planning to use akka-stream to process the data, I just need a way to retrieve it. 回答1: This should work. Basically, you do a single

Dynamically merge Akka streams

一曲冷凌霜 提交于 2021-02-08 04:12:40
问题 I’m trying to use Akka streams to build a pub sub bus in the following way: Publisher adds a source stream for the topic and subscribers specify a topic and get everything for that topic. However topic may be published by multiple Publishers, and both publisher and subscribers can join at any point. What I had in mind is to combine all sources and then return the filtered source to a subscriber. However as publishers may join at any point sources may be added after a subscription has been

Dynamically merge Akka streams

喜你入骨 提交于 2021-02-08 04:11:51
问题 I’m trying to use Akka streams to build a pub sub bus in the following way: Publisher adds a source stream for the topic and subscribers specify a topic and get everything for that topic. However topic may be published by multiple Publishers, and both publisher and subscribers can join at any point. What I had in mind is to combine all sources and then return the filtered source to a subscriber. However as publishers may join at any point sources may be added after a subscription has been

How to get object that caused failure in Akka Streams?

回眸只為那壹抹淺笑 提交于 2021-02-08 02:12:39
问题 According to akka streams docs one can handle stream failure by defining a decider that maps a Throwable to a Strategy : val decider: Supervision.Decider = { case _: ArithmeticException => Supervision.Resume case _ => Supervision.Stop } I wonder if there is a way to also get access to the element that caused the error. Of course, the type of this element is unknown, but is there a way to get it even as an instance of Object ? 回答1: The trivial way would be to catch the ArithmeticException near

How to get object that caused failure in Akka Streams?

可紊 提交于 2021-02-08 02:12:22
问题 According to akka streams docs one can handle stream failure by defining a decider that maps a Throwable to a Strategy : val decider: Supervision.Decider = { case _: ArithmeticException => Supervision.Resume case _ => Supervision.Stop } I wonder if there is a way to also get access to the element that caused the error. Of course, the type of this element is unknown, but is there a way to get it even as an instance of Object ? 回答1: The trivial way would be to catch the ArithmeticException near

Akka Stream & Kamon-Prometheus not returning any metrics but loads an empty page

半腔热情 提交于 2021-02-07 21:39:09
问题 I tried to integrate kamon-prometheus with akka stream project but at http://localhost:9095/ it loads an empty page.In the console I could see the message that metrics information is available at http://localhost:9095/. When I tried with akka quickstart project, it worked fine. Is kamon supported for akka streams? 回答1: Kamon uses aspecj heavily to gather some of the metrics. Please make sure that java agent aspectj-weaver is added to the boot of you JVM. See different options in this

Akka Stream connect to multiple sinks

微笑、不失礼 提交于 2021-02-07 18:29:13
问题 I have implemented a custom component in akka stream which takes elements as input, groups and merges them based on a key and sends them out through one of a dozen outlets. You can think of this component as a kind of GroupBy component which does not partition the flow into subflows, but actual flows. In addition to partitioning incoming elements, it merges them into one element, i.e. there is some buffering happening inside the component such that 1 element in does not necessarily mean 1

Confusing scala syntax

只愿长相守 提交于 2021-01-28 02:10:42
问题 trying to understand some scala syntax, and where to find their spec. Bellow i am confused about statefulMapConcat. The signature is this one: def statefulMapConcat[T](f: () => Out => immutable.Iterable[T]): Repr[T] and we have "be able to restart" in { Source(List(2, 1, 3, 4, 1)) .statefulMapConcat(() => { var prev: Option[Int] = None x => { if (x % 3 == 0) throw ex prev match { case Some(e) => prev = Some(x) (1 to e).map(_ => x) case None => prev = Some(x) List.empty[Int] } } })

How do I compute an aggregation inside a GraphStage in Akka Streams?

女生的网名这么多〃 提交于 2021-01-07 01:42:37
问题 I have an operator/component in Akka stream that aims to compute a value within a window of 5 seconds. So, I created my operator/component using TimerGraphStageLogic which you can see on the code below. In order to test it I created 2 sources, one that increments and the other that decrements, then I merge them using the Merge shape, then I use my windowFlowShape , and finally emit them in a Sink shape. I ensure that the TimerGraphStageLogic is working because I tested it in another PoC. In

use a partition to decide if a flow should go to next flow and if not have the stream pick it up next tick from the beginning (Akka)

怎甘沉沦 提交于 2020-12-13 04:57:05
问题 I want to create a Flow that have 4 main steps (FlowShapes), and after the first and the second I want to have partition that will decide if there is a reason to go to the next, and if not to sink it so the stream will pick it up later and start from beginning, but im not sure this is the way, cause I just used Sink.ignore, it looks like this: def mainFlow: Flow[MyGraphElement, MyGraphElement, NotUsed] = Flow.fromGraph(GraphDSL.create() { implicit builder => // FlowShape's // those flow