public PingReceiver() { var nsm = NamespaceManager.Create(); if (nsm.SubscriptionExists(TopicName, SubscriptionName)) { nsm.DeleteSubscription(TopicName, SubscriptionName); } nsm.CreateSubscription(TopicName, SubscriptionName, new SqlFilter("sys.To = 'CentralQueueManager' AND ActionName = 'Ping'")); var client = SubscriptionClient.Create(TopicName, SubscriptionName); client.OnMessage(ProcessMessage); }
private static void CreateTopic(NamespaceManager namespaceManager) { if (namespaceManager == null) { namespaceManager = NamespaceManager.Create(); } if (namespaceManager.TopicExists(Constants.TopicName)) { return; } Console.WriteLine("\nCreating Topic '{0}'...", Constants.TopicName); namespaceManager.CreateTopic(Constants.TopicName); }
public SettingsManager(BarcodeAnalyzer analyzer) { _analyzer = analyzer; var nsm = NamespaceManager.Create(); if (!nsm.SubscriptionExists(TopicName, SubscriptionName)) { nsm.CreateSubscription(TopicName, SubscriptionName, new SqlFilter("sys.To = 'FileSender' AND ActionName = 'SetTerminateWord'")); } var client = SubscriptionClient.Create(TopicName, SubscriptionName); client.OnMessage(ProcessMessage); }
private static void CreateQueue(NamespaceManager namespaceManager) { if (namespaceManager == null) { namespaceManager = NamespaceManager.Create(); } if (namespaceManager.QueueExists(Constants.QueueName)) { return; } Console.WriteLine("\nCreating Queue '{0}'...", Constants.QueueName); namespaceManager.CreateQueue(Constants.QueueName); }
public void CreateQueue(string queueName) { var nsManager = NamespaceManager.Create(); if (!nsManager.QueueExists(queueName)) { nsManager.CreateQueue(queueName); _logger.LogMessage($"Queue {queueName} created"); } else { _logger.LogMessage($"Queue {queueName} already exist"); } }
private void SetUpNecessaryInfrastructure() { var manager = NamespaceManager.Create(); if (manager.QueueExists(ReceiverEndpointName)) { manager.DeleteQueue(ReceiverEndpointName); } var queueDescription = new QueueDescription(ReceiverEndpointName) { LockDuration = TimeSpan.FromSeconds(10) }; var queue = manager.CreateQueue(queueDescription); }
private void CreateQueueIfNotExists() { NamespaceManager namespaceManager = NamespaceManager.Create(); Logger.Current.Informational("Check if queue exists '" + queueName + "'."); if (!namespaceManager.QueueExists(queueName)) { Logger.Current.Informational("Queue does not exist, creating the queue '" + queueName + "'."); QueueDescription queueDescription = new QueueDescription(queueName); queueDescription.LockDuration = new TimeSpan(0, 5, 0); queueDescription = namespaceManager.CreateQueue(queueDescription); Logger.Current.Informational("Queue created successfully. '" + queueName + "'."); } }
public void Init() { NamespaceManager namespaceManager = NamespaceManager.Create(); var queueName = "testqueue"; if (namespaceManager.QueueExists(queueName)) { namespaceManager.DeleteQueue(queueName); } _server = new QueueServer(queueName); namespaceManager.CreateQueue(new QueueDescription(queueName) { EnablePartitioning = false }); _client = QueueClient.Create(queueName, ReceiveMode.ReceiveAndDelete); }
private static void CreateTopic() { NamespaceManager namespaceManager = NamespaceManager.Create(); Console.WriteLine("\nCreating Topic '{0}'...", TopicName); // Delete if exists if (namespaceManager.TopicExists(TopicName)) { namespaceManager.DeleteTopic(TopicName); } var topicDesc = namespaceManager.CreateTopic(TopicName); namespaceManager.CreateSubscription(topicDesc.Path, SubscriptionName1); namespaceManager.CreateSubscription(topicDesc.Path, SubscriptionName2); }
private void SetUpNecessaryInfrastructure() { var manager = NamespaceManager.Create(); if (manager.QueueExists(SenderEndpointName)) { manager.DeleteQueue(SenderEndpointName); } manager.CreateQueue(SenderEndpointName); if (manager.QueueExists(ReceiverEndpointName)) { manager.DeleteQueue(ReceiverEndpointName); } manager.CreateQueue(ReceiverEndpointName); }
protected override void Load(ContainerBuilder builder) { builder.RegisterAssemblyTypes(System.Reflection.Assembly.GetAssembly(typeof(IServiceBus))) .AsImplementedInterfaces() .SingleInstance(); builder.Register(x => NamespaceManager.Create()) .AsSelf() .SingleInstance(); //TODO support settings on the factory, and possible multiple factories //var m1 = MessagingFactory.Create(); //var settings = m1.GetSettings(); //settings.NetMessagingTransportSettings.BatchFlushInterval = TimeSpan.FromMilliseconds(50); builder.Register(x => MessagingFactory.Create()) .AsSelf() .SingleInstance(); }
private static void CreateQueue() { NamespaceManager namespaceManager = NamespaceManager.Create(); Console.WriteLine("\nCreating Queue '{0}'...", QueueName); // Delete if exists if (namespaceManager.QueueExists(QueueName)) { namespaceManager.DeleteQueue(QueueName); } var description = new QueueDescription(QueueName) { RequiresSession = true }; namespaceManager.CreateQueue(description); }
private static void ReceiveMessagesByIMessageSessionHandler() { Console.WriteLine("\nReceiving message from Queue..."); queueClient.RegisterSessionHandler(typeof(MyMessageSessionHandler), new SessionHandlerOptions { AutoComplete = false }); NamespaceManager namespaceManager = NamespaceManager.Create(); var queue = namespaceManager.GetQueue(QueueName); while (queue.MessageCount > 0) { Thread.CurrentThread.Join(100); queue = namespaceManager.GetQueue(QueueName); } queueClient.Close(); }
public NotificationTopic(string topicName) { //TODO: Add security _namespaceManager = NamespaceManager.Create(); _messagingFactory = MessagingFactory.Create(); try { // doesn't always work, so wrap it if (!_namespaceManager.TopicExists(topicName)) { _namespaceManager.CreateTopic(topicName); } } catch (MessagingEntityAlreadyExistsException) { // ignore, timing issues could cause this } _topicClient = _messagingFactory.CreateTopicClient(topicName); }
public void Start() { var nsManager = NamespaceManager.Create(); if (!nsManager.QueueExists(PdfDocQueue)) { nsManager.CreateQueue(PdfDocQueue); } if (!nsManager.QueueExists(ClientSettingsQueue)) { nsManager.CreateQueue(ClientSettingsQueue); } if (!nsManager.TopicExists(ClientSettingstopic)) { nsManager.CreateTopic(ClientSettingstopic); } PopulateListFileSystemWatchers(); StartFileSystemWatcher(); StartListeningForSettingsUpdate(); StartSendingStatuses(); }
public async Task DeleteSubscriptionAsync(string topicName, string subscriptionName) { try { _logger.WriteInfo(new LogMessage("Deleting subscription..."), LogCategories); NamespaceManager manager = NamespaceManager.Create(); if (string.IsNullOrEmpty(subscriptionName)) { _logger.WriteWarning(new LogMessage("Cannot delete a subscription without specify subscription name"), LogCategories); return; } _logger.WriteInfo(new LogMessage($"Delete subscription name {subscriptionName}"), LogCategories); await manager.DeleteSubscriptionAsync(topicName, subscriptionName); } catch (Exception ex) { _logger.WriteError(ex, LogCategories); throw ex; } }
private void InitializeServiceBus() { var docQueueName = ConfigurationManager.AppSettings["queue"]; var centralManagementQueue = ConfigurationManager.AppSettings["centralQueue"]; var docTopic = ConfigurationManager.AppSettings["topic"]; var nsp = NamespaceManager.Create(); if (!nsp.QueueExists(docQueueName)) { nsp.CreateQueue(docQueueName); } if (!nsp.TopicExists(docTopic)) { nsp.CreateTopic(docTopic); } if (!nsp.QueueExists(centralManagementQueue)) { nsp.QueueExists(centralManagementQueue); } }
static void Main() { AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; //TODO: Add security var namespaceManager = NamespaceManager.Create(); var messagingFactory = MessagingFactory.Create(); //Only uncomment below if you want to delete the subcription and start over //namespaceManager.DeleteSubscription(TopicName,SubscriptionName); try { if (!namespaceManager.SubscriptionExists(TopicName, SubscriptionName)) { //Create a new filter var filter = new SqlFilter(string.Format("{0} = '{1}'", "Type", NotificationMessageType.Important)); //Create the subscription (including the filter) namespaceManager.CreateSubscription(TopicName, SubscriptionName, filter); } } catch (MessagingEntityAlreadyExistsException) { throw new InvalidOperationException(string.Format("Subscription named {0} already exists for topic {1}. Please change the subscription name and try again.", SubscriptionName, TopicName)); } var subscriptionClient = messagingFactory.CreateSubscriptionClient(TopicName, SubscriptionName, ReceiveMode.PeekLock); _notifier = new NotificationTopic(TopicName); _notifier.StartReceiving(NotificationReceived, subscriptionClient); while (true) { Thread.Sleep(10000); } }
public AzureQueueClient(string clientUniqueName) { NamespaceManager namespaceManager = NamespaceManager.Create(); var topicName = ClientConstants.SettingTopicName; try { if (namespaceManager.TopicExists(topicName)) { if (namespaceManager.SubscriptionExists(topicName, clientUniqueName)) { namespaceManager.DeleteSubscription(topicName, clientUniqueName); } namespaceManager.CreateSubscription(topicName, clientUniqueName); } } catch (Exception e) { // ignored } _subscibtionClient = SubscriptionClient.Create(topicName, clientUniqueName, ReceiveMode.ReceiveAndDelete); }
private void SetUpNecessaryInfrastructure() { var manager = NamespaceManager.Create(); if (manager.QueueExists(PublisherEndpointName)) { manager.DeleteQueue(PublisherEndpointName); } manager.CreateQueue(PublisherEndpointName); if (manager.QueueExists(SubscriberEndpointName)) { manager.DeleteQueue(SubscriberEndpointName); } manager.CreateQueue(SubscriberEndpointName); if (manager.TopicExists(EventTopic)) { manager.DeleteTopic(EventTopic); } manager.CreateTopic(EventTopic); if (manager.SubscriptionExists(EventTopic, SubscriptionName)) { manager.DeleteSubscription(EventTopic, SubscriptionName); } manager.CreateSubscription(new SubscriptionDescription( EventTopic, SubscriptionName) { ForwardTo = SubscriberEndpointName }); }
private void SetupQueues() { var nsManager = NamespaceManager.Create(); if (!nsManager.QueueExists(PdfDocQueue)) { nsManager.CreateQueue(PdfDocQueue); } if (!nsManager.QueueExists(ClientSettingsQueue)) { nsManager.CreateQueue(ClientSettingsQueue); } if (!nsManager.TopicExists(ClientSettingstopic)) { nsManager.CreateTopic(ClientSettingstopic); } var subscription = new SubscriptionDescription(ClientSettingstopic, ClientSettingsSubs); if (!nsManager.SubscriptionExists(ClientSettingstopic, ClientSettingsSubs)) { nsManager.CreateSubscription(subscription); } }
public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses) { var messageFactory = MessagingFactory.Create(); var namespaceManager = NamespaceManager.Create(); const string topicName = "WASPublisherServiceDemoTopic"; const string subscriptionName = "Subscription1"; if (!namespaceManager.TopicExists(topicName)) { namespaceManager.CreateTopic(topicName); } if (!namespaceManager.SubscriptionExists(topicName, subscriptionName)) { namespaceManager.CreateSubscription(topicName, subscriptionName); } var subscriptionClient = messageFactory.CreateSubscriptionClient(topicName, subscriptionName, ReceiveMode.PeekLock); subscriptionClient.BeginReceive(subscriptionClient_EndReceive, subscriptionClient); return(new ServiceHost(typeof(NullService.NullService), baseAddresses)); }
public Manager() { Client = NamespaceManager.Create(); Address = Client.Address; }
private void CreateTopicIfNotExists() { NamespaceManager namespaceManager = NamespaceManager.Create(); Logger.Current.Informational("Check if topic exists '" + topicName + "'."); if (!namespaceManager.TopicExists(topicName)) { Logger.Current.Informational("Topic does not exist, creating the topic '" + topicName + "'."); TopicDescription topicDescription = new TopicDescription(topicName) { RequiresDuplicateDetection = true }; topicDescription = namespaceManager.CreateTopic(topicDescription); Logger.Current.Informational("Topic created successfully. '" + topicName + "'."); } if (!namespaceManager.SubscriptionExists(topicName, leadScoreSubscriptionName)) { string conditionType = "LeadScoreConditionType != "; StringBuilder filter = new StringBuilder(conditionType).Append((byte)LeadScoreConditionType.ContactTagAdded); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.ContactMatchesSavedSearch); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.WorkflowActivated); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.OpportunityStatusChanged); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.ContactWaitPeriodEnded); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.WorkflowInactive); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.WorkflowPaused); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.UnsubscribeEmails); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.ContactLifecycleChange); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.CampaignSent); SqlFilter leadScoreFilter = new SqlFilter(filter.ToString()); SubscriptionDescription leadScoreSubDesc = new SubscriptionDescription(topicName, leadScoreSubscriptionName); leadScoreSubDesc.LockDuration = new TimeSpan(0, 3, 0); leadScoreSubDesc = namespaceManager.CreateSubscription(leadScoreSubDesc, leadScoreFilter); leadScoreSubDesc.EnableDeadLetteringOnMessageExpiration = false; namespaceManager.UpdateSubscription(leadScoreSubDesc); Logger.Current.Informational("Subscription created successfully. '" + leadScoreSubscriptionName + "'."); } if (!namespaceManager.SubscriptionExists(topicName, automationSubscriptionName)) { string conditionType = "LeadScoreConditionType != "; StringBuilder filter = new StringBuilder(conditionType).Append((byte)LeadScoreConditionType.ContactOpensEmail); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.ContactVisitsWebsite); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.ContactVisitsWebPage); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.PageDuration); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.ContactActionTagAdded); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.ContactNoteTagAdded); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.ContactLeadSource); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.ContactTourType); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.ContactTagRemoved); filter.Append(" AND ").Append(conditionType).Append((byte)LeadScoreConditionType.UnsubscribeEmails); SqlFilter automationMessageFilter = new SqlFilter(filter.ToString()); SubscriptionDescription automationSubDesc = new SubscriptionDescription(topicName, automationSubscriptionName); automationSubDesc.LockDuration = new TimeSpan(0, 3, 0); automationSubDesc = namespaceManager.CreateSubscription(automationSubDesc, automationMessageFilter); automationSubDesc.EnableDeadLetteringOnMessageExpiration = false; namespaceManager.UpdateSubscription(automationSubDesc); Logger.Current.Informational("Subscription created successfully. '" + automationSubscriptionName + "'."); } }
private static void Main(string[] args) { var namespaceManager = NamespaceManager.Create(); var messageFactory = MessagingFactory.Create(); var queueName = "ServiceBusTest"; if (!namespaceManager.QueueExists(queueName)) { var queueDescription = new QueueDescription(queueName) { EnableDeadLetteringOnMessageExpiration = true, RequiresSession = false }; namespaceManager.CreateQueue(queueDescription); //namespaceManager.DeleteQueue(queueName); } var queueClient = messageFactory.CreateQueueClient(queueName); var toSendMessages = new List <BrokeredMessage>(); for (var i = 0; i < 10; i++) { toSendMessages.Add(new BrokeredMessage(new Payload { Id = i, Time = DateTime.Now })); } queueClient.SendBatch(toSendMessages); IEnumerable <BrokeredMessage> brokeredMessages = null; long sequenceNumber = 0; var needPeek = true; Task.Run(() => { while (needPeek && (brokeredMessages = queueClient.PeekBatch(sequenceNumber, 5)) != null && brokeredMessages.Count() > 0) { foreach (var message in brokeredMessages) { try { if (message.State != MessageState.Deferred) { needPeek = false; break; } Messages.Add(message); sequenceNumber = message.SequenceNumber + 1; } catch (Exception ex) { Console.WriteLine(ex.GetBaseException().Message); } } } while ((brokeredMessages = queueClient.ReceiveBatch(2, new TimeSpan(0, 0, 5))) != null && brokeredMessages.Count() > 0) { foreach (var message in brokeredMessages) { try { message.Defer(); Messages.Add(message); sequenceNumber = message.SequenceNumber + 1; } catch (Exception ex) { Console.WriteLine(ex.GetBaseException().Message); } } } }); Task.Run(() => { while (true) { var message = Messages.Take(); try { var payload = message.GetBody <Payload>(); var toCompleteMessage = queueClient.Receive(message.SequenceNumber); toCompleteMessage.Complete(); } catch (Exception ex) { Console.WriteLine(ex.GetBaseException().Message); } } }); Console.ReadLine(); }
public void DeleteSubscription(string name) { var manager = NamespaceManager.Create(); manager.DeleteSubscription(TOPIC_NAME, name); }
static void Main() { const string queueName = "ServiceBusSecurityQueueSample"; //Create a NamespaceManager instance (for management operations) // NOTE: Namespace-level security is handled via PowerShell configuration on the namespace itself var namespaceManager = NamespaceManager.Create(); // Example of granting a domain user listen permissions to a queue var queue = new QueueDescription(queueName); const string issuer = "ServiceBusDefaultNamespace"; var domainUser = string.Format(@"{0}@{1}", "REPLACE WITH USERNAME", Environment.GetEnvironmentVariable("USERDNSDOMAIN")); var accessRights = new List <AccessRights> { AccessRights.Listen }; AuthorizationRule listenRule = new AllowRule(issuer, "nameidentifier", domainUser, accessRights); queue.Authorization.Add(listenRule); if (namespaceManager.QueueExists(queueName)) { namespaceManager.DeleteQueue(queueName); } queue = namespaceManager.CreateQueue(queue); //List out the access rules for the queue ListAccessRules(queue); //Create a MessagingFactory instance (for sending and receiving messages) const string hostname = "REPLACE WITH FULLY-QUALIFIED SERVER NAME"; const string sbNamespace = "ServiceBusDefaultNamespace"; var stsUris = new List <Uri> { new Uri(string.Format(@"sb://{0}:9355/", hostname)) }; var tokenProvider = TokenProvider.CreateWindowsTokenProvider(stsUris); var runtimeAddress = string.Format("sb://{0}:9354/{1}/", hostname, sbNamespace); //var messageFactory = MessagingFactory.Create(runtimeAddress, // new MessagingFactorySettings() { TokenProvider = tokenProvider, // OperationTimeout = TimeSpan.FromMinutes(30) }); var messageFactory = MessagingFactory.Create(runtimeAddress, tokenProvider); //Create a queue client to send and receive messages to and from the queue var myQueueClient = messageFactory.CreateQueueClient(queueName); //Create a simple brokered message and send it to the queue var sendMessage = new BrokeredMessage("Hello World!"); myQueueClient.Send(sendMessage); Console.WriteLine("Message sent: Body = {0}", sendMessage.GetBody <string>()); //Receive the message from the queue var receivedMessage = myQueueClient.Receive(TimeSpan.FromSeconds(5)); if (receivedMessage != null) { Console.WriteLine("Message received: Body = {0}", receivedMessage.GetBody <string>()); receivedMessage.Complete(); } //Close the connection to the Service Bus messageFactory.Close(); Console.WriteLine("Press Enter to close."); Console.ReadLine(); }
static void Main() { const string queueName = "QueueDeadLetterDemo"; //Create a NamespaceManager instance (for management operations) var namespaceManager = NamespaceManager.Create(); var queue = new QueueDescription(queueName) { //Make sure expired messages go to the dead letter queue EnableDeadLetteringOnMessageExpiration = true, //Set the expiration to 1 second so all messages expire quickly (1 second is the minimum for this) //DefaultMessageTimeToLive = TimeSpan.FromSeconds(1) }; if (namespaceManager.QueueExists(queueName)) { namespaceManager.DeleteQueue(queueName); } queue = namespaceManager.CreateQueue(queue); Console.WriteLine("EnableDeadLetterOnExpiration = {0}", queue.EnableDeadLetteringOnMessageExpiration); //Console.WriteLine("DefaultMessageTimeToLive = {0}", queue.DefaultMessageTimeToLive); //Create a MessagingFactory instance (for sending and receiving messages) var messageFactory = MessagingFactory.Create(); //Create a queue client to send and receive messages to and from the queue var queueClient = messageFactory.CreateQueueClient(queueName, ReceiveMode.ReceiveAndDelete); //Create a simple brokered message and send it to the queue var sendMessage = new BrokeredMessage("Hello World!"); //Set an expiration on the message sendMessage.TimeToLive = TimeSpan.FromSeconds(1); queueClient.Send(sendMessage); Console.WriteLine("Message sent: Body = {0}", sendMessage.GetBody<string>()); Console.WriteLine(); Console.WriteLine("Waiting to begin receiving..."); System.Threading.Thread.Sleep(5000); Console.WriteLine("Receiving..."); //Verify the message did expire //NOTE: Messages are NOT expired/deadlettered until a client attempts to receive messages var receivedMessage = queueClient.Receive(TimeSpan.FromSeconds(5)); if (receivedMessage != null) { Console.WriteLine("Queue message received: Body = {0}", receivedMessage.GetBody<string>()); receivedMessage.Complete(); } else { Console.WriteLine("No queue message received."); } //Create a queue client for the dead letter queue string deadLetterQueuePath = QueueClient.FormatDeadLetterPath(queueName); var deadletterQueueClient = messageFactory.CreateQueueClient(deadLetterQueuePath); //Receive the message from the dead letter queue BrokeredMessage deadLetterMessage = null; while (deadLetterMessage == null) { deadLetterMessage = deadletterQueueClient.Receive(TimeSpan.FromSeconds(5)); if (deadLetterMessage != null) { Console.WriteLine("Dead letter message received: Body = {0}", deadLetterMessage.GetBody<string>()); deadLetterMessage.Complete(); } else { Console.WriteLine("No message received yet... waiting..."); System.Threading.Thread.Sleep(2000); Console.WriteLine("Trying again..."); } } //Close the connection to the Service Bus messageFactory.Close(); Console.WriteLine("Press Enter to close."); Console.ReadLine(); }