Skip to content

Instantly share code, notes, and snippets.

👻
hakking

Johan Andrén johanandren

👻
hakking
Block or report user

Report or block johanandren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@johanandren
johanandren / ProgrammaticJoin.scala
Created Oct 4, 2018
Three node Akka cluster in one JVM with minimal fuzz
View ProgrammaticJoin.scala
import akka.actor.ActorSystem
import akka.cluster.Cluster
import com.typesafe.config.ConfigFactory
object ProgrammaticJoin extends App {
val commonConfig = ConfigFactory.parseString(
"""
akka {
actor.provider = cluster
remote.artery.enabled = true
View PartitionOnType.scala
import akka.NotUsed
import akka.actor.ActorSystem
import akka.stream.scaladsl.{GraphDSL, Partition, Sink, Source}
import akka.stream.{ActorMaterializer, SinkShape}
import scala.reflect.ClassTag
object PartitionOnType extends App {
implicit val system = ActorSystem()
View MinimalWebSocketServer.java
import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.http.javadsl.ConnectHttp;
import akka.http.javadsl.Http;
import akka.http.javadsl.model.HttpRequest;
import akka.http.javadsl.model.HttpResponse;
import akka.http.javadsl.model.ws.Message;
import akka.http.javadsl.model.ws.TextMessage;
import akka.http.javadsl.server.Route;
import akka.stream.ActorMaterializer;
@johanandren
johanandren / MultipleUnmarshallers.scala
Created Oct 13, 2017
Combining multiple unmarshallers for different dataformats for one path
View MultipleUnmarshallers.scala
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.ContentTypes
import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller}
import akka.stream.ActorMaterializer
object MultipleUnmarshallers extends App {
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
@johanandren
johanandren / RateLimit.scala
Created Jul 14, 2017
Sample for a custom rate limiting directive for Akka HTTP
View RateLimit.scala
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package http
import java.util.concurrent.atomic.AtomicInteger
import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpResponse, StatusCodes, Uri}
View TypedAndUnionTypes.scala
import akka.typed.Behavior
import akka.typed.scaladsl.Actor._
sealed trait LifecycleCommand
object Stop extends LifecycleCommand
val lifecycleBehavior: Behavior[LifecycleCommand] =
immutable[LifecycleCommand]((ctx, msg) =>
msg match {
case Stop =>
View SerializerAndPathDependentTypes.scala
package basics
import akka.actor.{ActorSystem, ExtendedActorSystem}
import akka.serialization.{JavaSerializer, SerializationExtension}
import com.typesafe.config.ConfigFactory
trait MyPayload
trait OtherPayload
trait PersistentExecutorProtocol extends Serializable {
View StashFailApp.scala
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 Apr 28, 2017
Trying to reproduce a problem with FSM
View FSMTestActor.java
import akka.actor.*;
public class FSMTestActor extends AbstractFSM<String, String> {
public final static String A = "A";
static class Event {
public final int n;
View ClusterRouting.scala
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 = {
You can’t perform that action at this time.