Skip to content

Instantly share code, notes, and snippets.

View Danthar's full-sized avatar

Arjen Smits Danthar

  • The Netherlands
View GitHub Profile
@Danthar
Danthar / gist:b64bd263fa27ca962f06
Last active August 29, 2015 14:03
Merge data from a list of ajax requests using jQuery deferred
var dataArguments = ['args1','arg2','arg3','arg4'];
var bucket =[];
$.when.apply($,$.map(dataArguments, function(arg){
//here you setup and return an ajax request
//for example
var ajaxData = {term:arg, somethingelse:0};
return $.ajax({
@Danthar
Danthar / gist:5f7e27956707de633431
Created March 24, 2015 14:13
Consume RabbitMq messages with Akka
system = ActorSystem.Create("myAkkaSystem");
var coordinator = system.ActorOf<WorkCoordinatorActor>("workcoordinator");
bus = RabbitHutch.CreateBus("host=localhost");
bus.Subscribe<CdrRecieved>("<mysubId>", message => {
var result = coordinator.Ask<WorkCompleted>(new StartWorkFor() {Details = message}).Result;
//do something with it
});
@Danthar
Danthar / gist:2526439ce65f3502b18d
Created April 13, 2015 14:01
Aks and Sender references
coordinatorActor.Ask<string>(new JuleeDoTheThing());
//meanwhile in the coordinatorActor..
//..
Receive<JuleeDoTheThing>(message => {
_askParent = Context.Sender;
childActor.Tell(new DoSomething());
@Danthar
Danthar / gist:d1fe5581a6ba13ca6e30
Created April 15, 2015 07:42
Akka.net Nested ask async await issue example
using System;
using Akka.Actor;
namespace AkkaAsyncAwait
{
class Program
{
static void Main(string[] args)
{
var system = ActorSystem.Create("MySystem");
@Danthar
Danthar / gist:594d08dc26bc36cfab34
Created April 24, 2015 06:42
Consume RabbitMq messages with Akka : Part 2
//this is with the easynetq librabry but could just as easily be anything else.
rabbitBus.Subscribe<MyMessageType>(subscriptionId, message => {
Log.Debug("message from rabbitmq received");
//this works! because of how Ask works (it creates a fake actor that is passed as sender behind the scenes)
var result = workers.Ask<WorkCompleted>(new StartWorkFor() {Details = message}).Result;
});
//however this...
@Danthar
Danthar / gist:5c44f93e65706467cc46
Created May 8, 2015 11:49
Simple akka supervision and retry with IUnboundedStash example
class Program
{
static void Main(string[] args) {
var system = ActorSystem.Create("failboat");
var actor = system.ActorOf(Props.Create(() => new ParentActor()));
actor.Tell(5); //this will fail
actor.Tell("This message will work");
@Danthar
Danthar / gist:12f1b2dd229d4e58927a
Created June 8, 2015 13:49
Start werkzaamheden - command based - vanaf scratch poc
public class WerkbonAggregate {
private WerkbonModel _state;
private List<object> _uncommittedEvents = new List<object>();
public WerkbonAggregate(WerkbonModel state) {
_state = state;
}
public void StartWerkzaamHeden(DateTime gestartOp){
@Danthar
Danthar / Throttler.cs
Created June 18, 2015 10:45
Basic throttler
//Usefull for consumer/producer processing where you keep track of how many work you have served up in the producer
//and call Wait with that amount
//then consumer will call Hit to signal some work has been completed.
//producer will block on Wait until consumer has catched up
public class Throttler {
private AutoResetEvent resetEvent = new AutoResetEvent(false);
private int counter;
private int throttleAmount;
@Danthar
Danthar / gist:5e2812d3d6ca31129c01
Last active August 29, 2015 14:23
Router supervisionstrategies
using System;
using Akka.Actor;
using Akka.Routing;
namespace Akka.RouterStrategies
{
class Program
{
static void Main(string[] args) {
var system = ActorSystem.Create("failboat");
2015-07-08 14:10:41.588 +02:00 [Information] "Message DeathWatchNotification from akka://Importer/user/stamdata/importRouter/$b/processor to akka://Importer/user/stamdata/importRouter/$b/processor was not delivered. 1 dead letters encountered."
2015-07-08 14:10:41.589 +02:00 [Information] "Message DeathWatchNotification from akka://Importer/user/stamdata/importRouter/$b to akka://Importer/user/stamdata/importRouter/$b was not delivered. 2 dead letters encountered."
2015-07-08 14:10:41.589 +02:00 [Information] "Message DeathWatchNotification from akka://Importer/user/stamdata/importRouter/$b/processor/database to akka://Importer/user/stamdata/importRouter/$b/processor/database was not delivered. 3 dead letters encountered."
2015-07-08 14:10:41.590 +02:00 [Information] "Message DeathWatchNotification from akka://Importer/user/stamdata/importRouter/$b to akka://Importer/user/stamdata/importRouter/$b was not delivered. 4 dead letters encountered."
2015-07-08 14:10:41.591 +02:00 [Information] "Message DeathWatchNo