Lightweight In-Memory Message Bus Using .NET Channels

  Рет қаралды 12,591

Milan Jovanović

Milan Jovanović

Күн бұрын

Пікірлер: 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 ай бұрын
If you only knew how timely this was for me to find by accident after watching some of your other videos. Thanks!
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
Awesome, glad to hear it 😁
9 ай бұрын
Great work Milan. Very well explaned with a good real-world scenario
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
Thanks!
@krccmsitp2884
@krccmsitp2884 9 ай бұрын
Nice approach using the Channels feature. 👍🏻
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
Thanks :)
@aborum75
@aborum75 9 ай бұрын
Also, the reader/writer pattern is often referred to as the producer/consumer pattern. It would be so nice to have transactional memory ..
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
A man can dream
@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 8 ай бұрын
I didn't know channels, it is a very amazing but unknown feature!
@MilanJovanovicTech
@MilanJovanovicTech 8 ай бұрын
Glad you learned about it :)
@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 ай бұрын
Wait X time in the test, and check for the consequences
@ezequielcardoso2431
@ezequielcardoso2431 9 ай бұрын
@@MilanJovanovicTech Precisely, test processing time. I'm going through this.
@nagendrakamath588
@nagendrakamath588 9 ай бұрын
Thanks for sharing this ....Hope it will all be covered in clean architecture course i purchased
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
This one not in particular (you can see the whole curriculum), but you'll see an elegant Outbox implementation
@tanglesites
@tanglesites 9 ай бұрын
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
@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
@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
@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.
@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
@miles6875
@miles6875 9 ай бұрын
Great video
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
Thanks!
@aliwa91
@aliwa91 9 ай бұрын
Thanks again
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
Always welcome
@MahmoudIsmail-rw7hg
@MahmoudIsmail-rw7hg 7 ай бұрын
I think bounded channel is 'limited capacity', limited with the number of items it can hold.
@MilanJovanovicTech
@MilanJovanovicTech 7 ай бұрын
Yep
@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.
@nickw656
@nickw656 9 ай бұрын
At kzbin.info/www/bejne/naDbYWlrhbScnJYkzbin.info/www/bejne/naDbYWlrhbScnJY, could you explain why the implementation is not reliable?
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
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.
@MaximT
@MaximT 7 ай бұрын
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 7 ай бұрын
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 7 ай бұрын
@@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
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
I first read this as "you're tripping" 😁
@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...
Completely Get Rid of Exceptions Using This Technique
19:24
Milan Jovanović
Рет қаралды 28 М.
.NET Project Setup From Scratch Using These 6 Best Practices
16:07
Milan Jovanović
Рет қаралды 23 М.
Хаги Ваги говорит разными голосами
0:22
Фани Хани
Рет қаралды 2,2 МЛН
«Жат бауыр» телехикаясы І 26-бөлім
52:18
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 434 М.
You DON'T want an In-Memory Event Bus like MediatR
11:20
CodeOpinion
Рет қаралды 23 М.
Getting Started With MassTransit (Beginner Friendly)
12:35
Milan Jovanović
Рет қаралды 27 М.
The Right Way To Use Scoped Services From Singletons in ASP.NET Core
12:58
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 512 М.
Best of CES 2025
14:50
The Verge
Рет қаралды 631 М.
Automated Work Machines That Will Change Your Life Forever
17:01
What is OpenTelemetry?
12:55
Highlight
Рет қаралды 19 М.
7 Serilog Best Practices for Better Structured Logging
13:36
Milan Jovanović
Рет қаралды 30 М.
Хаги Ваги говорит разными голосами
0:22
Фани Хани
Рет қаралды 2,2 МЛН