public static async Task <IDictionary <ActorId, TResult> > GetFromAllActors <TActorType, TResult>(IPartitionEnumerationManager partitionEnumerationManager, IActorProxyFactory actorProxyFactory, Uri serviceUri, Func <TActorType, Task <KeyValuePair <ActorId, TResult> > > onEachActor, CancellationToken cancellationToken = default(CancellationToken)) where TActorType : IActor { var servicePartitionKeysAsync = await ServiceContextExtensions.GetServicePartitionKeysAsync(partitionEnumerationManager, serviceUri); var activeActors = new List <ActorInformation>(); foreach (var partitionInformation in servicePartitionKeysAsync) { var actorServiceProxy = actorProxyFactory.CreateActorServiceProxy <IActorService>(serviceUri, partitionInformation.LowKey); ContinuationToken continuationToken = null; do { var page = await actorServiceProxy.GetActorsAsync(continuationToken, cancellationToken); activeActors.AddRange(page.Items); continuationToken = page.ContinuationToken; } while (continuationToken != null); } var tasks = activeActors.Select(activeActor => actorProxyFactory.CreateActorProxy <TActorType>(activeActor.ActorId)).Select(onEachActor).ToList(); return((await Task.WhenAll(tasks)).ToDictionary(task => task.Key, task => task.Value)); }
public async Task Handle(ProcessLevyPaymentsOnMonthEndCommand command, IMessageHandlerContext context) { paymentLogger.LogInfo($"Processing ProcessLevyPaymentsOnMonthEndCommand. Message Id : {context.MessageId}, Job: {command.JobId}"); using (var operation = telemetry.StartOperation("LevyFundedProxyService.ProcessLevyPaymentsOnMonthEndCommand", command.CommandId.ToString())) { var stopwatch = Stopwatch.StartNew(); var actorId = new ActorId(command.AccountId.ToString()); var actor = proxyFactory.CreateActorProxy <ILevyFundedService>(new Uri("fabric:/SFA.DAS.Payments.FundingSource.ServiceFabric/LevyFundedServiceActorService"), actorId); var fundingSourceEvents = await actor.HandleMonthEnd(command).ConfigureAwait(false); foreach (var fundingSourcePaymentEvent in fundingSourceEvents) { if (fundingSourcePaymentEvent is ProcessUnableToFundTransferFundingSourcePayment) { await context.SendLocal(fundingSourcePaymentEvent).ConfigureAwait(false); } else { await context.Publish(fundingSourcePaymentEvent).ConfigureAwait(false); } } telemetry.TrackDurationWithMetrics("LevyFundedProxyService.ProcessLevyPaymentsOnMonthEndCommand", stopwatch, command, command.AccountId, new Dictionary <string, double> { { TelemetryKeys.Count, fundingSourceEvents.Count } }); telemetry.StopOperation(operation); } }
public async Task Handle(T message, IMessageHandlerContext context) { paymentLogger.LogInfo($"Processing RequiredPaymentsProxyService event. Message Id : {context.MessageId}"); executionContext.JobId = message.JobId.ToString(); var contractType = message is PayableEarningEvent ? ContractType.Act1 : message is ApprenticeshipContractType2EarningEvent ? ContractType.Act2 : (message as IFunctionalSkillEarningEvent)?.ContractType ?? throw new InvalidOperationException($"Cannot resolve contract type for {typeof(T).FullName}"); var key = apprenticeshipKeyService.GenerateApprenticeshipKey( message.Ukprn, message.Learner.ReferenceNumber, message.LearningAim.FrameworkCode, message.LearningAim.PathwayCode, message.LearningAim.ProgrammeType, message.LearningAim.StandardCode, message.LearningAim.Reference, message.CollectionPeriod.AcademicYear, contractType ); var actorId = new ActorId(key); var actor = proxyFactory.CreateActorProxy <IRequiredPaymentsService>(new Uri("fabric:/SFA.DAS.Payments.RequiredPayments.ServiceFabric/RequiredPaymentsServiceActorService"), actorId); IReadOnlyCollection <PeriodisedRequiredPaymentEvent> requiredPaymentEvent; requiredPaymentEvent = await HandleEarningEvent(message, actor).ConfigureAwait(false); if (requiredPaymentEvent != null) { await Task.WhenAll(requiredPaymentEvent.Select(context.Publish)).ConfigureAwait(false); } paymentLogger.LogInfo($"Successfully processed RequiredPaymentsProxyService event for Actor Id {actorId}"); }
public static T GetClaptrap <T>(this IActorProxyFactory factory, IClaptrapIdentity identity) where T : IActor { var re = factory.CreateActorProxy <T>(new ActorId(identity.Id), identity.TypeCode); return(re); }
public async Task Handle(ApprenticeshipContractType1EarningEvent message, IMessageHandlerContext context) { if (message.Learner == null || message.Learner?.Uln == 0) { throw new InvalidOperationException("Invalid 'ApprenticeshipContractType1EarningEvent' received. Learner was null or Uln was 0."); } var uln = message.Learner.Uln; var learnerRef = message.Learner.ReferenceNumber; logger.LogDebug($"Processing DataLockProxyProxyService event for learner with learner ref {learnerRef}"); var actorId = new ActorId(uln.ToString()); logger.LogVerbose($"Creating actor proxy for learner with learner ref {learnerRef}"); var actor = proxyFactory.CreateActorProxy <IDataLockService>(new Uri("fabric:/SFA.DAS.Payments.DataLocks.ServiceFabric/DataLockServiceActorService"), actorId); logger.LogDebug($"Actor proxy created for learner with " + $"JobId: {message.JobId} and LearnRefNumber: {learnerRef}"); logger.LogVerbose($"Calling actor proxy to handle earning for learner with learner ref {learnerRef}"); var dataLockEvents = await actor.HandleEarning(message, CancellationToken.None).ConfigureAwait(false); logger.LogDebug($"Earning handled for learner with learner ref {learnerRef}"); if (dataLockEvents != null) { var summary = string.Join(", ", dataLockEvents.GroupBy(e => e.GetType().Name).Select(g => $"{g.Key}: {g.Count()}")); logger.LogVerbose($"Publishing data lock event for learner with learner ref {learnerRef}: {summary}"); await Task.WhenAll(dataLockEvents.Select(context.Publish)).ConfigureAwait(false); logger.LogDebug($"Data lock event published for learner with learner ref {learnerRef}"); } logger.LogInfo($"Successfully processed DataLockProxyProxyService event for Actor for learner {learnerRef}"); }
public async Task Handle(IdentifiedRemovedLearningAim message, IMessageHandlerContext context) { logger.LogDebug($"Processing 'IdentifiedRemovedLearningAim' message."); ((ExecutionContext)executionContext).JobId = message.JobId.ToString(); var key = apprenticeshipKeyService.GenerateApprenticeshipKey( message.Ukprn, message.Learner.ReferenceNumber, message.LearningAim.FrameworkCode, message.LearningAim.PathwayCode, message.LearningAim.ProgrammeType, message.LearningAim.StandardCode, message.LearningAim.Reference, message.CollectionPeriod.AcademicYear, message.ContractType); var actorId = new ActorId(key); var actor = proxyFactory.CreateActorProxy <IRequiredPaymentsService>(new Uri("fabric:/SFA.DAS.Payments.RequiredPayments.ServiceFabric/RequiredPaymentsServiceActorService"), actorId); IReadOnlyCollection <PeriodisedRequiredPaymentEvent> requiredPayments = await actor.RefundRemovedLearningAim(message, CancellationToken.None).ConfigureAwait(false); logger.LogDebug($"Got {requiredPayments?.Count ?? 0} required payments."); if (requiredPayments != null) { await Task.WhenAll(requiredPayments.Select(context.Publish)).ConfigureAwait(false); } logger.LogInfo($"Successfully processed IdentifiedRemovedLearningAim event for Actor Id {actorId}"); }
public async Task HandleAsync( OrderStatusChangedToSubmittedIntegrationEvent integrationEvent, [FromServices] IOptions <OrderingSettings> settings, [FromServices] IEmailService emailService) { // Gets the order details from Actor state. var actorId = new ActorId(integrationEvent.OrderId.ToString()); var orderingProcess = _actorProxyFactory.CreateActorProxy <IOrderingProcessActor>( actorId, nameof(OrderingProcessActor)); // var actorOrder = await orderingProcess.GetOrderDetails(); var readModelOrder = new Order(integrationEvent.OrderId, actorOrder); // Add the order to the read model so it can be queried from the API. // It may already exist if this event has been handled before (at-least-once semantics). readModelOrder = await _orderRepository.AddOrGetOrderAsync(readModelOrder); // Send a SignalR notification to the client. await SendNotificationAsync(readModelOrder.OrderNumber, integrationEvent.OrderStatus, integrationEvent.BuyerId); // Send a confirmation e-mail if enabled. if (settings.Value.SendConfirmationEmail) { await emailService.SendOrderConfirmationAsync(readModelOrder); } }
public async Task Handle(ProcessLevyPaymentsOnMonthEndCommand command, IMessageHandlerContext context) { paymentLogger.LogInfo($"Processing ProcessLevyPaymentsOnMonthEndCommand. Message Id : {context.MessageId}, Job: {command.JobId}"); using (var operation = telemetry.StartOperation()) { var actorId = new ActorId(command.AccountId); var actor = proxyFactory.CreateActorProxy <ILevyFundedService>(new Uri("fabric:/SFA.DAS.Payments.FundingSource.ServiceFabric/LevyFundedServiceActorService"), actorId); var fundingSourceEvents = await actor.HandleMonthEnd(command).ConfigureAwait(false); foreach (var fundingSourcePaymentEvent in fundingSourceEvents) { if (fundingSourcePaymentEvent is ProcessUnableToFundTransferFundingSourcePayment) { await context.SendLocal(fundingSourcePaymentEvent).ConfigureAwait(false); } else { await context.Publish(fundingSourcePaymentEvent).ConfigureAwait(false); } } //await Task.WhenAll(fundingSourceEvents.Select(context.Publish)); telemetry.StopOperation(operation); } }
public async Task DoSomething(Guid id, string msg) { var proxy = _actorProxyFactory.CreateActorProxy <IExampleActor>(new ActorId(id), "App", "Service", "Listener"); await _subscriptionHelper.SubscribeAsync <IExampleEvents>(proxy, this); //await proxy.SubscribeAsync<IExampleEvents>(this); //crashes if the caller is not of type ActorProxy, which is not the case when mocked. await proxy.ActorSomething(msg); }
public static T GetClaptrap <T>(this IActorProxyFactory factory, string id) where T : IActor { var attribute = typeof(T).GetCustomAttribute <ClaptrapStateAttribute>() !; var re = factory.CreateActorProxy <T>(new ActorId(id), attribute.ClaptrapTypeCode); return(re); }
private IOrderingProcessActor GetOrderingProcessActor(Guid orderId) { var actorId = new ActorId(orderId.ToString()); return(_actorProxyFactory.CreateActorProxy <IOrderingProcessActor>( actorId, nameof(OrderingProcessActor))); }
private async Task InvokeSubmissionAction(long accountId, T message) { var actorId = new ActorId(accountId); var uri = new Uri(LevyFundedServiceConstants.ServiceUri); var actor = proxyFactory.CreateActorProxy <ILevyFundedService>(uri, actorId); await HandleSubmissionEvent(message, actor); logger.LogInfo($"Successfully processed {typeof(T).Name} event for Actor Id {actorId}, Job: {message.JobId}, UKPRN: {message.Ukprn}"); }
public async Task Handle(EmployerChangedProviderPriority message, IMessageHandlerContext context) { paymentLogger.LogInfo($"Processing EmployerChangedProviderPriority event. Message Id: {context.MessageId}, Account Id: {message.EmployerAccountId}"); var actorId = new ActorId(message.EmployerAccountId.ToString()); var actor = proxyFactory.CreateActorProxy <ILevyFundedService>(new Uri("fabric:/SFA.DAS.Payments.FundingSource.ServiceFabric/LevyFundedServiceActorService"), actorId); await actor.HandleEmployerProviderPriorityChange(message).ConfigureAwait(false); paymentLogger.LogInfo($"Successfully processed EmployerChangedProviderPriority event for Actor Id {actorId} ,Account Id: {message.EmployerAccountId}"); }
public static TActorInterface CreateActorProxy <TActorInterface>(this IActorProxyFactory actorProxyFactory, ActorReference actorReference) where TActorInterface : IActor { if (actorProxyFactory == null) { throw new ArgumentNullException(nameof(actorProxyFactory)); } if (actorReference == null) { throw new ArgumentNullException(nameof(actorReference)); } return(actorProxyFactory.CreateActorProxy <TActorInterface>(actorReference.ServiceUri, actorReference.ActorId, actorReference.ListenerName)); }
public Task Subscribe(TSubscription subscription) { return(WithLock(async() => { var topicId = subscription.GetTopicId(); if (!_proxies.ContainsKey(topicId)) { var uri = ActorNameFormat.GetFabricServiceUri(typeof(ITopicActor)); var actor = _actorProxyFactory.CreateActorProxy <ITopicActor>(uri, new ActorId(topicId)); await actor.SubscribeAsync(this); _proxies.Add(topicId, actor); } })); }
public async Task Publish(TMessage message, TSubscription subscription) { var uri = ActorNameFormat.GetFabricServiceUri(typeof(ITopicActor)); var topicId = subscription.GetTopicId(); var actor = _actorProxyFactory.CreateActorProxy <ITopicActor>(uri, new ActorId(topicId)); var serialisedMessage = JsonConvert.SerializeObject(message); var serialisedSubscription = JsonConvert.SerializeObject(subscription); await actor.PublishMessage(new TopicActorMessage { Subscription = serialisedSubscription, Message = serialisedMessage }); }
public static TTargetActorInterface Rebind <TTargetActorInterface>(this IActorProxyFactory actorProxyFactory, IActor actor) where TTargetActorInterface : IActor { if (actor == null) { throw new ArgumentNullException(nameof(actor)); } if (actorProxyFactory == null) { throw new ArgumentNullException(nameof(actorProxyFactory)); } var actorReference = actor.GetActorReference(); return(actorProxyFactory.CreateActorProxy <TTargetActorInterface>(actorReference.ServiceUri, actorReference.ActorId, actorReference.ListenerName)); }
public async Task Handle(ReceivedProviderEarningsEvent message, IMessageHandlerContext context) { paymentLogger.LogInfo($"Processing ReceivedProviderEarningsEvent, UKPRN: {message.Ukprn}, JobId: {message.JobId}, Period: {message.CollectionPeriod}, ILR: {message.IlrSubmissionDateTime}"); var actorId = new ActorId(message.Ukprn.ToString()); var actor = proxyFactory.CreateActorProxy <IRemovedLearnerService>(new Uri("fabric:/SFA.DAS.Payments.RequiredPayments.ServiceFabric/RemovedLearnerServiceActorService"), actorId); var removedAims = await actor.HandleReceivedProviderEarningsEvent(message.CollectionPeriod.AcademicYear, message.CollectionPeriod.Period, message.IlrSubmissionDateTime, CancellationToken.None).ConfigureAwait(false); foreach (var removedAim in removedAims) { removedAim.JobId = message.JobId; await context.Publish(removedAim).ConfigureAwait(false); } paymentLogger.LogInfo($"Finished processing ReceivedProviderEarningsEvent, published {removedAims.Count} aims. UKPRN: {message.Ukprn}, JobId: {message.JobId}, Period: {message.CollectionPeriod}, ILR: {message.IlrSubmissionDateTime}"); }
public async Task Handle(ResetActorsCommand message, IMessageHandlerContext context) { logger.LogDebug("Resetting datalock actors."); var resetTasks = new List <Task>(); foreach (var uln in message.Ulns) { var actorId = new ActorId(uln.ToString()); var actor = proxyFactory.CreateActorProxy <IDataLockService>(new Uri("fabric:/SFA.DAS.Payments.DataLocks.ServiceFabric/DataLockServiceActorService"), actorId); resetTasks.Add(actor.Reset()); } await Task.WhenAll(resetTasks).ConfigureAwait(false); logger.LogInfo("Finished resetting the datalock actors"); }
// GET /home/Fredrik%20G%C3%B6ransson public async Task <SpeakerDetails> Get(string id) { var cancelationToken = CancellationToken.None; var speakerActor = _actorProxyFactory.CreateActorProxy <ISpeakerActor>(new ActorId(id)); var speakerInfo = await speakerActor.GetSpeakerInfoAsync(cancelationToken); var sessionsInfo = await speakerActor.GetSessionsAsync(cancelationToken); var speaker = new SpeakerDetails() { Name = speakerInfo.Name, Bio = speakerInfo.Bio, Sessions = sessionsInfo, }; return(speaker); }
public async Task Handle(ResetCacheCommand message, IMessageHandlerContext context) { logger.LogDebug($"Resetting cache for provider :{message.Ukprn}"); var ulns = await repository.ApprenticeshipUlnsByProvider(message.Ukprn); var resetTasks = new List <Task>(); foreach (var uln in ulns) { var actorId = new ActorId(uln.ToString()); var actor = proxyFactory.CreateActorProxy <IDataLockService>(new Uri("fabric:/SFA.DAS.Payments.DataLocks.ServiceFabric/DataLockServiceActorService"), actorId); logger.LogVerbose($"Actor proxy created, now resetting the cache."); resetTasks.Add(actor.Reset()); } await Task.WhenAll(resetTasks).ConfigureAwait(false); logger.LogInfo($"Finished resetting the cache for provider: {message.Ukprn}"); }
public async Task Handle(ProcessUnableToFundTransferFundingSourcePayment message, IMessageHandlerContext context) { logger.LogInfo($"Processing ProcessUnableToFundTransferFundingSourcePayment event. Message Id: {message.EventId}, Learner: {message.Learner?.ReferenceNumber}, Job: {message.JobId}, UKPRN: {message.Ukprn}"); ((ESFA.DC.Logging.ExecutionContext)executionContext).JobId = message.JobId.ToString(); if (!message.AccountId.HasValue) { throw new ArgumentException($"Employer AccountId cannot be null. Event Id: {message.EventId}"); } logger.LogDebug($"Sending message to actor: {message.AccountId.Value}."); var actorId = new ActorId(message.AccountId.Value); var actor = proxyFactory.CreateActorProxy <ILevyFundedService>(new Uri("fabric:/SFA.DAS.Payments.FundingSource.ServiceFabric/LevyFundedServiceActorService"), actorId); var fundingSourceEvents = await actor.UnableToFundTransfer(message).ConfigureAwait(false); await Task.WhenAll(fundingSourceEvents.Select(context.Publish)); logger.LogInfo($"Successfully processed ProcessUnableToFundTransferFundingSourcePayment event for Actor Id {actorId}, Learner: {message.Learner?.ReferenceNumber}, Job: {message.JobId}, UKPRN: {message.Ukprn}"); }
public async Task Handle(CalculatedRequiredLevyAmount message, IMessageHandlerContext context) { paymentLogger.LogInfo($"Processing ApprenticeshipContractType1RequiredPaymentEvent event. Message Id: {context.MessageId}, Job: {message.JobId}, UKPRN: {message.Ukprn}"); executionContext.JobId = message.JobId.ToString(); if (!message.AccountId.HasValue) { throw new ArgumentException($"Employer AccountId cannot be null. Event id: {message.EventId}"); } var accountToUse = levyMessageRoutingService.GetDestinationAccountId(message); paymentLogger.LogDebug($"Sending levy message to levy actor: {accountToUse}. Account: {message.AccountId}, sender: {message.TransferSenderAccountId}. "); var actorId = new ActorId(accountToUse); var actor = proxyFactory.CreateActorProxy <ILevyFundedService>(new Uri("fabric:/SFA.DAS.Payments.FundingSource.ServiceFabric/LevyFundedServiceActorService"), actorId); await actor.HandleRequiredPayment(message).ConfigureAwait(false); paymentLogger.LogInfo($"Successfully processed LevyFundedProxyService event for Actor Id {actorId}, Job: {message.JobId}, UKPRN: {message.Ukprn}"); }
public async Task Handle(T message, IMessageHandlerContext context) { paymentLogger.LogInfo($"Processing RequiredPaymentsProxyService event. Message Id : {context.MessageId}"); executionContext.JobId = message.JobId.ToString(); var contractType = GetContractTypeFromMessage(message); var key = apprenticeshipKeyService.GenerateApprenticeshipKey( message.Ukprn, message.Learner.ReferenceNumber, message.LearningAim.FrameworkCode, message.LearningAim.PathwayCode, message.LearningAim.ProgrammeType, message.LearningAim.StandardCode, message.LearningAim.Reference, message.CollectionPeriod.AcademicYear, contractType ); var actorId = new ActorId(key); var actor = proxyFactory.CreateActorProxy <IRequiredPaymentsService>( new Uri("fabric:/SFA.DAS.Payments.RequiredPayments.ServiceFabric/RequiredPaymentsServiceActorService"), actorId); IReadOnlyCollection <PeriodisedRequiredPaymentEvent> requiredPaymentEvent; requiredPaymentEvent = await HandleEarningEvent(message, actor).ConfigureAwait(false); if (requiredPaymentEvent != null) { await Task.WhenAll(requiredPaymentEvent.Select(context.Publish)).ConfigureAwait(false); } paymentLogger.LogInfo("Successfully processed RequiredPaymentsProxyService event for Actor for " + $"jobId:{message.JobId}, learnerRef:{message.Learner.ReferenceNumber}, frameworkCode:{message.LearningAim.FrameworkCode}, " + $"pathwayCode:{message.LearningAim.PathwayCode}, programmeType:{message.LearningAim.ProgrammeType}, " + $"standardCode:{message.LearningAim.StandardCode}, learningAimReference:{message.LearningAim.Reference}, " + $"academicYear:{message.CollectionPeriod.AcademicYear}, contractType:{contractType}"); }
public async Task Handle(ApprenticeshipUpdated message, IMessageHandlerContext context) { if (message.Uln == 0) { throw new InvalidOperationException("Invalid 'ApprenticeshipUpdated' received. Uln was 0."); } logger.LogDebug($"Now handling the apprenticeship updated event. Apprenticeship: {message.Id}, employer: {message.EmployerAccountId}, ukprn: {message.Ukprn}"); var actorId = new ActorId(message.Ukprn); logger.LogVerbose($"Creating actor proxy."); var actor = actorProxyFactory.CreateActorProxy <IDataLockService>(new Uri("fabric:/SFA.DAS.Payments.DataLocks.ServiceFabric/DataLockServiceActorService"), actorId); logger.LogDebug($"Actor proxy created for actor id {message.Uln}"); await actor.HandleApprenticeshipUpdated(message, CancellationToken.None).ConfigureAwait(false); //var dataLockEvents = await actor.GetApprenticeshipUpdatedPayments( message, CancellationToken.None).ConfigureAwait(false); //logger.LogDebug($"Earning handled for learner with learner uln {message.Uln}"); //if (dataLockEvents != null) //{ // var summary = string.Join(", ", dataLockEvents.GroupBy(e => e.GetType().Name).Select(g => $"{g.Key}: {g.Count()}")); // logger.LogVerbose($"Publishing data lock event for learner with learner uln {message.Uln}: {summary}"); // await Task.WhenAll(dataLockEvents.Select(context.Publish)).ConfigureAwait(false); // logger.LogDebug($"Data lock event published for learner with learner uln {message.Uln}"); //} //var dataLockFunctionalSkillEvents = await actor.GetApprenticeshipUpdateFunctionalSkillPayments(message, CancellationToken.None).ConfigureAwait(false); //if (dataLockFunctionalSkillEvents != null) //{ // var summary = string.Join(", ", dataLockFunctionalSkillEvents.GroupBy(e => e.GetType().Name).Select(g => $"{g.Key}: {g.Count()}")); // logger.LogVerbose($"Publishing data lock event for learner with learner uln {message.Uln}: {summary}"); // await Task.WhenAll(dataLockFunctionalSkillEvents.Select(context.Publish)).ConfigureAwait(false); // logger.LogDebug($"Data lock event published for learner with learner uln {message.Uln}"); //} logger.LogInfo($"Finished handling the apprenticeship updated event. Apprenticeship: {message.Id}, employer: {message.EmployerAccountId}, provider: {message.Ukprn}"); }
public async Task Handle(ProcessLearnerCommand message, IMessageHandlerContext context) { logger.LogDebug( $"Handling ILR learner submission. Job: {message.JobId}, Ukprn: {message.Ukprn}, Collection year: {message.CollectionYear}, Learner: {message.Learner.LearnRefNumber}"); var key = new LearnerKey(message).Key; var actorId = new ActorId(key); var actor = proxyFactory.CreateActorProxy <IProcessLearnerService>( new Uri("fabric:/SFA.DAS.Payments.EarningEvents.ServiceFabric/ProcessLearnerServiceActorService"), actorId); var learnerEarningEvents = await actor.CreateLearnerEarningEvents(message); foreach (var earningEvent in learnerEarningEvents) { await context.Publish(earningEvent).ConfigureAwait(false); } var summary = learnerEarningEvents.Any() ? string.Join(", ", learnerEarningEvents.GroupBy(e => e.GetType().Name).Select(g => $"{g.Key}: {g.Count()}")): "none"; logger.LogInfo( $"Finished handling ILR learner submission.Job: {message.JobId}, Ukprn: {message.Ukprn}, Collection year: {message.CollectionYear}, Learner: {message.Learner.LearnRefNumber}. Published events: {summary}"); }
/// <summary> /// Creates a proxy to the actor object that implements an actor interface. /// </summary> /// <typeparam name="TActorInterface"> /// The actor interface implemented by the remote actor object. /// The returned proxy object will implement this interface. /// </typeparam> /// <param name="actorId">The actor ID of the proxy actor object. Methods called on this proxy will result in requests /// being sent to the actor with this ID.</param> /// <param name="actorType">Type of actor implementation.</param> /// <param name="options">The optional <see cref="ActorProxyOptions" /> to use when creating the actor proxy.</param> /// <returns>Proxy to the actor object.</returns> public static TActorInterface Create <TActorInterface>(ActorId actorId, string actorType, ActorProxyOptions options = null) where TActorInterface : IActor { return(DefaultProxyFactory.CreateActorProxy <TActorInterface>(actorId, actorType, options)); }
private IPool GetProxy(string serviceTypeUri) => _actorProxyFactory.CreateActorProxy <IPool>(new ActorId(serviceTypeUri), "PoolManager", "PoolActorService");
/// <summary> /// This is the main entry point for your service replica. /// This method executes when this replica of your service becomes primary and has write status. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { try { _freeHandlers = Enumerable.Range(1, HandlerCount).ToConcurrentQueue(); await SetupServiceBus(); while (!cancellationToken.IsCancellationRequested) { try { //if (_messageReceiver.IsClosedOrClosing) //{ // _bigBrother.Publish(new MessageReceiverClosingEvent { FabricId = $"{this.Context.ServiceName}:{this.Context.ReplicaId}" }); // continue; //} var(messages, activeReaderId) = await ReceiveMessagesFromActiveReceiver(); await ServiceReceiversLifecycle(); if (messages == null || messages.Count == 0) { // ReSharper disable once MethodSupportsCancellation - no need to cancellation token here #if DEBUG //this is done due to enable SF mocks to run as receiver call is not awaited and therefore RunAsync would never await await Task.Delay(TimeSpan.FromMilliseconds(10)); #endif continue; } foreach (var message in messages) { var messageData = new MessageData(Encoding.UTF8.GetString(message.Body), _initData.EventType, _initData.SubscriberName, Context.ServiceName.ToString(), _initData.DlqMode != null); var handlerId = GetFreeHandlerId(); messageData.HandlerId = handlerId; messageData.CorrelationId = Guid.NewGuid().ToString(); var handleData = new MessageDataHandle { LockToken = _serviceBusManager.GetLockToken(message), ReceiverId = activeReaderId }; _inflightMessages.TryAdd(messageData.CorrelationId, handleData); //should again always succeed await _proxyFactory.CreateActorProxy <IEventHandlerActor>( new ActorId(messageData.EventHandlerActorId), serviceName : ServiceNaming.EventHandlerServiceShortName) .Handle(messageData); } } catch (ServiceBusCommunicationException sbCommunicationException) { BigBrother.Write(sbCommunicationException.ToExceptionEvent()); await SetupServiceBus(); } catch (Exception e) { BigBrother.Write(e.ToExceptionEvent()); } } _bigBrother.Publish(new Common.Telemetry.CancellationRequestedEvent { FabricId = $"{Context.ServiceName}:{Context.ReplicaId}" }); } catch (Exception e) { BigBrother.Write(e.ToExceptionEvent()); } }
private IPartition GetProxy(string partitionId) => _actorProxyFactory.CreateActorProxy <IPartition>(new ActorId(partitionId), "PoolManager", "PartitionActorService");