Skip to content

Instantly share code, notes, and snippets.

View andreasohlund's full-sized avatar

Andreas Öhlund andreasohlund

View GitHub Profile
using System;
using System.Linq;
using System.Web.Http;
using System.Web.Mvc;
using NServiceBus;
public static class ConfigureWeAPiDependencyInjection
{
public static Configure ForWebApi(this Configure configure)
{
using System;
using System.Collections.Generic;
using System.Web.Http.Dependencies;
using NServiceBus;
using NServiceBus.ObjectBuilder;
public class NServiceBusDependencyResolverAdapter : IDependencyResolver
{
readonly IBuilder builder;
<configSections>
<section name="MessageForwardingInCaseOfFaultConfig"
type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
</configSections>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error"/>
@andreasohlund
andreasohlund / endpoint.cs
Created August 24, 2012 08:31
New fluent api
namespace NServiceBus.Config
{
/// <summary>
/// Configuration class for Endpoint attributes.
/// </summary>
public class Endpoint : IContainRuntimeSettings
{
/// <summary>
/// Requests that queues will be created as Volatile (non-transactional) hence sending and receiving will be outside a transaction
/// </summary>
@andreasohlund
andreasohlund / CustomRetryPolicy.cs
Created September 25, 2012 11:49
How to turn SLR of for a given exception type
public class ChangeRetryPolicy : INeedInitialization
{
public void Init()
{
SecondLevelRetries.RetryPolicy = (tm) =>
{
// retry max 3 times
if (TransportMessageHelpers.GetNumberOfRetries(tm) >= 3)
{
// To send back a value less than zero tells the
if(tm.Headers["NServiceBus.ExceptionInfo.ExceptionType"] == typeof(MyBusinessException).FullName)
return TimeSpan.MinValue;
public class ShippingPolicy : Saga<ShippingPolicyData>,
IAmStartedByMessages<OrderAccepted>,
IHandleMessages<OrderBilled>
{
public void Handle(OrderAccepted message)
{
Data.OrderId = message.OrderId;
Data.Accepted = true;
DispatchOrder();
}
@andreasohlund
andreasohlund / DeduplicationCleanup.cs
Created October 9, 2012 08:01
How to clear the NServiceBus inMemory gateway persister periodically
public class DeduplicationCleanup : IWantToRunWhenTheBusStarts
{
public InMemoryPersistence MemoryPersistence { get; set; }
public void Run()
{
Schedule.Every(TimeSpan.FromMinutes(1))
//delete all ID's older than 30 minutes
.Action(()=> MemoryPersistence.DeleteDeliveredMessages(DateTime.UtcNow.AddMinutes(30)));
}
}
@andreasohlund
andreasohlund / DeduplicationCleanup.cs
Created October 9, 2012 08:01
How to clear the NServiceBus inMemory gateway persister periodically
public class DeduplicationCleanup : IWantToRunWhenTheBusStarts
{
public InMemoryPersistence MemoryPersistence { get; set; }
public void Run()
{
Schedule.Every(TimeSpan.FromMinutes(1))
//delete all ID's older than 30 minutes
.Action(()=> MemoryPersistence.DeleteDeliveredMessages(DateTime.UtcNow.AddMinutes(-30)));
}
}
<system.net>
<defaultProxy>
<proxy usesystemdefault="False" bypassonlocal="True" proxyaddress="http://127.0.0.1:8888"/>
</defaultProxy>
</system.net>