Akka-HTTP-Akka-Streams-Akka-Actors-Integration | Streaming Chuck Norris jokes in JSON as Server
kandi X-RAY | Akka-HTTP-Akka-Streams-Akka-Actors-Integration Summary
kandi X-RAY | Akka-HTTP-Akka-Streams-Akka-Actors-Integration Summary
The JokeFetcher Akka Actor is used to continuously poll the ICNDB endpoint behind the scenes and publish each discrete JSON response onto the Event Stream as a JokeEvent. The JokePublisher Akka Actor is a point of integration between Akka Actors and Akka Streams. The JokePublisher is created whenever a request to the /streaming-jokes endpoint which in turn creates an Akka Stream to stream the response back to the requester. It lives for the duration of that Stream and gets terminated once the Stream completes (does not happen in this case because it is an infinite Stream) or when the Stream is cancelled (happens when the requester does not want anymore data). As you can see the JokePublisher is tied to the duration of each Stream. This means if 6 users come in and request data from /streaming-jokes then 6 actors of JokePublisher will be created, each of them will be responsible for publishing data into that specific user's streaming response. The JokePublisher on creation, will subscribe to the Akka EventStream and listen for JokeEvents and send them downstream to provide streaming responses. As you can see, publishing messages to the JokePublisher Actor will end up in the Akka Stream which is why this is a point of integration between Akka Actors and Akka Streams when it comes to publishing data into the Akka Stream. This actor respects backpressure. It will only send information as fast as the downstream consumer can consume. It will drop messages if they are coming in too quickly. Users can hit the /streaming-jokes route in order to get back an SSE streaming JSON response of Chuck Norris jokes in JSON format.
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-Streams-Akka-Actors-Integration
Akka-HTTP-Akka-Streams-Akka-Actors-Integration Key Features
Akka-HTTP-Akka-Streams-Akka-Actors-Integration Examples and Code Snippets
Community Discussions
Trending Discussions on Akka-HTTP-Akka-Streams-Akka-Actors-Integration
QUESTION
I tried: EventStream -> Source -> Akka HTTP (SSE)
As I see it, this cannot work, because the source will be materialized by Akka HTTP complete(Source, ...)
and to send messages from the EventStream to the materialized Source I need the ActorRef (is there a way to get that ActorRef?)
I've found a solution on GitHub which uses ActorPublisher: https://github.com/calvinlfer/Akka-HTTP-Akka-Streams-Akka-Actors-Integration
But since ActorPublisher is an internal API, I am still hoping for clean solution.
...ANSWER
Answered 2017-Nov-30 at 00:19You can use Source.actorRef
to create a Source
that converts event stream elements to ServerSentEvent
instances, and BroadcastHub.sink
, in a manner like the following:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Akka-HTTP-Akka-Streams-Akka-Actors-Integration
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