This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static Mutex SingleInstanceMutex = AcquireGlobalMutex("Receiver"); | |
static Mutex AcquireGlobalMutex(string id, int durationInSeconds = 1) | |
{ | |
var m = new Mutex(true, @"Global\" + id); | |
var maxWaitDuration = TimeSpan.FromSeconds(durationInSeconds); | |
if (!m.WaitOne(maxWaitDuration)) throw new InvalidOperationException("Failed to acquire mutex."); | |
return m; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SendDoSomethingTask : IWantToRunWhenEndpointStartsAndStops | |
{ | |
ILog log = LogManager.GetLogger<SendDoSomethingTask>(); | |
Task loop; | |
CancellationTokenSource cancellationTokenSource; | |
public Task Start(IMessageSession session) | |
{ | |
cancellationTokenSource = new CancellationTokenSource(); | |
loop = Task.Run(async () => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using NServiceBus.Logging; | |
using NServiceBus.Pipeline; | |
/// <code> | |
/// endpointConfiguration.Pipeline.Register(behavior: new LogDispatchedMessageIdBehavior(), description: LogDispatchedMessageIdBehavior.Description); | |
/// </code> | |
class LogDispatchedMessageIdBehavior : Behavior<IBatchDispatchContext> | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Linq; | |
interface IMetrics | |
{ | |
void UpdateDuration(Stopwatch value); | |
} | |
class MetricsViaPerformanceCounters : IDisposable, IMetrics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using NServiceBus; | |
using NServiceBus.Transport; | |
class ExponentialBackoffPolicy | |
{ | |
static Random random = new Random(); | |
public static RecoverabilityAction Process(RecoverabilityConfig config, ErrorContext context) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class StartableEndpointExtensions | |
{ | |
public static async Task<IEndpointInstance> StartWithRetry( | |
this IStartableEndpoint startableEndpoint, | |
int maxAttempts = 10 | |
) | |
{ | |
var attempts = 0; | |
while (true) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using NServiceBus; | |
class ShippingSpeedMetricCollector | |
: Saga<ShippingSpeedData> | |
, IAmStartedByMessages<OrderCreated> | |
, IHandleMessages<OrderCancelled> | |
, IHandleMessages<OrderShipped> | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Concurrent; | |
using System.Collections.Generic; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Raven.Client; | |
/// <summary> | |
/// This class allows performing high throughput document store operations, using a batching mechanism | |
/// That mechanism collects up to 128 documents into a single batch and stores them in a single operation, reducing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (args.Length == 1 && args[0] == "install") | |
{ | |
await Console.Out.WriteLineAsync("Running installers...").ConfigureAwait(false); | |
var endpointConfiguration = CreateConfiguration(); | |
endpointConfiguration.EnableInstallers(); | |
await Endpoint.Create(endpointConfiguration).ConfigureAwait(false); | |
return; // Exit application, we are not going to start the endpoint and process messages | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Via send options. | |
var sendOptions = new SendOptions(); | |
sendOptions.SetHeader("StackTrace", System.Environment.StackTrace); | |
await context.Send(myMessage, sendOptions).ConfigureAwait(false); | |
// Via outgoing message mutator, requires registering the mutator via the endpoint configuration. | |
class AddStackTraceMutator : IMutateOutgoingTransportMessages | |
{ | |
public Task MutateOutgoing(MutateOutgoingTransportMessageContext context) |