Exemple #1
0
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            // need to call base run async to prepare for the state or else actor state will throw errors ReminderLoadInProgressException
            await base.RunAsync(cancellationToken);

            var config = ServiceConfig.GetConfigSection(SectionKeyName);

            //read the blob and init scheduler actor

            if (ConfigMode == ConfigMode.BlobConfig)
            {
                var configList = await BlobStorageConfiguration.GetConfigsFromBlobFile <ServiceBusOption>(
                    config[CONNECTION_STRING_KEY],
                    config[CONTAINER_NAME_KEY],
                    config[FILE_NAME_KEY],
                    $"{SectionKeyName}");

                foreach (var option in configList)
                {
                    Logger.LogInformation($"[{SectionKeyName}] Initialize Listener Actor", option);
                    await InitScalingListenersAsync(option, cancellationToken);
                }
            }
            else if (ConfigMode == ConfigMode.ServiceFabricConfig)
            {
                var serviceBusOption = new ServiceBusOption()
                {
                    ConnectionString           = config[CONNECTION_STRING_KEY],
                    ClientMode                 = ClientMode.Receiving,
                    SubscriptionRequireSession = false,
                    SubscriptionName           = $"{SectionKeyName}_sub_no_sessionId"
                };
                await InitScalingListenersAsync(serviceBusOption, cancellationToken);
            }
        }
        protected override void Load(ContainerBuilder builder)
        {
            Guard.Against.Null(ServiceBusConnectionStrings, nameof(ServiceBusConnectionStrings));
            foreach (var connString in ServiceBusConnectionStrings)
            {
                Guard.Against.NullOrEmpty(connString.Value, nameof(connString));
                var serviceBusOption = new ServiceBusOption()
                {
                    ConnectionString = connString.Value,
                    ClientMode       = ClientMode.Sending,
                    IsCompressed     = isCompressed
                };

                if (ServiceBusConnectionStrings.Count == 1)
                {
                    builder.Register(c =>
                    {
                        var serviceBusConnection          = new ServiceBusConnectionStringBuilder(connString.Value);
                        var serviceBusPersisterConnection = new DefaultServiceBusPersisterConnection(serviceBusConnection);
                        return(new EventBusServiceBus(serviceBusPersisterConnection, serviceBusOption));
                    }).As <IEventBus>().SingleInstance();
                }
                else
                {
                    builder.Register(c =>
                    {
                        var serviceBusConnection          = new ServiceBusConnectionStringBuilder(connString.Value);
                        var serviceBusPersisterConnection = new DefaultServiceBusPersisterConnection(serviceBusConnection);
                        return(new EventBusServiceBus(serviceBusPersisterConnection, serviceBusOption));
                    }).Keyed <IEventBus>(connString.Key).SingleInstance();
                }
            }
        }
Exemple #3
0
 public ReceiverBus(
     IProductService product,
     IAreaService area,
     ITopicBus topicBus,
     IOptions <ServiceBusOption> option)
 {
     _product  = product;
     _area     = area;
     _option   = option.Value;
     _topicBus = topicBus;
     _rule     = new RuleDescription
     {
         Filter = new CorrelationFilter {
             Label = _option.ServiceBus.Store
         },
         Name = "filter-store"
     };
 }
Exemple #4
0
        protected virtual async Task InitEventBusClient(ServiceBusOption serviceBusOption)
        {
            try
            {
                //retrieve from servicebus option
                var serviceBusConnection          = new ServiceBusConnectionStringBuilder(serviceBusOption.ConnectionString);
                var serviceBusPersisterConnection = new DefaultServiceBusPersisterConnection(serviceBusConnection);
                var eventBusSubcriptionsManager   = new InMemoryEventBusSubscriptionsManager();

                //resolve if needed using the scope
                //careful consider create child scope instead of passing container
                EventBus = new EventBusServiceBus(serviceBusPersisterConnection, eventBusSubcriptionsManager, serviceBusOption.SubscriptionName, CoreDependencyResolver.Container, serviceBusOption, CoreDependencyResolver.Container.Resolve <ILoggerFactory>());
                await((EventBusServiceBus)EventBus).InitializeAsync(serviceBusPersisterConnection, eventBusSubcriptionsManager,
                                                                    serviceBusOption.SubscriptionName, RetryPolicy.Default);
                await Subscribe();
            }
            catch (Exception ex)
            {
                Logger.LogError($"{CurrentActor} failed to init service bus client with provided service bus option subscriptionName = {serviceBusOption.SubscriptionName}", ex);
                throw;
            }
        }
Exemple #5
0
        protected Task InitScalingListenersAsync(ServiceBusOption sbConfig, CancellationToken cancellationToken)
        {
            try
            {
                cancellationToken.ThrowIfCancellationRequested();
                var data = MessagePackSerializer.Serialize(sbConfig);

                var proxy = ActorProxy.Create <IBaseMessagingActor>(new ActorId(ActorIdRetriever.Invoke(sbConfig)),
                                                                    new Uri(
                                                                        $"{Context.CodePackageActivationContext.ApplicationName}/{ListenerActorServiceUri.Invoke()}"));

                var actionName = ActionName ?? nameof(IDefaultServiceBusListenerAction);

                proxy.ChainProcessMessageAsync(new ActorRequestContext(SectionKeyName, actionName, Guid.NewGuid().ToString()), data, cancellationToken).GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                //failed to call scheduler actor
                Logger.LogError(e, $"[{SectionKeyName}] Failed to init the listener actor: " + e.Message, sbConfig);
            }
            return(Task.CompletedTask);
        }
Exemple #6
0
 public TopicBus(IOptions <ServiceBusOption> option)
 {
     _option = option.Value;
 }
Exemple #7
0
        protected async Task ChainCreateEventBusListenersAsync(ServiceBusOption serviceBusOption)
        {
            await StateManager.AddOrUpdateStateAsync(BASE_EB_STATE_NAME, serviceBusOption, (key, value) => serviceBusOption);

            await InitEventBusClient(serviceBusOption);
        }
Exemple #8
0
 public QueueBus(ServiceBusOption option)
 {
     _option = option;
 }