Top Banner
http ://particular.net Introduction to NServiceBus and the Particular Platform Mauro Servienti Solution Architect @ Particular Software
30

Designing distributed, scalable and reliable systems using NServiceBus

Jul 16, 2015

Download

Software

Mauro Servienti
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Designing distributed, scalable and reliable systems using NServiceBus

http://particular.net

Introduction to NServiceBusand the Particular Platform

Mauro Servienti

Solution Architect @ Particular Software

Page 2: Designing distributed, scalable and reliable systems using NServiceBus

Mauro Servienti

Solution Architect @ [email protected]

@mauroservienti

//milestone.topics.it

Microsoft MVP - Visual C#

Page 3: Designing distributed, scalable and reliable systems using NServiceBus

Learn to build better systemsfrom Udi Dahan

Advanced Distributed Systems Design

2 days (out of 5) for FREE

Join us at the Particular booth

for more information

Page 4: Designing distributed, scalable and reliable systems using NServiceBus

Agenda

• What is it all about?

• Long running workflows: what if you need state?

• Async monitoring of async processes

• What if something goes wrong?

Page 5: Designing distributed, scalable and reliable systems using NServiceBus

Tenets

• NServiceBus is built around and enforces the following tenets:

• Boundaries are explicit

• Services are autonomous

• Services share schema & contract, not class

• Service compatibility is based upon policy

Page 6: Designing distributed, scalable and reliable systems using NServiceBus

Messages, commands and events

• Messages:• An atomic piece of information;• Used to drive the system forward;

• Commands:• Are imperative messages;• Are directed to a well known receiver;

• Events:• Are an immutable representation of something that occurred in the past;• Are directed to anyone interested;

• Commands and Events are messages with a semantic meaning:• NServiceBus enforces the semantic of commands and events;

Page 7: Designing distributed, scalable and reliable systems using NServiceBus

Messaging patterns

Page 8: Designing distributed, scalable and reliable systems using NServiceBus

Request / Response

• A message is sent to a destination;

• The receiver of the message can reply back;

• The sender knows the receiver perfectly:• Knows where the receiver is;

• Knows what to send;

• The receiver:• Does not necessarily know where the sender is;

• Knows what the sender expects: what to reply;

• There is coupling between the sender and the receiver;

Page 9: Designing distributed, scalable and reliable systems using NServiceBus

Publish / Subscribe

• An actor in the system acted on something:• The actor can broadcast an event to the entire system;

• The publisher is not interested in who is interested in the event;

• Another actor in the system can be interested in an event:• The actor will subscribe to the interesting event(s);

• The intent is on the subscriber’s side;• The subscriber knows the publisher, not the other way round;

• The publisher will deliver a copy of the event to each subscriber;

• There is less coupling between the publisher and the subscriber;

Page 10: Designing distributed, scalable and reliable systems using NServiceBus

Message handlerswhat can we do with messages?

Page 11: Designing distributed, scalable and reliable systems using NServiceBus

Handling messages

• Each time a message is received a handler is invoked;

• A handler is the “container” (class) that hosts our code;

• A handler is stateless:• Each time a message is received a new handler is created and invoked;

Page 12: Designing distributed, scalable and reliable systems using NServiceBus

Endpoints & HostingHandlers home

Page 13: Designing distributed, scalable and reliable systems using NServiceBus

Where do handlers live?

• Handlers are grouped by service (a logical concept);

• Services are hosted in Endpoints;

• Endpoint instances run on Windows machines:• As Windows Services:

• Can be self hosted;

• Can leverage the NServiceBus.Host;

• Self-hosted in any application type, web, console, WPF, etc…;

Page 14: Designing distributed, scalable and reliable systems using NServiceBus

Demo

Page 15: Designing distributed, scalable and reliable systems using NServiceBus

Recap

• We saw what Endpoints, Messages and Handlers are;

• How to configure an endpoint using the BusConfiguration;

• How to exchange messages:• using the request/response pattern;

• using the publish/subscribe pattern;

• How message routing works;

Page 16: Designing distributed, scalable and reliable systems using NServiceBus

What about the transport?

Page 17: Designing distributed, scalable and reliable systems using NServiceBus

Supported transports

Transports needs be durable and reliable

in order to guarantee delivery

• MSMQ

• RabbitMQ

• Sql Server

• Azure ServiceBus

• Azure Storage Queues

Page 18: Designing distributed, scalable and reliable systems using NServiceBus

What if you need state?Long running workflows

Page 19: Designing distributed, scalable and reliable systems using NServiceBus

Sagas

• Sagas are durable, state full, reliable workflows:• Can be scaled out;

• Can survive failures;

• Are highly available and fault tolerant;

• Sagas guarantee state persistence across message handling;• Guarantee state consistency in a scaled out environment;

• Allow to express message and state correlation;

• Empower “timeouts” to make decisions in an async world;

Page 20: Designing distributed, scalable and reliable systems using NServiceBus

Demo

Page 21: Designing distributed, scalable and reliable systems using NServiceBus

Recap

• Persistence can be:• RavenDB;

• any RDBMS via NHibernate;

• Azure Storage Tables;

• Sagas:• Are orchestrators that coordinate the work among multiple endpoints;

• Can be started by commands or events;

• Can be started by multiple messages;

Page 22: Designing distributed, scalable and reliable systems using NServiceBus

Async monitoring…of async processes

Page 23: Designing distributed, scalable and reliable systems using NServiceBus

Auditing

• In a system composed of multiple actors can be easy to lose control:• Of the overall status of the system;

• Of the status of each actor in the system, especially if distributed;

• NServiceBus has auditing ‘on’ by default via “Audit” queues;• An audit queue is just a queue;

• ServiceControl is the under the hood tool that monitors Audit queues;

• ServiceInsight is one of the monitoring tools we supply;

Page 24: Designing distributed, scalable and reliable systems using NServiceBus

Demo

Page 25: Designing distributed, scalable and reliable systems using NServiceBus

Recap

• ServiceInsight is a Developer / DevOps tool:• Provides debugging capabilities;

• Can be connected to live environments controlled by ServiceControl;

Page 26: Designing distributed, scalable and reliable systems using NServiceBus

If something goes wrong?Design with failure in mind

Page 27: Designing distributed, scalable and reliable systems using NServiceBus

Handling async failures can be hard

• When a system is driven by messages we cannot lose anything:• Losing a message equals to a corrupted system;

• We need to face 2 main types of error:• transient failures;• business errors;

• If a message fails:• -> First level retries;• -> Second Level retries;• -> Error queue;

• ServiceControl is the under the hood tool that monitors error queues;

• ServicePulse is the Ops / DevOps monitoring tool;

Page 28: Designing distributed, scalable and reliable systems using NServiceBus

Demo

Page 29: Designing distributed, scalable and reliable systems using NServiceBus

Recap

• That wasn't so hard;

• ServicePulse is the monitoring tool to monitor the entire system;

• The system itself can react to failures using ServiceControl events;

Page 30: Designing distributed, scalable and reliable systems using NServiceBus

Q&AThanks