SlideShare a Scribd company logo
1 of 36
Publish- and Subscribe to
events using an
Event Aggregator
Lars-Erik Kindblad
Senior Consultant
Blog: kindblad.com
Agenda
What is the Publish-Subscribe Pattern?
 Message
 Publisher
 Subscriber
 Event Aggregator and how to create one
Code Sample #1 and #2 without and with publish-subscribe
Summary
What is the Publish-Subscribe Pattern?
Publish-Subscribe = Pub/Sub
Message/event based pattern
The publisher creates and publishes messages through an event
aggregator (message bus) – but don’t program the messages to be sent
directly to any subscribers
The subscribers define what messages they want to subscribe to
Event Aggregator
Subscriber Subscriber
Publisher
Message
MessageMessage
Subscribe
What is a Message?
A simple .NET POCO class with or without properties
What is a Publisher?
Any class that wants to create and publish a message
What is a Subscriber?
Any class that wants to do something when a specific message or event
occurs
What is an Event Aggregator?
A lightweight message bus
Accepts a message and publishes it out to only those who subscribes for it
Can be synchronous or asynchronous
Must have
 Publish(message) method
Can have
 Subscribe(subscriber) method
 Unsubscribe(subscriber) method
Event Aggregator for the UI
Event Aggregator for non-UI
Code Sample #1
Name: MainForm
Name: NewCustomerControl
Name: ToolbarControl
New requirement
Save button should be disabled when the first name or lastname is empty
NewCustomerControl
ToolbarControl
BtnSave.Enabled = true/false
Dependency graph
Strongly Coupled Code
Control Control
Control
Control
Control
Control
Control Control
Dependency graph for a more complex scenario
Strongly Coupled Code
Dependency graph for an enterprise application
Even more strongly coupled code
Event Aggregator
(Pub-Sub)
Control Control
Control
Control
Control
Control
Control Control
A better solution - Loosely coupled code
1. Define the messages
2. Publish the messages
3. Subscribe to- and handle the messages
NewCustomerControl
ToolbarControl Event Aggregator
ToolbarControl
NewCustomerControl
Publish:
• DisableSave
• EnableSave
BtnSave.Enabled
= true/false
Subscribe to & handle:
• DisableSave
• EnableSave
From strong- to loose coupling
Code Sample #2
New Requirement
The customer should receive an e-mail when the customer has been
registered
1. Create a New Class
2. Call EmailCustomer From RegisterCustomer
New Requirement
Send a SMS to the customer when the customer has been registered
1. Create a New Class
2. Call SmsCustomer From RegisterCustomer
Open Closed Principle
“Software entities (classes, modules, functions, etc.) should be open for
extension, but closed for modification”
The current implementation breaks this principle
Publish-Subscribe would not break the principle
RegisterCustomer
EmailCustomer SmsCustomer
Event Aggregator
EmailCustomer SmsCustomer
RegisterCustomer
Publish message:
CustomerRegistered
Subscribe to &
handle the
message
Invoke
1. Define the Message
2. Create and Publish the Message
3. Subscribe to the Message
RegisterCustomer
EmailCustomer SmsCustomer
Event Aggregator
EmailCustomer SmsCustomer
RegisterCustomer
Publish message:
CustomerRegistered
Subscribe to &
handle the
message
Invoke
Overview
Summary
Publish & Subscribe + Event Aggregator gives:
 Code that is loosely coupled
 Less complex code that is easier to maintain and unit-test
Where to use it?
1. UI/Presentation layer
2. Other layers when needed
How to use it?
1. Download or create your own event aggregator
2. Define a message
3. Create and publish a message
4. Subscribe to the message
QUESTIONS?
The information contained in this presentation is proprietary.
© 2012 Capgemini. All rights reserved.
www.capgemini.com
About Capgemini
With more than 120,000 people in 40 countries, Capgemini is one
of the world's foremost providers of consulting, technology and
outsourcing services. The Group reported 2011 global revenues
of EUR 9.7 billion.
Together with its clients, Capgemini creates and delivers
business and technology solutions that fit their needs and drive
the results they want. A deeply multicultural organization,
Capgemini has developed its own way of working, the
Collaborative Business ExperienceTM, and draws on Rightshore ®,
its worldwide delivery model.
Rightshore® is a trademark belonging to Capgemini

