public async Task <QueueDescription> Create(string queuePath, INamespaceManager namespaceManager) { var description = descriptionFactory(queuePath, settings); try { if (!await ExistsAsync(namespaceManager, description.Path).ConfigureAwait(false)) { await namespaceManager.CreateQueue(description).ConfigureAwait(false); logger.InfoFormat("Queue '{0}' created in namespace '{1}'.", description.Path, namespaceManager.Address.Host); var key = GenerateQueueKey(namespaceManager, queuePath); await rememberExistence.AddOrUpdate(key, s => Task.FromResult(true), (s, b) => Task.FromResult(true)).ConfigureAwait(false); } else { logger.InfoFormat("Queue '{0}' in namespace '{1}' already exists, skipping creation.", description.Path, namespaceManager.Address.Host); logger.InfoFormat("Checking if queue '{0}' in namespace '{1}' needs to be updated.", description.Path, namespaceManager.Address.Host); if (IsSystemQueue(description.Path)) { logger.InfoFormat("Queue '{0}' in '{1}' is a shared queue and should not be updated.", description.Path, namespaceManager.Address.Host); return(description); } var existingDescription = await namespaceManager.GetQueue(description.Path).ConfigureAwait(false); if (MembersAreNotEqual(existingDescription, description)) { OverrideImmutableMembers(existingDescription, description); logger.InfoFormat("Updating queue '{0}' in namespace '{1}' with new description.", description.Path, namespaceManager.Address.Host); await namespaceManager.UpdateQueue(description).ConfigureAwait(false); } } } catch (MessagingEntityAlreadyExistsException) { // the queue already exists or another node beat us to it, which is ok logger.InfoFormat("Queue '{0}' in namespace '{1}' already exists, another node probably beat us to it.", description.Path, namespaceManager.Address.Host); } catch (TimeoutException) { logger.InfoFormat("Timeout occurred on queue creation for '{0}' in namespace '{1}' going to validate if it doesn't exist.", description.Path, namespaceManager.Address.Host); // there is a chance that the timeout occurred, but the topic was still created, check again if (!await ExistsAsync(namespaceManager, description.Path, removeCacheEntry: true).ConfigureAwait(false)) { throw; } logger.InfoFormat("Looks like queue '{0}' in namespace '{1}' exists anyway.", description.Path, namespaceManager.Address.Host); } catch (MessagingException ex) { if (!ex.IsTransient) { logger.Fatal(string.Format("{1} {2} occurred on queue creation '{0}' in namespace '{3}'.", description.Path, (ex.IsTransient ? "Transient" : "Non transient"), ex.GetType().Name, namespaceManager.Address.Host), ex); throw; } logger.Info(string.Format("{1} {2} occurred on queue creation '{0}' in namespace '{3}'.", description.Path, (ex.IsTransient ? "Transient" : "Non transient"), ex.GetType().Name, namespaceManager.Address.Host), ex); } return(description); }