Lightweight In-Memory Message Bus Using .NET Channels

Поділитися
Вставка

КОМЕНТАРІ • 53

  • @MilanJovanovicTech
    @MilanJovanovicTech  6 місяців тому

    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

  • @sergiom.954
    @sergiom.954 5 місяців тому

    I didn't know channels, it is a very amazing but unknown feature!

  • @andersborum9267
    @andersborum9267 6 місяців тому +1

    Also, the reader/writer pattern is often referred to as the producer/consumer pattern. It would be so nice to have transactional memory ..

  • @aliwa91
    @aliwa91 6 місяців тому

    Thanks again

  • @MahmoudIsmail-rw7hg
    @MahmoudIsmail-rw7hg 3 місяці тому

    I think bounded channel is 'limited capacity', limited with the number of items it can hold.

  • @banster85
    @banster85 6 місяців тому

    Maybe the InMemeoryMessageQueue class should be generic to be able to get the WorkoutId from the Reader of the channel

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 місяців тому

      Why is that necessary?

    • @banster85
      @banster85 6 місяців тому

      ​@@MilanJovanovicTech Because you publish a WorkoutRemovedIntegrationEvent object but instantiate a Channel of IIntegrationEvent so in the background service, reading from the Channel, we have access only to the property of IIntegrationEvent and not the WorkoutId property of WorkoutRemovedIntegrationEvent

  • @tanglesites
    @tanglesites 6 місяців тому +1

    What is the difference between a Websocket API, and a REST API when working with C# and how do set one up? Can you use a REST architecture on top of the Websocket API? Maybe you can make a video covering some flavor of these questions.

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 місяців тому

      learn.microsoft.com/en-us/aspnet/core/fundamentals/websockets

  • @MaximT
    @MaximT 4 місяці тому

    If nobody subscribes to the events, there will be be a memory leak
    P.S. - better to create channels on the subscription to the the events, and if no subscription then to drop messages

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 місяці тому

      That's true, but if this is an in-memory pub-sub model, why would you a publish a message that you don't want to handle?

    • @MaximT
      @MaximT 4 місяці тому

      @@MilanJovanovicTech That's about the maintenance of a project. Sombody will remove a subscription because it is not needed anymore, and forget to remove the publishing.

  •  6 місяців тому +1

    Great work Milan. Very well explaned with a good real-world scenario

  • @MirosawSiwecki
    @MirosawSiwecki 5 місяців тому

    I think that you incorrectly use word asynchronous. Your first publish was asynchronous. The job was taken out of IO thread. I think you should saythat task is not parallel

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 місяців тому

      Is MediatR Publish IO or CPU heavy? It doesn't really do any IO last time I checked. The notification handler might, but that's a different thing.

  • @JestNest-b8v
    @JestNest-b8v 5 місяців тому

    Thank you for the video, Milan! From the asynchrony perspective I think that nothing has changed between using INotification and IEventBus. You couldn't make your code MORE asynchronous. Even in the second approach you were still using await and returned response to the client only after the method for publishing was awaited on. So you're not making your program work any different if we consider only asynchrony - you still use the same threadpool mechanism. What you should have pointed out in your video is that you've enforced decoupling between the party that publishes and the party that processes event messages.

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 місяців тому

      "you've enforced decoupling between the party that publishes and the party that processes event messages." - which is what I mean by asynchronous here

  • @nickw656
    @nickw656 6 місяців тому

    At ua-cam.com/video/gox065POif4/v-deo.htmlua-cam.com/video/gox065POif4/v-deo.html, could you explain why the implementation is not reliable?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 місяців тому +2

      Simply because it works IN MEMORY only. If your app crashes, or there's an exception, the message is lost and you don't have a way to recover it.

  • @nagendrakamath588
    @nagendrakamath588 6 місяців тому

    Thanks for sharing this ....Hope it will all be covered in clean architecture course i purchased

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 місяців тому +1

      This one not in particular (you can see the whole curriculum), but you'll see an elegant Outbox implementation

  • @aliadly6440
    @aliadly6440 6 місяців тому

    Thanks ,Why don't you add the githup repo?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 місяців тому

      I share the code on Patreon, but you can find most of it here: www.milanjovanovic.tech/blog/lightweight-in-memory-message-bus-using-dotnet-channels

  • @krccmsitp2884
    @krccmsitp2884 6 місяців тому

    Nice approach using the Channels feature. 👍🏻

  • @ezequielcardoso2431
    @ezequielcardoso2431 6 місяців тому

    Great Milan, how would you do an integrated test on a background service that consumes messages from the servicebus?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 місяців тому +1

      Wait X time in the test, and check for the consequences

    • @ezequielcardoso2431
      @ezequielcardoso2431 6 місяців тому

      @@MilanJovanovicTech Precisely, test processing time. I'm going through this.

  • @miles6875
    @miles6875 6 місяців тому

    Great video

  • @bobek8030
    @bobek8030 6 місяців тому

    why there is no need to have while loop inside background task?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 місяців тому

      Because the Task doesn't complete

    • @bobek8030
      @bobek8030 6 місяців тому

      @@MilanJovanovicTech what about cpu load in this approach? isnt it like while true loop without task.delay?

    • @andersborum9267
      @andersborum9267 6 місяців тому

      ​@@bobek8030there's no CPU load as there's no wait state for the CPU; when items are written to the channel, (task based) readers are notified by means of queuing tasks on the threadpool. It effectively releases the iterating thread to do other tasks until the channel is asking for work to be processed. You should (very high level) think of channels as a high level producer/consumer API around task queues.

  • @danieleluppi6648
    @danieleluppi6648 6 місяців тому

    you're ripping

  • @maxm1079
    @maxm1079 6 місяців тому

    Когда я увидел публикацию, то подумал, что увижу что-то родное. Но опять же этот MediatR, его нельзя использовать в проектах со слишком большим количеством сущностей, он добавляет совершенно ненужную сложность восприятию проекта и его отладке

    • @ANTONZUBAREV
      @ANTONZUBAREV 6 місяців тому

      Mediatr это больше про DDD и чистую архитектуру. Идею шины (bus) и Thread channel можно использовать и в громадном монолите.

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 місяців тому

      Медиатр в этом примере - всего лишь средство для достижения цели. Я использовал его только для того, чтобы упростить публикацию событий. При желании вы можете реализовать все с нуля. Извините, если по-русски неправильно - это вина Google Translate. С уважением!

    • @Fikusiklol
      @Fikusiklol 6 місяців тому

      @@ANTONZUBAREV Какое отношение имеет mediatr к DDD и чистой архитектуре?
      Ни там ни там нет упоминания про него. Это просто инструмент.

    • @Fikusiklol
      @Fikusiklol 6 місяців тому

      Сложности он явно не добавляет, даже сказал бы, особенно в большом проекте.
      Посмотри в сторону Vertical Slice архитектуры (или ее подобия), если у вас файлики разбросаны по всему проекту. Чтобы повысить функциональный cohesion.
      У Milan был недавно видео на эту тему :)

    • @YehorBachurinDev
      @YehorBachurinDev 2 місяці тому

      ​@@MilanJovanovicTech No apologies or respect for the ᵣussians...