private SubscriptionMesssage GetSubscriptions() { SubscriptionMesssage subscription = new SubscriptionMesssage(); System.Data.DataSet ds = SqlHelper.ExecuteDataset(_connectionString, "ASBMessaging_Subscriptions_Get_Details"); if (ds != null && ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { DataRow dr = ds.Tables[0].Rows[0]; subscription.Id = dr.Field <int>("ID"); subscription.TopicName = dr["TopicName"].ToString(); subscription.SubscriptionName = dr["SubscriptionName"].ToString(); subscription.Description = dr["Description"].ToString(); subscription.TypeOfTopic = dr["Description"].ToString(); subscription.PrimaryKey = dr["PrimaryKey"].ToString(); subscription.PrimaryConnectionString = dr["PrimaryConnectionString"].ToString(); subscription.SecondaryKey = dr["SecondaryKey"].ToString(); subscription.SecondaryConnectionString = dr["SecondaryConnectionString"].ToString(); subscription.IsEnabled = dr.Field <bool?>("IsEnabled"); subscription.CreatedDate = dr.Field <DateTime?>("CreatedDate"); } } return(subscription); }
public async Task Subscribe() { try { _subscriptionMesssage = GetSubscriptions(); if (_subscriptionMesssage != null) { _subscriptionClient = new SubscriptionClient(_subscriptionMesssage.PrimaryConnectionString , _subscriptionMesssage.TopicName, _subscriptionMesssage.SubscriptionName); // Console.WriteLine("======================================================"); // Console.WriteLine("Press ENTER key to exit after receiving all the messages."); // Console.WriteLine("======================================================"); // Register subscription message handler and receive messages in a loop RegisterOnMessageHandlerAndReceiveMessages(); } } catch (Exception ex) { _logger.LogError("Error - Subscription {Details}", ex); } finally { Console.ReadKey(); await _subscriptionClient.CloseAsync(); } }