Beispiel #1
0
        public static void Run()
        {
            try
            {
                InitializeCache();

                IDurableTopicSubscription electronicsSharedSubs = RunSubscriber("ElectronicsOrders", "ElectronicsSubscription", SubscriptionPolicy.Shared);
                IDurableTopicSubscription garmentsExclusiveSubs = RunSubscriber("GarmentsOrders", "GarmentsSubscription", SubscriptionPolicy.Exclusive);

                //Following patterns can be used;
                //* -	 represents zero or more characters. For example, ‘bl*’ finds TOPICs ‘black’, ‘blue’, and ‘blob’ etc.
                //? -	 represents one character. For example, ‘h?t’ finds ‘hot’, ‘hat’, and ‘hit’ etc.
                //[]-	 represents any single character within the brackets. For example, ‘h[oa]t’ finds hot and hat, but not hit.

                IDurableTopicSubscription allOrdersSubscription = RunPatternBasedSubscriber("*Orders", "AllOrdersSubscription");

                Console.WriteLine("Press any key to stop all subscribers...");
                Console.ReadLine();
                electronicsSharedSubs.UnSubscribe();
                garmentsExclusiveSubs.UnSubscribe();
                allOrdersSubscription.UnSubscribe();
            }
            catch (CacheException ex)
            {
                if (ex.ErrorCode == NCacheErrorCodes.SUBSCRIPTION_EXISTS)
                {
                    Console.WriteLine("Active Subscription with this name already exists");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        private void DoInternalSubscription(string eventName)
        {
            var containsKey = _subsManager.HasSubscriptionsForEvent(eventName);

            if (!containsKey)
            {
                if (_subscription == null)
                {
                    var topic = _persistantConnection.CreateModel();

                    if (topic == null)
                    {
                        _logger.LogError($"Unable to subscribe to event {eventName} due to topic creation issues");
                        return;
                    }

                    _subscription = topic.CreateDurableSubscription(
                        _subscriptionName,
                        SubscriptionPolicy.Shared,
                        (o, args) =>
                    {
                        var payLoad    = args.Message.Payload as Tuple <string, string>;
                        var eventName1 = payLoad.Item1;
                        var message    = payLoad.Item2;

                        ProcessEvent(eventName1, message).Wait();
                    });
                }
            }
        }
Beispiel #3
0
 private void CreateRelevantSubscribtion()
 {
     try
     {
         MessageReceivedCallback transactonmessageReceivedCallback = new TransactionCompletedMessage(this).MessageReceivedCallback;
         transactionSubscription = CreateRelevantSubscribtions(Topics.REPLIESTOPICS, transactonmessageReceivedCallback);
     }
     catch
     {
         throw;
     }
 }
 private void CreateRelevantSubscribtion()
 {
     try
     {
         // initializes the relevant subscribers with their call backs
         MessageReceivedCallback fraudManagermessageReceivedCallback = new TransactionStartedMessage(this).MessageReceivedCallback;
         _subscriptions = CreateRelevantSubscribtions(Topics.TRANSACTIONTOPICS, fraudManagermessageReceivedCallback);
     }
     catch
     {
         throw;
     }
 }