Skip to content

Instantly share code, notes, and snippets.

View johanandren's full-sized avatar
👻
hakking

Johan Andrén johanandren

👻
hakking
View GitHub Profile
import akka.actor.{Actor, ActorSystem, Props, Stash}
class MyActor extends Actor with Stash {
def receive = {
case _ =>
unstashAll()
println("after unstashAll")
}
}
@johanandren
johanandren / FSMTestActor.java
Last active April 28, 2017 16:00
Trying to reproduce a problem with FSM
import akka.actor.*;
public class FSMTestActor extends AbstractFSM<String, String> {
public final static String A = "A";
static class Event {
public final int n;
import akka.actor.{Actor, ActorLogging, ActorRef, ActorSystem, Props}
import akka.cluster.{Cluster, MemberStatus}
import akka.routing.FromConfig
import com.typesafe.config.ConfigFactory
object ClusterRouting extends App {
class EchoActor extends Actor with ActorLogging {
log.info("Started")
def receive = {
@johanandren
johanandren / DistributedPubSubApp.java
Last active May 27, 2019 09:28
Simple sample of a two node cluster using distributed pubsub in Java
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.cluster.pubsub.DistributedPubSub;
import akka.cluster.pubsub.DistributedPubSubMediator;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import com.typesafe.config.Config;
package streams
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
import com.typesafe.config.ConfigFactory
object StreamDispatchers extends App {
implicit val system = ActorSystem("dispatchers", ConfigFactory.parseString(
import akka.actor.ActorSystem
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.ActorMaterializer
import scala.concurrent.Await
// important - it needs to be this Seq and not the default one
import scala.collection.immutable.Seq
// this is just for the await, so not really needed
import scala.concurrent.duration._
@johanandren
johanandren / RequestId.scala
Created September 6, 2016 07:17
Example showing how to ensure a unique id for each request, and how to log that from the Akka HTTP server DSL
import java.util.UUID
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpRequest
import akka.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
import akka.stream.ActorMaterializer
import akka.http.scaladsl.server._
import scala.io.StdIn
@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;
@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;
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 {