Upgrade to Pro — share decks privately, control downloads, hide ads and more …

LEVELUP 2015 - Enterprise software schaalbaar maken met Service Fabric

LEVELUP 2015 - Enterprise software schaalbaar maken met Service Fabric

hoe AFAS zijn next gen ERP platform ontwikkelt

Michiel Overeem

November 26, 2015
Tweet

More Decks by Michiel Overeem

Other Decks in Technology

Transcript

  1. AFAS Online 1780 cores, 25 TB RAM, 180 TB SSD

    storage 10.000 concurrent RDP gebruikers 200.000 unieke gebruikers per maand 1.500.000 API calls per dag
  2. Command public class CreateArticleCommand : Command { public Guid ArticleId

    { get; set; } public string Description { get; set; } public decimal Price { get; set; } } Event public class ArticleCreatedEvent : Event { public Guid ArticleId { get; set; } public string Description { get; set; } public decimal Price { get; set; } } Query public class GetArticleQuery : Query { public Guid ArticleId { get; set; } }
  3. AggregateRoot - Handle public void Handle(CreateArticleCommand command) { if(command.Price <=

    0) { throw new CommandValidationException("Price should be greater than 0."); } if(string.IsNullOrEmpty(command.Description) || command.Description.Length > 20) { throw new CommandValidationException("Description is mandatory, " + "and cannot be longer than 20 characters."); } RaiseEvent(new ArticleCreatedEvent(command.ArticleId, command.Description, command.Price)); } AggregateRoot - Apply private void Apply(ArticleCreatedEvent @event) { _saleable = true; _price = @event.Price; }
  4. CommandHandler private void Handle(CreateArticleCommand command) { Repository.ExecuteOn<ArticleAggregateRoot>(command.ArticleId, command); } AggregateRootRepository

    - InMemory public virtual async Task ExecuteOn<T>(Guid aggregateId, Command command) where T: AggregateRoot { T aggregateRoot = LoadAggregateRoot<T>(aggregateId); aggregateRoot.Handle(command); await SaveAndDispatchEvents(aggregateRoot); }
  5. 1 3 7 4 8 2 8 6 5 1

    3 1 4 6 2 7 6 5 4 8 3 7 2 5
  6. 1 3 7 4 8 2 8 6 5 1

    3 1 4 6 2 7 6 5 4 8 3 7 2 5
  7. AggregateRootRepository - InMemory public virtual async Task ExecuteOn<T>(Guid aggregateId, Command

    command) where T: AggregateRoot { T aggregateRoot = LoadAggregateRoot<T>(aggregateId); aggregateRoot.Handle(command); await SaveAndDispatchEvents(aggregateRoot); } AggregateRootRepository – Service Fabric public override async Task ExecuteOn<T>(Guid aggregateId, Command command) { var actor = ActorProxy.Create<IAggregateRootActor>(new ActorId(aggregateId), "App"); await actor.ExecuteOn(typeof(T).AssemblyQualifiedName, command.ToJson()); }
  8. AggregateRootActor public async Task ExecuteOn(string aggregateRootType, string commandJson) { var

    aggregateRoot = LoadAggregateRoot(aggregateRootType); var command = Deserialize(commandJson); aggregateRoot.Handle(command); await SaveAndDispatchEvents(aggregateRoot); }
  9. QueryModelBuilder private void Handle(ArticleCreatedEvent @event) { Repository.Add(@event.ArticleId, new JObject( new

    JProperty("Article", @event.ArticleId), new JProperty("Description", @event.Description), new JProperty("Price", @event.Price))); } QueryHandler private JObject Handle(GetArticleQuery query) { return Repository.Get(query.ArticleId); }
  10. QueryModelBuilder Service public async Task Handle(string eventJson) { var queue

    = await StateManager.GetOrAddAsync<IReliableQueue<string>>("qmbQueue"); using(ITransaction tx = StateManager.CreateTransaction()) { await queue.EnqueueAsync(tx, eventJson); await tx.CommitAsync(); } }
  11. QueryModelBuilder Service protected override async Task RunAsync(CancellationToken cancellationToken) { var

    queue = await StateManager.GetOrAddAsync<IReliableQueue<string>>("qmbQueue"); while(true) { using(ITransaction tx = StateManager.CreateTransaction()) { ConditionalResult<string> dequeueReply = await queue.TryDequeueAsync(tx); if(dequeueReply.HasValue) { string message = dequeueReply.Value; _queryModelBuilder.Handle(Deserialize(message)); await tx.CommitAsync(); } } } }
  12. Voor vragen, discussie etc: [email protected] - @michielovereem - https://linkedin.com/in/movereem CQRS

    + Service Fabric • Sluit ontzettend goed aan bij onze architectuur. • Betrouwbaarheid, schaalbaarheid en onderhoudsgemak. • Portable cloud hosting is mogelijk. https://github.com/AFASSoftware/CQRS-Microservices