Lightweight In-Memory Message Bus Using .NET Channels

Поделиться
HTML-код
  • Опубликовано: 21 янв 2025

Комментарии • 57

  • @MilanJovanovicTech
    @MilanJovanovicTech  9 месяцев назад

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

  • @lldadb664
    @lldadb664 2 месяца назад +1

    If you only knew how timely this was for me to find by accident after watching some of your other videos. Thanks!

  •  9 месяцев назад +1

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

  • @krccmsitp2884
    @krccmsitp2884 9 месяцев назад

    Nice approach using the Channels feature. 👍🏻

  • @aborum75
    @aborum75 9 месяцев назад +1

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

  • @emanuelrodriguez3155
    @emanuelrodriguez3155 Месяц назад

    whats the benefit of using the abstract class implementing the interface for the integration event ínstead of just using the interface?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Месяц назад

      The implementing class only needs to define its own fields (without implementing the interface)

  • @sergiom.954
    @sergiom.954 9 месяцев назад

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

  • @nagendrakamath588
    @nagendrakamath588 9 месяцев назад

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 месяцев назад +1

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

  • @JestNest-b8v
    @JestNest-b8v 9 месяцев назад

    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  9 месяцев назад

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

  • @tanglesites
    @tanglesites 9 месяцев назад +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  9 месяцев назад

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

  • @ezequielcardoso2431
    @ezequielcardoso2431 9 месяцев назад

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 месяцев назад +1

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

    • @ezequielcardoso2431
      @ezequielcardoso2431 9 месяцев назад

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

  • @bobek8030
    @bobek8030 9 месяцев назад

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 месяцев назад

      Because the Task doesn't complete

    • @bobek8030
      @bobek8030 9 месяцев назад

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

    • @aborum75
      @aborum75 9 месяцев назад

      ​@@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.

  • @miles6875
    @miles6875 9 месяцев назад

    Great video

  • @aliadly6440
    @aliadly6440 9 месяцев назад

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 месяцев назад

      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

  • @aliwa91
    @aliwa91 9 месяцев назад

    Thanks again

  • @banster85
    @banster85 9 месяцев назад

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 месяцев назад

      Why is that necessary?

    • @banster85
      @banster85 9 месяцев назад

      ​@@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

  • @MahmoudIsmail-rw7hg
    @MahmoudIsmail-rw7hg 7 месяцев назад

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

  • @nickw656
    @nickw656 9 месяцев назад

    At ruclips.net/video/gox065POif4/видео.htmlruclips.net/video/gox065POif4/видео.html, could you explain why the implementation is not reliable?

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 месяцев назад +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.

  • @MirosawSiwecki
    @MirosawSiwecki 9 месяцев назад

    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  9 месяцев назад

      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.

  • @MaximT
    @MaximT 8 месяцев назад

    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  8 месяцев назад

      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 8 месяцев назад

      @@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.

  • @danieleluppi6648
    @danieleluppi6648 9 месяцев назад

    you're ripping

  • @maxm1079
    @maxm1079 9 месяцев назад

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

    • @ANTONZUBAREV
      @ANTONZUBAREV 9 месяцев назад

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 месяцев назад

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

    • @Fikusiklol
      @Fikusiklol 9 месяцев назад

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

    • @Fikusiklol
      @Fikusiklol 9 месяцев назад

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

    • @YehorBachurinDev
      @YehorBachurinDev 6 месяцев назад

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