private void EnsureTopicExists(string topicName) { if (_topicExistanceChecked) { return; } using (var scope = CustomTransactionScope.GetTransactionSuppressedScope()) { _syncService.Execute("WindowsServiceBus_" + topicName, () => { var namespaceManager = GetNamespaceManager(); if (!namespaceManager.TopicExists(topicName)) { _logger.Debug("Attempting to create topic {0}...".Args(topicName)); var topicDescription = new TopicDescription(topicName); namespaceManager.CreateTopic(topicDescription); _logger.Debug("Topic {0} created.".Args(topicName)); } _topicExistanceChecked = true; }); scope.Complete(); } }
public void PublishExternalMessage <T>(T message) where T : class { var brokeredMessage = new BrokeredMessage(message) { ContentType = message.GetType().AssemblyQualifiedName }; using (var scope = CustomTransactionScope.GetTransactionSuppressedScope()) { TopicClient.Send(brokeredMessage); scope.Complete(); } }
private string EnsureSubscriptionExists(string topicName, Type subscriberType) { string subscriptionName = subscriberType.Name; var key = topicName + subscriptionName; if (_subscriptionsWithCheckedExistance.Contains(key)) { return(subscriptionName); } using (var scope = CustomTransactionScope.GetTransactionSuppressedScope()) { _syncService.Execute("WindowsServiceBus_" + subscriptionName, () => { var types = subscriberType .GetInterfaces() .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IConsumes <>)) .SelectMany(i => i.GetGenericArguments()) .OrderBy(x => x.FullName) .ToList(); var namespaceManager = GetNamespaceManager(); if (!namespaceManager.SubscriptionExists(topicName, subscriptionName)) { _logger.Debug("Attempting to create subscription for {0} in topic {1}...".Args(subscriptionName, topicName)); var subscriptionDescription = new SubscriptionDescription(topicName, subscriptionName); namespaceManager.CreateSubscription(subscriptionDescription); _logger.Debug("Subscription for {0} in topic {1} created.".Args(subscriptionName, topicName)); } UpsertSubscriptionRules(topicName, subscriptionName, types); _subscriptionsWithCheckedExistance.Add(key); }); scope.Complete(); } return(subscriptionName); }
public void PublishMessage <T>(T message) where T : class, IMessage { EnsureTopicExists(TopicName); EnsureTopicClientExists(TopicName); var json = JsonConvert.SerializeObject(message); var brokeredMessage = new BrokeredMessage(json) { ContentType = "application/json", Label = message.GetType().FullName }; brokeredMessage.Properties[PropertyForTypeName] = message.GetType().Name; brokeredMessage.Properties[PropertyForTypeFullName] = message.GetType().FullName; using (var scope = CustomTransactionScope.GetTransactionSuppressedScope()) { _topicClient.Send(brokeredMessage); scope.Complete(); } }
private void EnsureTopicExists(string topicName) { if (_topicExistanceChecked) { return; } using (var scope = CustomTransactionScope.GetTransactionSuppressedScope()) { var namespaceManager = GetNamespaceManager(); if (!namespaceManager.TopicExists(topicName)) { _logger.Debug("Fake Ugs Service Bus: Attempting to create topic {0}".Args(topicName)); var topicDescription = new TopicDescription(topicName); namespaceManager.CreateTopic(topicDescription); _logger.Debug("Fake Ugs Service Bus: Topic {0} created".Args(topicName)); } _topicExistanceChecked = true; scope.Complete(); } }