Ejemplo n.º 1
0
        public override Task <ListTopicSubscriptionsResponse> ListTopicSubscriptions(Empty request, ServerCallContext context)
        {
            var result = new ListTopicSubscriptionsResponse();

            result.Subscriptions.Add(new TopicSubscription()
            {
                PubsubName = "pubsub",
                Topic      = "exampletopic"
            });
            return(Task.FromResult(result));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// implement ListTopicSubscriptions to register deposit and withdraw subscriber
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Task <ListTopicSubscriptionsResponse> ListTopicSubscriptions(Empty request, ServerCallContext context)
        {
            var result = new ListTopicSubscriptionsResponse();

            //result.Subscriptions.Add(new TopicSubscription
            //{
            //    PubsubName = "pubsub",
            //    Topic = "orders"
            //});
            //result.Subscriptions.Add(new TopicSubscription
            //{
            //    PubsubName = "pubsub",
            //    Topic = "withdraw"
            //});

            return(Task.FromResult(result));
        }
Ejemplo n.º 3
0
        // FYI Here where ServiceB tells Dapr which Pubsub subscriptions it can handle.
        public override Task <ListTopicSubscriptionsResponse> ListTopicSubscriptions(Empty request, ServerCallContext context)
        {
            var result = new ListTopicSubscriptionsResponse();

            try
            {
                TopicSubscription subscr;

                subscr = new TopicSubscription
                {
                    PubsubName = NamesOfQueuesNPubSubs.PubSubAzServiceBusComponent,
                    Topic      = NamesOfQueuesNPubSubs.ServiceADemoEvent1Topic
                };
                result.Subscriptions.Add(subscr);
                // For display in a running demo.
                Console.WriteLine($" ** ServiceB: Subscribed to Topic={subscr.Topic} for PubsubName={subscr.PubsubName}");


                // For Dapr default Redis pubsub component.  Also needs event processing code in OnTopicEvent() below.
                subscr = new TopicSubscription()
                {
                    PubsubName = NamesOfQueuesNPubSubs.PubSubDefaultDaprComponent,
                    Topic      = NamesOfQueuesNPubSubs.ServiceADemoEvent1Topic
                };
                result.Subscriptions.Add(subscr);
                // For display in a running demo.
                Console.WriteLine($" ** ServiceB: Subscribed to Topic={subscr.Topic} for PubsubName={subscr.PubsubName}");
            }
            catch (Exception ex)
            {
                m_Logger.LogError($"** ServiceB.ListTopicSubscriptions() threw exception ex={ex}");
                throw;
            }

            // TODO If required, add subscription for NamesOfQueuesNPubSubs.ServiceADemoEvents2Topic

            return(Task.FromResult(result));
        }
Ejemplo n.º 4
0
        protected override void ProcessRecord()
        {
            if (Subscription != null)
            {
                Subscription = Subscription.Select(item => GetProjectPrefixForSubscription(item, Project)).ToArray();
            }

            // Handles the case where user wants to list all subscriptions in a particular topic.
            // In this case, we will have to make a call to get the name of all the subscriptions in that topic
            // before calling get request on each subscription.
            if (Topic != null)
            {
                Topic = GetProjectPrefixForTopic(Topic, Project);
                ProjectsResource.TopicsResource.SubscriptionsResource.ListRequest listRequest =
                    Service.Projects.Topics.Subscriptions.List(Topic);
                do
                {
                    ListTopicSubscriptionsResponse response = null;
                    try
                    {
                        response = listRequest.Execute();
                    }
                    catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound)
                    {
                        WriteResourceMissingError(
                            exceptionMessage: $"Topic '{Topic}' does not exist in project '{Project}'.",
                            errorId: "TopicNotFound",
                            targetObject: Topic);
                    }

                    if (response?.Subscriptions != null)
                    {
                        // If user gives us a list of subscriptions to search for, we have to make sure that
                        // those subscriptions belong to the topic.
                        if (Subscription != null)
                        {
                            IEnumerable <string> selectedSubscriptions = response.Subscriptions
                                                                         .Where(sub => Subscription.Contains(sub, System.StringComparer.OrdinalIgnoreCase));
                            GetSubscriptions(selectedSubscriptions);
                        }
                        else
                        {
                            GetSubscriptions(response.Subscriptions);
                        }
                    }
                    listRequest.PageToken = response.NextPageToken;
                }while (!Stopping && listRequest.PageToken != null);
                return;
            }

            // If no topic is given, then we are left with 2 cases:
            // 1. User gives us a list of subscriptions: we just find those subscriptions and returned.
            // 2. User does not give us any subscriptions: we just return all subscriptions in the project.
            if (Subscription != null && Subscription.Length > 0)
            {
                GetSubscriptions(Subscription.Select(item => GetProjectPrefixForSubscription(item, Project)));
            }
            else
            {
                ProjectsResource.SubscriptionsResource.ListRequest listRequest =
                    Service.Projects.Subscriptions.List($"projects/{Project}");
                do
                {
                    ListSubscriptionsResponse response = listRequest.Execute();

                    if (response.Subscriptions != null)
                    {
                        WriteObject(response.Subscriptions, true);
                    }
                    listRequest.PageToken = response.NextPageToken;
                }while (!Stopping && listRequest.PageToken != null);
            }
        }