public void IncludesCorrelationIdInTheThreeLoggedLines() { // ${basedir}/logs/logfile.log var logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", "logfile.log"); if (File.Exists(logFilePath)) { File.Delete(logFilePath); } var activator = new BuiltinHandlerActivator(); Configure.With(Using(activator)) .Logging(l => l.NLog()) .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "test")) .Start(); var counter = new SharedCounter(1); Using(counter); var logger = LogManager.GetLogger("test"); activator.Handle<string>(async str => { logger.Info("1"); await Task.Delay(100); logger.Info("2"); await Task.Delay(100); logger.Info("3"); counter.Decrement(); }); var headers = new Dictionary<string,string> { {Headers.CorrelationId, "known-correlation-id" } }; activator.Bus.SendLocal("hej med dig min ven!!!", headers).Wait(); counter.WaitForResetEvent(); WaitForFile(logFilePath); var loggedLines = File.ReadAllLines(logFilePath); AssertLineIsThere(loggedLines, "1|known-correlation-id"); AssertLineIsThere(loggedLines, "2|known-correlation-id"); AssertLineIsThere(loggedLines, "3|known-correlation-id"); }
public async Task YesItDoes() { using (var activator = new BuiltinHandlerActivator()) { var counter = new SharedCounter(1); activator.Handle<string>(async str => counter.Decrement()); var bus = Configure.With(activator) .Transport(t => t.UseAzureServiceBus(_connectionString, _queueName).EnablePartitioning()) .Start(); await bus.SendLocal("hej med dig min ven!!!"); counter.WaitForResetEvent(); } }
public async Task CommitsBeforeSendingMessages() { var counter = new SharedCounter(1); _otherActivator.Handle<string>(async str => { RegisterEvent("message sent from uow-enabled endpoint was handled"); }); _uowActivator.Handle<string>(async (bus, str) => { RegisterEvent("uow-message handled"); await bus.Advanced.Routing.Send(OtherQueueName, "woohooo!!!"); counter.Decrement(); }); RegisterEvent("message sent"); await _uowBus.SendLocal("hej med dig min veeeeeen!"); counter.WaitForResetEvent(); await Task.Delay(1000); var events = _events.ToArray(); var expectedEvents = new[] { "message sent", "uow-message handled", "uow committed", "uow cleaned up", "message sent from uow-enabled endpoint was handled" }; Assert.That(events, Is.EqualTo(expectedEvents)); }
public void WorksWithPrefetch(int prefetch, int numberOfMessages) { var activator = Using(new BuiltinHandlerActivator()); var counter = new SharedCounter(numberOfMessages); Using(counter); activator.Handle<string>(async str => { counter.Decrement(); }); Console.WriteLine("Sending {0} messages", numberOfMessages); var transport = GetTransport(); var tasks = Enumerable.Range(0, numberOfMessages) .Select(i => $"THIS IS MESSAGE # {i}") .Select(async msg => { using (var context = new DefaultTransactionContext()) { var headers = DefaultHeaders(); var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(msg)); var transportMessage = new TransportMessage(headers, body); await transport.Send(_queueName, transportMessage, context); await context.Complete(); } }) .ToArray(); Task.WhenAll(tasks).Wait(); Console.WriteLine("Receiving {0} messages", numberOfMessages); var stopwatch = Stopwatch.StartNew(); Configure.With(activator) .Transport(t => { t.UseAzureServiceBus(StandardAzureServiceBusTransportFactory.ConnectionString, _queueName, _mode) .EnablePrefetching(prefetch); }) .Options(o => { o.SetNumberOfWorkers(5); o.SetMaxParallelism(10); }) .Start(); counter.WaitForResetEvent(timeoutSeconds: (int)(numberOfMessages * 0.1 + 3)); var elapsedSeconds = stopwatch.Elapsed.TotalSeconds; Console.WriteLine("Receiving {0} messages took {1:0.0} s - that's {2:0.0} msg/s", numberOfMessages, elapsedSeconds, numberOfMessages / elapsedSeconds); }