Skip to content

Instantly share code, notes, and snippets.

View johanandren's full-sized avatar
👻
hakking

Johan Andrén johanandren

👻
hakking
View GitHub Profile
@johanandren
johanandren / SimpleClient.scala
Created December 3, 2015 07:39
Minimal example showing request api and unmarshalling response body to a string
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling._
import akka.stream.ActorMaterializer
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
object SimpleClient {
@johanandren
johanandren / Intersperse.scala
Created December 3, 2015 15:46
Naive intersperse implementation
import akka.stream.FlowShape
import akka.stream.scaladsl.FlowGraph
import akka.stream.scaladsl.{Source, Concat, Flow}
import akka.stream.stage.{SyncDirective, Context, PushPullStage}
object Intersperse {
def apply[E](separator: E): Flow[E, E, Unit] =
Flow[E].transform(() => new Intersperse[E](separator))
@johanandren
johanandren / ActorMaterializerSettingsApp.scala
Created May 20, 2016 14:55
Does the stages inherit the materializer strategy?
package streams
import akka.actor.ActorSystem
import akka.stream.ActorAttributes.SupervisionStrategy
import akka.stream.Supervision.Resume
import akka.stream._
import akka.stream.scaladsl.Source
import akka.stream.stage.{GraphStage, GraphStageLogic}
object ActorMaterializerSettingsApp extends App {
@johanandren
johanandren / GracefulLeaveCluster.scala
Created June 7, 2016 09:41
Simple self-contained two-node-cluster app
import akka.actor._
import akka.cluster.{Cluster, MemberStatus}
import com.typesafe.config.ConfigFactory
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.io.StdIn
object GracefulLeaveCluster extends App {
@johanandren
johanandren / SimplePartitionSample.scala
Created July 26, 2016 08:25
Sample of using partition to split up incoming elements over multiple outgoing streams
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
import scala.io.StdIn
import scala.util.Random
object SimplePartitionSample extends App {
implicit val system = ActorSystem()
@johanandren
johanandren / UdpRemoting
Created August 3, 2016 12:25
Non-working minimal udp remoting sample
package remoting
import akka.actor.{Actor, ActorLogging, ActorSystem, Props}
import com.typesafe.config.ConfigFactory
import scala.io.StdIn
/**
* Created by johan on 2016-08-03.
*/
import akka.actor.{Actor, ActorSystem, Props}
import akka.http.scaladsl.Http
import akka.http.scaladsl.marshalling._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import http.ActorPerRequest.RequestHandler.Handle
import scala.io.StdIn
import akka.actor.{Actor, ActorSystem, Props}
import akka.cluster.Cluster
import akka.cluster.ClusterEvent.{MemberEvent, ReachabilityEvent}
import com.typesafe.config.ConfigFactory
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.io.StdIn
object WeaklyUp extends App {
@johanandren
johanandren / LogsToAmqpSample.java
Last active November 4, 2016 11:58
Sample of streaming log entries from a local logfile to an AMQP broker
package streams;
import akka.actor.ActorSystem;
import akka.stream.ActorMaterializer;
import akka.stream.Materializer;
import akka.stream.contrib.FileTailSource;
import akka.stream.contrib.amqp.*;
import akka.stream.javadsl.Framing;
import akka.util.ByteString;
import scala.concurrent.duration.FiniteDuration;
@johanandren
johanandren / RandomNumberSource.java
Created August 18, 2016 12:50
Sample of a source emitting random integers
package streams;
import akka.stream.Attributes;
import akka.stream.Outlet;
import akka.stream.SourceShape;
import akka.stream.stage.AbstractOutHandler;
import akka.stream.stage.GraphStage;
import akka.stream.stage.GraphStageLogic;
import akka.stream.stage.OutHandler;