More Related Content

What's hot

Distributed Event Routing in Publish/Subscribe Systems
Distributed Event Routing in Publish/Subscribe SystemsDistributed Event Routing in Publish/Subscribe Systems
Distributed Event Routing in Publish/Subscribe Systems
Roberto Baldoni
 

What's hot (20)

Building Event-Driven Integration Architectures with Azure Event Grid (GIB2019)
Building Event-Driven Integration Architectures with Azure Event Grid (GIB2019)Building Event-Driven Integration Architectures with Azure Event Grid (GIB2019)
Building Event-Driven Integration Architectures with Azure Event Grid (GIB2019)
 
Micro Frontends
Micro FrontendsMicro Frontends
Micro Frontends
 
Understanding the architecture of MariaDB ColumnStore
Understanding the architecture of MariaDB ColumnStoreUnderstanding the architecture of MariaDB ColumnStore
Understanding the architecture of MariaDB ColumnStore
 
Microservices and SOA
Microservices and SOAMicroservices and SOA
Microservices and SOA
 
MySQL 8.0.16 New Features Summary
MySQL 8.0.16 New Features SummaryMySQL 8.0.16 New Features Summary
MySQL 8.0.16 New Features Summary
 
Go로 새 프로젝트 시작하기
Go로 새 프로젝트 시작하기Go로 새 프로젝트 시작하기
Go로 새 프로젝트 시작하기
 
Kubernetes networking: Introduction to overlay networks, communication models...
Kubernetes networking: Introduction to overlay networks, communication models...Kubernetes networking: Introduction to overlay networks, communication models...
Kubernetes networking: Introduction to overlay networks, communication models...
 
Building Microservices with gRPC and NATS
Building Microservices with gRPC and NATSBuilding Microservices with gRPC and NATS
Building Microservices with gRPC and NATS
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message Broker
 
MySQL Enterprise Edition
MySQL Enterprise EditionMySQL Enterprise Edition
MySQL Enterprise Edition
 
.Net platform .Net core fundamentals
.Net platform .Net core  fundamentals.Net platform .Net core  fundamentals
.Net platform .Net core fundamentals
 
IBM MQ: An Introduction to Using and Developing with MQ Publish/Subscribe
IBM MQ: An Introduction to Using and Developing with MQ Publish/SubscribeIBM MQ: An Introduction to Using and Developing with MQ Publish/Subscribe
IBM MQ: An Introduction to Using and Developing with MQ Publish/Subscribe
 
Cross-Cluster and Cross-Datacenter Elasticsearch Replication at sahibinden.com
Cross-Cluster and Cross-Datacenter Elasticsearch Replication at sahibinden.comCross-Cluster and Cross-Datacenter Elasticsearch Replication at sahibinden.com
Cross-Cluster and Cross-Datacenter Elasticsearch Replication at sahibinden.com
 
Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
 
Distributed Event Routing in Publish/Subscribe Systems
Distributed Event Routing in Publish/Subscribe SystemsDistributed Event Routing in Publish/Subscribe Systems
Distributed Event Routing in Publish/Subscribe Systems
 
Running MariaDB in multiple data centers
Running MariaDB in multiple data centersRunning MariaDB in multiple data centers
Running MariaDB in multiple data centers
 
ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)
 
Performance Analysis: The USE Method
Performance Analysis: The USE MethodPerformance Analysis: The USE Method
Performance Analysis: The USE Method
 
How to Upload Presentations in SlideShare and Embed in your Wordpress Blog
How to Upload Presentations in SlideShare and Embed in your Wordpress BlogHow to Upload Presentations in SlideShare and Embed in your Wordpress Blog
How to Upload Presentations in SlideShare and Embed in your Wordpress Blog
 

Viewers also liked

Windows Azure Active Directory: Identity Management in the Cloud
Windows Azure Active Directory: Identity Management in the CloudWindows Azure Active Directory: Identity Management in the Cloud
Windows Azure Active Directory: Identity Management in the Cloud
Chris Dufour
 
How to build a digital insurance company
How to build a digital insurance companyHow to build a digital insurance company
How to build a digital insurance company
Tata Consultancy Services
 
