public async Task CanUseAlternativeTimeoutManager() { var gotTheString = new ManualResetEvent(false); _activator.Handle <string>(async str => { Console.WriteLine($"Received string: '{str}'"); gotTheString.Set(); }); var bus = Configure.With(_activator) .Transport(t => { var options = new AzureStorageQueuesTransportOptions { UseNativeDeferredMessages = false }; t.UseAzureStorageQueues(_storageAccount, QueueName, options: options); }) .Timeouts(t => t.Register(c => new InMemoryTimeoutManager(new DefaultRebusTime()))) .Start(); await bus.DeferLocal(TimeSpan.FromSeconds(5), "hej med dig min ven!!!!!"); gotTheString.WaitOrDie(TimeSpan.FromSeconds(10), "Did not receive the string withing 10 s timeout"); }
/// <summary> /// Constructs the transport /// </summary> public AzureStorageQueuesTransport(CloudStorageAccount storageAccount, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, AzureStorageQueuesTransportOptions options) { if (storageAccount == null) { throw new ArgumentNullException(nameof(storageAccount)); } if (rebusLoggerFactory == null) { throw new ArgumentNullException(nameof(rebusLoggerFactory)); } _options = options; _queueClient = storageAccount.CreateCloudQueueClient(); _log = rebusLoggerFactory.GetLogger <AzureStorageQueuesTransport>(); _initialVisibilityDelay = options.InitialVisibilityDelay; if (inputQueueName != null) { if (!Regex.IsMatch(inputQueueName, QueueNameValidationRegex)) { throw new ArgumentException($"The inputQueueName {inputQueueName} is not valid - it can contain only alphanumeric characters and hyphens, and must not have 2 consecutive hyphens.", nameof(inputQueueName)); } Address = inputQueueName.ToLowerInvariant(); } }
public async Task RunTest(bool prefetch, int messageCount, int workers, int parallelism) { var counter = new SharedCounter(messageCount); var activator = new BuiltinHandlerActivator(); var dictionary = new ConcurrentDictionary <string, object>(); Using(activator); activator.Handle <string>(async str => { dictionary.TryRemove(str, out _); counter.Decrement(); }); var bus = Configure.With(activator) .Logging(l => l.Console(minLevel: LogLevel.Warn)) .Transport(t => { var options = new AzureStorageQueuesTransportOptions { Prefetch = prefetch ? 32 : default(int?) }; t.UseAzureStorageQueues(AzureConfig.ConnectionString, QueueName, options); }) .Options(o => { o.SetNumberOfWorkers(0); o.SetMaxParallelism(parallelism); }) .Start(); await Task.WhenAll(Enumerable.Range(0, messageCount) .Select(async i => { var payload = $"THIS IS MESSAGE {i}"; dictionary[payload] = DummyObject; await bus.SendLocal(payload); })); var stopwatch = Stopwatch.StartNew(); bus.Advanced.Workers.SetNumberOfWorkers(workers); counter.WaitForResetEvent(120); var elapsedSeconds = stopwatch.Elapsed.TotalSeconds; Console.WriteLine($@"Receiving {messageCount} took {elapsedSeconds:0.0} s - that's {messageCount / elapsedSeconds:0.0} msg/s"); }
public async Task CanUseDedicatedAlternativeTimeoutManager() { // start the timeout manager Configure.With(Using(new BuiltinHandlerActivator())) .Transport(t => { var options = new AzureStorageQueuesTransportOptions { UseNativeDeferredMessages = false }; t.UseAzureStorageQueues(_storageAccount, TimeoutManagerQueueName, options: options); }) .Timeouts(t => t.Register(c => new InMemoryTimeoutManager(new DefaultRebusTime()))) .Start(); var gotTheString = new ManualResetEvent(false); _activator.Handle <string>(async str => { Console.WriteLine($"Received string: '{str}'"); gotTheString.Set(); }); var bus = Configure.With(_activator) .Transport(t => { var options = new AzureStorageQueuesTransportOptions { UseNativeDeferredMessages = false }; t.UseAzureStorageQueues(_storageAccount, QueueName, options: options); }) .Timeouts(t => t.UseExternalTimeoutManager(TimeoutManagerQueueName)) .Start(); await bus.DeferLocal(TimeSpan.FromSeconds(5), "hej med dig min ven!!!!!"); gotTheString.WaitOrDie(TimeSpan.FromSeconds(10), "Did not receive the string withing 10 s timeout"); //// don't dispose too quickly, or else we'll get annoying errors in the log //await Task.Delay(TimeSpan.FromSeconds(0.5)); }
public async Task CanDoIt() { var activator = Using(new BuiltinHandlerActivator()); var gotTheMessage = Using(new ManualResetEvent(initialState: false)); activator.Handle <string>(async str => gotTheMessage.Set()); Configure.With(activator) .Transport(t => { var options = new AzureStorageQueuesTransportOptions { UseNativeDeferredMessages = false }; t.UseAzureStorageQueues(AzureConfig.StorageAccount, TestConfig.GetName("myqueue"), options); }) .Timeouts(t => t.StoreInMemory()) .Start(); await activator.Bus.DeferLocal(TimeSpan.FromSeconds(2), "HEJ 🍗"); gotTheMessage.WaitOrDie(timeout: TimeSpan.FromSeconds(5)); }