This file contains hidden or 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.Messaging; | |
| using System.Runtime.InteropServices; | |
| static class MsmqExtensions | |
| { | |
| /// <remarks> | |
| /// Source: http://functionalflow.co.uk/blog/2008/08/27/counting-the-number-of-messages-in-a-message-queue-in/ | |
| /// </remarks> | |
| public static int GetCount(this MessageQueue self) |
This file contains hidden or 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
| var config = new LoggingConfiguration(); | |
| var console = new ColoredConsoleTarget(); | |
| var async = new AsyncTargetWrapper(console); | |
| config.AddTarget("console", wrapper); | |
| config.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, async)); | |
| config.DefaultCultureInfo = CultureInfo.InvariantCulture; |
This file contains hidden or 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
| <?xml version="1.0" encoding="utf-8" ?> | |
| <configuration> | |
| <appSettings> | |
| <add key="NServiceBus/ErrorAddress" value="error"/> | |
| <add key="NServiceBus/AuditAddress" value="audit"/> | |
| <add key="NServiceBus/InstanceMappingFile" value="instances.xml"/> | |
| <add key="NServiceBus/RouteMappingFile" value="routes.xml"/> | |
| <add key="NServiceBus/MonitoringAddress" value=""/> | |
| <!--<add key="NServiceBus/InstanceId" value="1"/>--> | |
| </appSettings> |
This file contains hidden or 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 log4net; | |
| using NServiceBus.Pipeline; | |
| /// <summary> | |
| /// Pushes the current message ID to the log4net NDC stack. When using a log4net conversation pattern containing `%ndc` then this value used ("%date [%-3thread] %-5level [%ndc] %logger - %message%newline"). | |
| /// </summary> | |
| /// <example> | |
| /// var pipeline = endpointConfiguration.Pipeline; |
This file contains hidden or 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 AssignMessageIdtoNLogNdlcBehavior : Behavior<ITransportReceiveContext> | |
| { | |
| public override async Task Invoke(ITransportReceiveContext context, Func<Task> next) | |
| { | |
| var headers = context.Message.Headers; | |
| headers.TryGetValue(Headers.ConversationId, out var conversationId); | |
| headers.TryGetValue(Headers.CorrelationId, out var correlationId); | |
| using (NLog.NestedDiagnosticsLogicalContext.Push(context.Message.MessageId)) | |
| using (MappedDiagnosticsLogicalContext.SetScoped(Headers.ConversationId, conversationId)) |
This file contains hidden or 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; | |
| using System.Threading.Tasks; | |
| using System.Transactions; | |
| using log4net.Appender; | |
| using log4net.Core; | |
| using NServiceBus; | |
| [Obsolete("This is a proof of concept! It is not advisable to use this appender in a hot path! It probably is better to use something more lightweight as https://www.nuget.org/packages/log4net.Appender.Msmq/")] | |
| class NServiceBusAppender : AppenderSkeleton |
This file contains hidden or 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; | |
| using System.Threading.Tasks; | |
| using NServiceBus; | |
| class SerializedHandler : IHandleMessages<MyMessage> | |
| { | |
| static readonly SemaphoreSlim sequentialAccess = new SemaphoreSlim(1); | |
| static readonly TimeSpan waitDuration = TimeSpan.FromSeconds(5); |
This file contains hidden or 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
| var logLevelValue = ConfigurationManager.AppSettings["NServiceBus/Logging/LogLevel"]; | |
| var logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), logLevelValue); | |
| var defaultFactory = LogManager.Use<DefaultFactory>(); | |
| defaultFactory.Level(LogLevel); |
This file contains hidden or 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
| /// <summary> | |
| /// Usage: | |
| /// endpointConfiguration.Pipeline.Register(new SequentialProcessingByMessageTypeBehavior(), "Processes incoming messages of the same type sequentially."); | |
| /// </summary> | |
| class SequentialProcessingByMessageTypeBehavior : IBehavior<IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext> | |
| { | |
| TimeSpan Timeout = TimeSpan.FromSeconds(1); | |
| ConcurrentDictionary<string, SemaphoreSlim> semaphores = new ConcurrentDictionary<string, SemaphoreSlim>(); | |
| public async Task Invoke(IIncomingPhysicalMessageContext context, Func<IIncomingPhysicalMessageContext, Task> next) |
This file contains hidden or 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.Data.Entity; | |
| using System.Threading.Tasks; | |
| using NServiceBus; | |
| public class UpdateDataInDifferentCatalogHandler | |
| : IHandleMessages<CompleteOrder> | |
| { | |
| public async Task Handle(MyMessage message, IMessageHandlerContext context) | |
| { | |
| var sharedSession = context.SynchronizedStorageSession.SqlPersistenceSession(); |