TCS Innovation Forum 2012 - Day2: May 15 and 16, Le Meridien Cambridge, MA
TCS Innovation Forum 2012 - Day2: May 15 and 16, Le Meridien Cambridge, MATCS Innovation Forum 2012 - Day2: May 15 and 16, Le Meridien Cambridge, MA
TCS Innovation Forum 2012 - Day2: May 15 and 16, Le Meridien Cambridge, MA
Tata Consultancy Services
 

Viewers also liked (20)

Azure AD Connect
Azure AD ConnectAzure AD Connect
Azure AD Connect
 
Cloud application architecture with sql azure and windows azure
Cloud application architecture with sql azure and windows azureCloud application architecture with sql azure and windows azure
Cloud application architecture with sql azure and windows azure
 
AAD with MVC App
AAD with MVC AppAAD with MVC App
AAD with MVC App
 
Leverage the Power of SAP HANA with Microsoft Azure Cloud Migration
Leverage the Power of SAP HANA with Microsoft Azure Cloud MigrationLeverage the Power of SAP HANA with Microsoft Azure Cloud Migration
Leverage the Power of SAP HANA with Microsoft Azure Cloud Migration
 
Microsoft Cloud Computing - Windows Azure Platform
Microsoft Cloud Computing - Windows Azure PlatformMicrosoft Cloud Computing - Windows Azure Platform
Microsoft Cloud Computing - Windows Azure Platform
 
Application Architecture
Application ArchitectureApplication Architecture
Application Architecture
 
Windows Azure Active Directory: Identity Management in the Cloud
Windows Azure Active Directory: Identity Management in the CloudWindows Azure Active Directory: Identity Management in the Cloud
Windows Azure Active Directory: Identity Management in the Cloud
 
Azure AD with Office 365 and Beyond!
Azure AD with Office 365 and Beyond!Azure AD with Office 365 and Beyond!
Azure AD with Office 365 and Beyond!
 
Azure Active Directory, Practical Guide
Azure Active Directory, Practical GuideAzure Active Directory, Practical Guide
Azure Active Directory, Practical Guide
 
SPOF - Single "Person" of Failure
SPOF - Single "Person" of FailureSPOF - Single "Person" of Failure
SPOF - Single "Person" of Failure
 
Getting started with Azure Active Directory
Getting started with Azure Active DirectoryGetting started with Azure Active Directory
Getting started with Azure Active Directory
 
Single point of failure
Single point of failureSingle point of failure
Single point of failure
 
Balancing Creativity with Discipline – Innovation management at TCS
Balancing Creativity with Discipline – Innovation management at TCSBalancing Creativity with Discipline – Innovation management at TCS
Balancing Creativity with Discipline – Innovation management at TCS
 
TCS PoV on Digitize
TCS PoV on DigitizeTCS PoV on Digitize
TCS PoV on Digitize
 
How to build a digital insurance company
How to build a digital insurance companyHow to build a digital insurance company
How to build a digital insurance company
 
Innovation Leadership in the Digital Age by K. Ananth Krishnan, VP and CTO, TCS
Innovation Leadership in the Digital Age by K. Ananth Krishnan, VP and CTO, TCSInnovation Leadership in the Digital Age by K. Ananth Krishnan, VP and CTO, TCS
Innovation Leadership in the Digital Age by K. Ananth Krishnan, VP and CTO, TCS
 
TCS Innovation Forum 2012 - Day2: May 15 and 16, Le Meridien Cambridge, MA
TCS Innovation Forum 2012 - Day2: May 15 and 16, Le Meridien Cambridge, MATCS Innovation Forum 2012 - Day2: May 15 and 16, Le Meridien Cambridge, MA
TCS Innovation Forum 2012 - Day2: May 15 and 16, Le Meridien Cambridge, MA
 
Digital Blurring Business Boundaries
Digital Blurring Business BoundariesDigital Blurring Business Boundaries
Digital Blurring Business Boundaries
 
Transforming Enterprises through Next-generation Cloud Applications
Transforming Enterprises through Next-generation Cloud ApplicationsTransforming Enterprises through Next-generation Cloud Applications
Transforming Enterprises through Next-generation Cloud Applications
 
Digital Insurance Enterprise: The Nest Case Study
Digital Insurance Enterprise: The Nest Case StudyDigital Insurance Enterprise: The Nest Case Study
Digital Insurance Enterprise: The Nest Case Study
 

