Skip to content

Instantly share code, notes, and snippets.

@abdullin
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
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 https://gist.github.com/1035950
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
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 =>
{
p.DispatcherIs(
(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
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: http://groups.google.com/group/lokad/browse_thread/thread/4d39dc299037ea09
// 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
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: http://abdullin.com/journal/2011/7/6/lokadcqrs-can-make-windows-azure-cheaper-for-you.html
public class WebRole : RoleEntryPoint
{
CqrsEngineHost _host;
readonly CancellationTokenSource _source = new CancellationTokenSource();
public override bool OnStart()
{
@abdullin
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>
[TestFixture]
public sealed class TestMessageSerialization
{
static Group[] ListMessages()
{
View SimpleMessage.cs
/// <summary>
/// Source: https://gist.github.com/1308830
/// This simple envelope includes only:
/// <code>
/// Header - int32
/// TotalLength - int32
/// IdLength - int32
/// UTF8-encoded message ID - byte[IdLength]
/// ContractLength - int32
/// UTF-encoded contract name 0 byte[ContractLength]
@abdullin
abdullin / SessionStore.js
Created Mar 6, 2015
Example of a Flux Store that maintains session token in a cookie
View SessionStore.js
"use strict";
var createStore = require("fluxible/utils/createStore");
var client = require("../client");
var cookies = require("cookies-js");
var debug = require("debug")("ClientTokenStore");
var ClientTokenStore = createStore({
storeName: "ClientSessionStore",
@abdullin
abdullin / cqrs-search.html
Created Feb 2, 2012
Snippet that does AJAX search over a denormalized projection (handled by server) in async
View cqrs-search.html
// Snippet that shows AJAX search over a denormalized projection (handled by server) in async
// for sending commands in async - just do the AJAX post to server
// for getting changes - just poll the server for view version
// for cases when polling is expensive - use web sockets.
<script type="text/javascript">
$(document).ready(function () {
$('#searchButton').click(function () {
GetData($('#searchbox').val());
@abdullin
abdullin / lock_user.cs
Created Sep 14, 2012
Rough cuts of improved Simple Testing
View lock_user.cs
// sample unit test for a command "LockUser"
public class lock_user : user_syntax
{
static readonly UserId id = new UserId(1);
static readonly SecurityId sec = new SecurityId(1);
static readonly TimeSpan fiveMins = TimeSpan.FromMinutes(5);
[Test]