Learning Golang: Concurrency Pattern Publisher / Subscriber

preview_player
Показать описание
Also known as Pub/Sub, this messaging pattern allows customers, known as subscribers, to asynchronously receive events generated by a producer, known as a publisher. Pub/Sub is a well-known pattern used in distributed systems to asynchronously communicate different services interested in learning specific information about a particular service.

In Go, we can use the concurrency primitives of the language, such as channels and goroutines, to implement this pattern.

Let me show you how.

=== Relevant Links

== All Go/Golang Playlists

00:00 - Intro to Golang Publisher Subscriber Concurrency Pattern
00:08 - What is the Publisher/Subscriber Concurrency Pattern?
00:52 - Creating the PubSub Golang generic type
02:03 - Implementing the Subscribe method
03:19 - Implementing the Publish method
04:49 - Putting it all together
08:13 - Conclusion of Golang Publisher Subscriber Concurrency Pattern

=== Who am I?

Hello 👋🏼! My name is Mario, and I am a Hands-on Software Architect and Lead Backend Engineer with decades of professional experience building all kinds of software, such as on-premise Automation Systems, Linux Accessibility Desktop Applications, Cloud Governance and Compliance Systems, and Distributed Cloud-based Advertising Systems.

The content I produce includes what I've learned while working for small startups and large companies and the processes I've followed for successfully delivering complex enterprise systems from start to end.

Subscribe if you like Software Development, Software Architecture, and Systems Design, and of course, Go!

Keep it up. Don't give up!

#golang #tutorial #concurrency

=== Follow us on Instagram for our family adventures

=== Our affiliate links below

DISCLAIMER: Some of the links shared in the description are affiliate links. As a member of these affiliate programs, I earn a small commission from your purchases at no additional cost. I appreciate your support! 💖
Рекомендации по теме
Комментарии
Автор

about the question at the end: you can iterate over channels cleanly `for msg := range channel {` the for exits when the channel is closed

jpfontenele
Автор

There are errors in the code. wg.Add(1) must be done before starting the goroutine. And wg.Done() is better used with defer

EyeOfInfinity-tg
Автор

This is similar to reactive programming, really cool 👍

hgfjegryteureyegfhej
Автор

are u sure? Publish method will be blocked by subscriber until read value from chan.

eamarc