Similar to Publish & Subscribe to events using an Event Aggregator

Test DB user
Test DB userTest DB user
Test DB user
techweb08
 
test validation
test validationtest validation
test validation
techweb08
 
Mail tracker mini
Mail tracker miniMail tracker mini
Mail tracker mini
pendyam
 

Similar to Publish & Subscribe to events using an Event Aggregator (20)

Design Patterns - Distributed Publisher-Subscriber Network
Design Patterns - Distributed Publisher-Subscriber NetworkDesign Patterns - Distributed Publisher-Subscriber Network
Design Patterns - Distributed Publisher-Subscriber Network
 
Java Messaging Services
Java Messaging ServicesJava Messaging Services
Java Messaging Services
 
Test DB user
Test DB userTest DB user
Test DB user
 
test validation
test validationtest validation
test validation
 
Newsletter Popup User Guide (Full version)
Newsletter Popup User Guide (Full version)Newsletter Popup User Guide (Full version)
Newsletter Popup User Guide (Full version)
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
test
testtest
test
 
JMS
JMSJMS
JMS
 
Distributed System-Multicast & Indirect communication
Distributed System-Multicast & Indirect communicationDistributed System-Multicast & Indirect communication
Distributed System-Multicast & Indirect communication
 
Drupal & Simplenews
Drupal & SimplenewsDrupal & Simplenews
Drupal & Simplenews
 
Publish Subscribe pattern - Design Patterns
Publish Subscribe pattern - Design PatternsPublish Subscribe pattern - Design Patterns
Publish Subscribe pattern - Design Patterns
 
Mail tracker mini
Mail tracker miniMail tracker mini
Mail tracker mini
 
A Complete Guide to Email Studio and Journey Builder.pdf
A Complete Guide to Email Studio and Journey Builder.pdfA Complete Guide to Email Studio and Journey Builder.pdf
A Complete Guide to Email Studio and Journey Builder.pdf
 
Message Stack in Drupal
Message Stack in DrupalMessage Stack in Drupal
Message Stack in Drupal
 

More from Lars-Erik Kindblad

Application Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, CapgeminiApplication Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, Capgemini
Lars-Erik Kindblad
 

More from Lars-Erik Kindblad (13)

Application Architecture April 2014
Application Architecture April 2014Application Architecture April 2014
Application Architecture April 2014
 
How to build more reliable, robust and scalable distributed systems
How to build more reliable, robust and scalable distributed systemsHow to build more reliable, robust and scalable distributed systems
How to build more reliable, robust and scalable distributed systems
 
Message Oriented Architecture using NServiceBus
Message Oriented Architecture using NServiceBusMessage Oriented Architecture using NServiceBus
Message Oriented Architecture using NServiceBus
 
Unit Tests are Overrated (NDCOslo 2013)
Unit Tests are Overrated (NDCOslo 2013)Unit Tests are Overrated (NDCOslo 2013)
Unit Tests are Overrated (NDCOslo 2013)
 
The Single Responsibility Principle
The Single Responsibility PrincipleThe Single Responsibility Principle
The Single Responsibility Principle
 
Avoid code duplication! Principles & Patterns
Avoid code duplication! Principles & PatternsAvoid code duplication! Principles & Patterns
Avoid code duplication! Principles & Patterns
 
Application Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, CapgeminiApplication Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, Capgemini
 
The Fluent Interface Pattern
The Fluent Interface PatternThe Fluent Interface Pattern
The Fluent Interface Pattern
 
Inversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best PracticeInversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best Practice
 
Layered Software Architecture
Layered Software ArchitectureLayered Software Architecture
Layered Software Architecture
 
Introduction to FluentData - The Micro ORM
Introduction to FluentData - The Micro ORMIntroduction to FluentData - The Micro ORM
Introduction to FluentData - The Micro ORM
 
Dependency Injection vs Service Locator - Best Practice
Dependency Injection vs Service Locator - Best PracticeDependency Injection vs Service Locator - Best Practice
Dependency Injection vs Service Locator - Best Practice
 
Data Access - Best Practice
Data Access - Best PracticeData Access - Best Practice
Data Access - Best Practice
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Publish & Subscribe to events using an Event Aggregator