Top Banner
INTRODUCTION TO NSERVICEBUS Adam Fyles Solution Architect AdamFyles.blogspot.com
25

Introduction to NServiceBus

Jul 02, 2015

Download

Technology

Adam Fyles

Introduction to the open source ESB NServiceBus
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: Introduction to NServiceBus

INTRODUCTION TO

NSERVICEBUSAdam Fyles

Solution Architect

AdamFyles.blogspot.com

Page 2: Introduction to NServiceBus

Why use a service bus?

• Definition

• “a software architecture construct which provides fundamental

services for complex architectures via an event-driven and

standards-based messaging engine (the bus).” – Wikipedia

• Building Systems vs. Applications

Application

System

Page 3: Introduction to NServiceBus

The 8 fallacies of distributed computing

1. The network is reliable

2. Latency isn‟t a problem

3. Bandwidth isn‟t a problem

4. The network is secure

5. The topology won‟t change

6. The administrator will know what to do

7. Transport cost isn‟t a problem

8. The network is homogeneous

• Deutsch „94, Gosling „97

Page 4: Introduction to NServiceBus

Coupling

• Platform• Interoperability matters( Fallacy #8 )

• Proprietary vs. Standard protocols

• Schema & Contract – XML

• Spatial• Server A relies on Server B

• Can communication continue?

• Store & Forward

• Temporal• The processing of B affects that of A

• Request/Response

• Asynchronous Messaging

Windows Linux

RPC

Page 5: Introduction to NServiceBus

Scalability & Flexibility

• Flexibility

• What about upgrades?

• What about virtualization?

• Scalability

• Scaling Up vs. Out – don‟t get stuck with one option

• The Grid – work distribution

Page 6: Introduction to NServiceBus

Messaging to the Rescue!

• Communication between services and Endpoints is

described by message patterns

• Durable

• Flexible

• Unidirectional – non-blocking

• Less coupling

• NServiceBus provides several messaging patterns out of

the box, but allows for the composition and/or creation of

new patterns

Page 7: Introduction to NServiceBus

Example

Transaction

DB

Queue

App

Order

RollbackRollback

Call 1 of 3

Call 2 of 3

Order is back in the queue

Page 8: Introduction to NServiceBus

Endpoint

NSB Process Flow Overview

Scan /bin for Types

Configuration

Wait for Messages

Scan IoC & Dispatch Handlers

• IWantCustomLogging

• IProfile

• IConfigureThisEndPoint

• AsA_Server

• IWantToRunAtStartup

• IMessage

• ISpecifyMessageOrderHandling

• IHandleMessages<T>

Page 9: Introduction to NServiceBus

Generic Host

NServiceBus.Host.exe

Page 10: Introduction to NServiceBus

Point to Point

2

BusClient

Bus

Server

Bus.Send()

Page 11: Introduction to NServiceBus

Point to Point Configuration

Client

class EndPointConfig : IConfigureThisEndpoint, AsA_Client{ }

<UnicastBusConfig><MessageEndpointMappings><add Messages="MyMessages“ Endpoint="MyServerInputQueue" />

</MessageEndpointMappings></UnicastBusConfig>

Server

class EndPointConfig : IConfigureThisEndpoint, AsA_Server{ }

<MsmqTransportConfig InputQueue="MyServerInputQueue" />

Page 12: Introduction to NServiceBus

Point to Point Demo

Page 13: Introduction to NServiceBus

Bus

Bus

Request & Response

3

Client

Server

Bus.Send(), Bus.Reply()

Page 14: Introduction to NServiceBus

Bus

Publish & Subscribe

5

Subscription

Storage

Publisher

BusSubscriber

Bus

Subscriber

Bus

Subscriber

Bus.Publish(), Bus.Subscribe(), Bus.Unsubscribe()

Page 15: Introduction to NServiceBus

Pub/Sub ConfigurationSubscriber

class EndPointConfig : IConfigureThisEndpoint, AsA_Server{ }

<MsmqTransportConfig InputQueue=Subscriber1InputQueue" />

<UnicastBusConfig><MessageEndpointMappings><add Messages="MyMessages" Endpoint=" MyPublisherInputQueue" />

</MessageEndpointMappings></UnicastBusConfig>

Publisher

class EndPointConfig : IConfigureThisEndpoint, AsA_Publisher{ }

<MsmqTransportConfig InputQueue="MyPublisherInputQueue />

Page 16: Introduction to NServiceBus

Pub/Sub Demo

Page 17: Introduction to NServiceBus

Scaling Out

Page 18: Introduction to NServiceBus

Distributor

2

Work

ManagementDistributor

Bus

Worker

Bus

Worker

Bus

Worker

Page 19: Introduction to NServiceBus

Distributor Config<appSettings><add key="NumberOfWorkerThreads" value="1"/><!-- queue that the distributor process reads and feeds to workers --><add key="DataInputQueue" value="nservicebus_distributor_data_bus"/>

<!--queue that manages work distribution --><add key="ControlInputQueue“

value="nservicebus_distributor_control_bus"/>

<!-- errors --><add key="ErrorQueue" value="nservicebus_error"/>

<!-- queue that maintains the state(availability) of the workers --><add key="StorageQueue" value="nservicebus_distributor_storage"/>

<!-- relevant for a Serialization of "interfaces" or "xml" --><add key="NameSpace" value="http://www.MySite.com"/>

<add key="Serialization" value="xml"/><!-- can be either "xml", or "binary" -->

</appSettings>

Page 20: Introduction to NServiceBus

Demo

Page 21: Introduction to NServiceBus

Long Running Workflows(Sagas)

Page 22: Introduction to NServiceBus

Saga(Workflow)

22

State

Persistence

Main

Business

ProcessBus

Sub

Process

3

Bus

Sub

Process

1 Bus

Sub

Process 2

Are we done yet?

Page 23: Introduction to NServiceBus

Saga ConfigurationServer

class EndPointConfig : IConfigureThisEndpoint, AsA_Server{ }

<MsmqTransportConfig InputQueue=MySagaInputQueue" />

<UnicastBusConfig><MessageEndpointMappings><add Messages="MyMessages" Endpoint="MyDestinationInputQueue" /><add Messages=“NServiceBus.Saga.TimeoutMessage” Endpoint=“timeoutmanager” />

</MessageEndpointMappings></UnicastBusConfig>

<NHibernateSagaPersisterConfig><NHibernateProperties>

<add Key="connection.provider“ Value="NHibernate.Connection.DriverConnectionProvider"/>

<add Key="connection.driver_class" Value="NHibernate.Driver.SqlClientDriver"/><add Key="connection.connection_string" Value="Server=localhost;initial

catalog=NServiceBus;Integrated Security=SSPI"/><add Key="dialect" Value="NHibernate.Dialect.MsSql2000Dialect"/>

</NHibernateProperties></NHibernateSagaPersisterConfig>

Page 24: Introduction to NServiceBus

Summary

• The Bus architectural style typically prompts more

questions

• What happens if communication fails?

• How long can it take for a process to complete?

• What is my process dependent on and what depends on my

process?

• Is ok to lose an order(or other entity)?

• Is this truly a domain event?

• NServiceBus provides the plumbing, you must provide the

System

Page 25: Introduction to NServiceBus

THANK YOUAdam Fyles

Solution Architect

AdamFyles.blogspot.com

GitHub.com/afyles

NServiceBus.com

Credits: Udi Dahan, NSB Author