示例#1
0
        private async Task UnsubscribeAsync(string messageTypeName)
        {
            var brokerServiceName = await _brokerServiceLocator.LocateAsync();

            var brokerService = await ServiceFabric.PubSubActors.PublisherActors.PublisherActorExtensions.GetBrokerServiceForMessageAsync(messageTypeName, brokerServiceName);

            var serviceReference = SubscriberServiceExtensions.CreateServiceReference(Context, Partition.PartitionInfo);
            await brokerService.UnregisterServiceSubscriberAsync(serviceReference, messageTypeName, false);

            ServiceEventSource.Current.ServiceMessage(this, $"Unsubscribing from Message Type {messageTypeName}.");
        }
        private async Task SubscribeAsync(string messageTypeName, bool useConcurrentBroker)
        {
            var builder = new UriBuilder(Context.CodePackageActivationContext.ApplicationName);

            if (useConcurrentBroker)
            {
                builder.Path += "/ConcurrentBrokerService";
            }
            else
            {
                builder.Path += "/BrokerService";
            }
            var brokerSvcLocation = builder.Uri;

            ServiceEventSource.Current.ServiceMessage(this, $"Using Broker Service at '{brokerSvcLocation}'.");

            var brokerService = await ServiceFabric.PubSubActors.PublisherActors.PublisherActorExtensions.GetBrokerServiceForMessageAsync(messageTypeName, brokerSvcLocation);

            var serviceReference = SubscriberServiceExtensions.CreateServiceReference(Context, Partition.PartitionInfo);
            await brokerService.RegisterServiceSubscriberAsync(serviceReference, messageTypeName);

            ServiceEventSource.Current.ServiceMessage(this, $"Subscribing to Message Type {messageTypeName}.");
        }