Skip to content

Instantly share code, notes, and snippets.

abdullin / SampleQuarantine.cs
Created Jun 15, 2011
Quarantine sample that reports recurring failures to email (sample for Lokad.CQRS v2.0)
View SampleQuarantine.cs
// This quarantine sample uses in-memory quarantine to detect repetitive processing failures
// It records each failure into the streaming container (which could be file/Azure)
// When failure threshold is breached, we send an email to the hardcoded address.
// failure message contains all information about failures and message contents
public sealed class MailQuarantine : IEnvelopeQuarantine
readonly SmtpHandlerCore _core;
readonly IStreamingContainer _container;
readonly MemoryQuarantine _quarantine = new MemoryQuarantine();
abdullin / IEnvelopeQuarantine.cs
Created Jun 16, 2011
Documented version of IEnvelopeQuarantine
View IEnvelopeQuarantine.cs
/// <summary>
/// Implements quarantine logic for the specific message handler. Default implementation
/// is <see cref="MemoryQuarantine"/>
/// </summary>
public interface IEnvelopeQuarantine
/// <summary>
/// Tries to quarantine the specified envelope. Implementation can decide whether we need to give another
/// try to process the envelope (by returning <em>False</em>) or if quarantine should accept the envelope
/// completely. Then processor will discard the queue from it's incoming queue and leave it up to the
abdullin / RegisterPoisoningQuarantine.cs
Created Jun 16, 2011
An example of registering poison quarantine.
View RegisterPoisoningQuarantine.cs
x.Quarantine(c => {
var logRoot = c.Resolve<IStreamingRoot>();
var registry = c.Resolve<QueueWriterRegistry>();
IQueueWriterFactory factory;
if (!registry.TryGet("azure-account-name", out factory))
throw new IOE("Didn't find the specified Azure account. Did you register it in the queue registry?")
// registration is right now, if you don't have it already
// builder.Advanced.RegisterQueueWriterFactory(c => new AzureQueueWriterFactory(account, c.Resolve<IEnvelopeStreamer>()));
return new SampleQuarantine(logging, factory);
abdullin / RoutingDispatcher.cs
Created Jun 20, 2011
Sample of message dispatcher that routes and records messages (for Lokad.CQRS v2.0)
View RoutingDispatcher.cs
// this dispatchers routes all incoming messages between 2 queues (commands/events)
// and also records all messages into a tape storage.
// fore registration sample see
public sealed class RoutingDispatcher : ISingleThreadMessageDispatcher
readonly IDictionary<string, IQueueWriter> _routes = new Dictionary<string, IQueueWriter>();
readonly QueueWriterRegistry _factories;
readonly string _endpoint;
readonly ITapeWriter _writer;
readonly IEnvelopeStreamer _streamer;
abdullin / RoutingDispatcherRegistration.cs
Created Jun 20, 2011
Sample of registering routing dispatcher with custom quarantine (Lokad.CQRS v2.0)
View RoutingDispatcherRegistration.cs
m.AddAzureProcess(config, IdFor.Publish, p =>
(c, a, x) =>
// provided by the bus
var registry = c.Resolve<QueueWriterRegistry>();
var streamer = c.Resolve<IEnvelopeStreamer>();
// not provided by bus in v2.0
var tapeWriter = c.Resolve<ITapeWriter>();
abdullin / RedirectToWhen.cs
Created Jun 26, 2011
Static helper class for invoking handling methods on AR and AR state.
View RedirectToWhen.cs
// snippet is for
// simple helper, that looks up and calls the proper overload of
// When(SpecificEventType event). Reflection information is cached statically
// once per type.
public static class RedirectToWhen
static class Cache<T>
public static readonly IDictionary<Type, MethodInfo> Dict = typeof(T)
abdullin / TimerService.cs
Created Jun 28, 2011
Sample of a timer service for powering up sagas (for Lokad.CQRS v2.0)
View TimerService.cs
// the gist is discussed in:
// This is a sample of a timer service for powering up sagas (for Lokad.CQRS v2.0)
// register it in CqrsHostBuilder like this:
// hostBuilder.Advanced.ConfigureContainer(cb => cb.RegisterType<TimerService>().As<IEngineProcess>());
public sealed class TimerService : IEngineProcess
readonly IMessageSender _sender;
public TimerService(IMessageSender sender)
abdullin / WebRole.cs
Created Jul 6, 2011
Sample of running AppEngine inside the Web Role (for Lokad.CQRS v2.0)
View WebRole.cs
// Sample of running AppEngine inside the Web Role, essentially merging
// 1 worker role and 1 web role (for Lokad.CQRS v2.0)
// For explanation see:
public class WebRole : RoleEntryPoint
CqrsEngineHost _host;
readonly CancellationTokenSource _source = new CancellationTokenSource();
public override bool OnStart()
abdullin / Program.cs
Created Oct 6, 2011
Wiring Lokad-CodeDSL in a MightyMoose style.
View Program.cs
// This is a hacky sample (that works for me) of alternative way to use Lokad-codeDSL
// or any similar way of generating message contracts on-the-fly. Original approach was
// with using T4 template, that would rebuild cs files from DSL representation, whenever
// we hit Ctrl-S.
// This approach works almost exactly like this (Ctrl-S to rebuild), but does not require VS
// to run or does not require unloading VS to change the underlying generator code.
// in fact it is extremely boring. Lolcats from MightyMoose could be used to improve the situation, though.
// any takers? :)
abdullin / TestMessageSerialization.cs
Created Oct 12, 2011
Sample of using Specifications to test serializers
View TestMessageSerialization.cs
/// <summary>
/// This class scans all available specifications for messages used
/// then performs round-trip via specified serializer,
/// and then does the structural comparison of resulting values
/// </summary>
public sealed class TestMessageSerialization
static Group[] ListMessages()