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 NServiceBus; | |
| using NServiceBus.Logging; | |
| class LogHandler : IHandleMessages<object> | |
| { | |
| static readonly ILog Log = LogManager.GetLogger<LogHandler>(); | |
| public IBus Bus { get; set; } |
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.Collections.Concurrent; | |
| using System.Diagnostics; | |
| using System.Threading.Tasks; | |
| using NServiceBus; | |
| using NServiceBus.Pipeline; | |
| class OriginatingMachineLatencyBehavior : Behavior<IIncomingPhysicalMessageContext> | |
| { | |
| ConcurrentDictionary<string, (PerformanceCounter Counter, PerformanceCounter Base)> machineCounters = new ConcurrentDictionary<string, (PerformanceCounter,PerformanceCounter)>(); |
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
| // https://stackoverflow.com/questions/281640/how-do-i-get-a-human-readable-file-size-in-bytes-abbreviation-using-net | |
| public static class SizeFormatter | |
| { | |
| static String StrFormatByteSize (long length, IFormatProvider provider) | |
| { | |
| const int kb = 1024; | |
| string[] suffix = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; | |
| if (length == 0) return "0" + suffix[0]; | |
| var bytes = Math.Abs(length); | |
| var index = (int)Math.Floor(Math.Log(bytes, kb)); |
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.Text; | |
| using System.Threading.Tasks; | |
| using NServiceBus.Logging; | |
| using NServiceBus.MessageMutator; | |
| class LogMessageHeadersMutator : IMutateIncomingTransportMessages | |
| { | |
| static readonly ILog Log = LogManager.GetLogger<LogMessageHeadersMutator>(); | |
| public Task MutateIncoming(MutateIncomingTransportMessageContext context) |
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
| // LogManager.Use<DefaultFactory>().Level(LogLevel.Debug); | |
| // var pipeline = endpointConfiguration.Pipeline; | |
| // pipeline.Register(new IN(), nameof(IN)); | |
| // pipeline.Register(new OUT(), nameof(OUT)); | |
| class IN : Behavior<IIncomingLogicalMessageContext> | |
| { | |
| public const string Key = "count"; | |
| static long count; | |
| static readonly ILog Log = LogManager.GetLogger<IN>(); |
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; | |
| public class CustomOptionsWrapper : IEndpointInstance | |
| { | |
| readonly IEndpointInstance innerInstance; | |
| readonly IPrincipalAccessor principalAccessor; | |
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
| // Usage: endpointConfiguration.Pipeline.Register(typeof(EnforceTransactionScopePromotionBehavior), nameof(EnforceTransactionScopePromotionBehavior)); | |
| public class EnforceTransactionScopePromotionBehavior : IBehavior<IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext> | |
| { | |
| public Task Invoke(IIncomingPhysicalMessageContext context, Func<IIncomingPhysicalMessageContext, Task> next) | |
| { | |
| var transaction = System.Transactions.Transaction.Current; | |
| if(transaction==null) throw new InvalidOperationException($"No ambient TransactionScope active, disable {nameof(EnforceTransactionScopePromotionBehavior)} behavior"); | |
| System.Transactions.TransactionInterop.GetTransmitterPropagationToken(transaction); | |
| return next(context); | |
| } |
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
| static class Jitter | |
| { | |
| static readonly Random Random = new Random(); | |
| public static TimeSpan Next(int count, TimeSpan first) | |
| { | |
| double jitter; | |
| lock (Random) jitter = Random.NextDouble(); // Needed to make random threadsafe | |
| return TimeSpan.FromTicks((long) (first.Ticks * Math.Pow(2, count + jitter))); | |
| } |
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
| CREATE TABLE [dbo].[EndpointInstance] | |
| ( | |
| [EndpointName] VARCHAR(128) NOT NULL, | |
| [Discriminator] VARCHAR(128) NULL DEFAULT NULL, | |
| [Machine] VARCHAR(256) NOT NULL | |
| ) |
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
| for /R %%X in (*.csv) do "c:\Program Files\7-Zip\7z.exe" a -tgzip -sdel -mx9 "%%X.gz" "%%X" |