SlideShare une entreprise Scribd logo
1  sur  67
NServicebus
Rich Helton
June 14, 2012
Buy “Mastering NServiceBus
with Persitence”
Introduction
•By using the .NET 4 Framework, with the
combination of the Windows Communication
Framework (WCF), Workflow (WF), Model-
View-Controller (MVC3), Entity Frameworks
(EF4), Azure, AppFabric, and Message Queuing,
I believe that Microsoft has brought serious
competition to compete against the entire
spectrum of all other Enterprise Development
Systems.
Introduction 2
•Now Microsoft systems can be virtualized to
be decoupled form the hardware, be stripped
down to run minimum services for the
applications, and have many diagnostic and
management tools.
•This turns the Operating System into an
Application Server to be reckoned with from
the Application Server vendors.
•This could also creates software quality that
was never as common as it is now in the
Industry, see
The need for ESB
•An ESB, is a software architecture model used
for designating and implementing the
interaction and communication between
mutually interacting software applications in
Service Oriented Architecture,
http://en.wikipedia.org/wiki/Enterprise_service
_bus
The need for ESB
•The Bus, is the combination of software that
queues messages, routes messages and
processes messages to the correct endpoints.
•In order to do this ESB software will usually
use other frameworks that handle message
queuing and standard message queuing
mechanisms.
•For instance, NServiceBus can use RabbitMQ
or MSMQ.
Some benefits of ESB
•The message bus provides both
standardization and integration of messages
across an enterprise.
•A message could be sent from any endpoint,
be it a database or service, and the messages
are routed and interpreted to other services
through the bus.
•The services could be redundant as they could
come from any endpoint.
•Even though the messages could be complex
NServiceBus
•NServiceBus is an Open Source Enterprise
Service Bus for .Net, http://nservicebus.com/
•Commercial licenses are required based on
messages per second,
http://nservicebus.com/License.aspx
•For the basic code, it can be pulled from
https://github.com/NServiceBus/NServiceBus
Other Choices
•There are many ESB choices, but price and
documentation, including blogs and samples
usually drive my choice.
•For .NET, there is additionally BizTalk,
MassTransit, KeystrokeESBNet and
SimpleServiceBus.
•There are many sites like
http://en.wikipedia.org/wiki/Comparison_of_b
usiness_integration_software
AppFabric
•Adding a caching provider and a monitoring
service to WCF and WF creates the Microsoft
AppFabric Framework and Architecture.
•There is a special version that supports Azure.
•The Micrsoft.ServiceBus.dll and namespace
will be used to extend Service Bus helper
extensions to WCF and WF.
Biztalk
•Biztalk uses a Micrsoft ESB Toolkit to build ESB.
This Toolkit intergrates into Visual Studio 2010.
http://technet.microsoft.com/en-
us/library/ff699598.aspx
•NServiceBus also has modeling and Code
Snippets that integrate into Visual Studio 2010
as well, more work has been done into Visual
Studio 11.
Other Choices
•Even other choices include not to utilize ESBs
at all, but use other technology like Windows
Communication Foundation Workflow Services
for SOA Binding Services and MSMQ as a
message queue system to build a message
system.
•But standard Message Queue and ESB
frameworks provide the pieces that are already
built and tested.
•The downside is that you may be locked into
the technology and the roadmap that the
NServiceBus
•NServiceBus is an Open Source Enterprise
Service Bus for .Net, http://nservicebus.com/
•Commercial licenses are required based on
messages per second,
http://nservicebus.com/License.aspx
•For the basic code, it can be pulled from
https://github.com/NServiceBus/NServiceBus
NServiceBus-
Intro
Getting Started
•The benefit of using a ESB package is that it
will normally handle the messaging packages
for you, NServiceBus handles a lot of the
MSMQ and DTC complexities.
•See
http://nservicebus.com/GettingStarted.aspx ,
http://nservicebus.com/GettingStarted2.aspx
http://nservicebus.com/GettingStarted3.aspx
Getting Started
•The installation is usually just running the
RunMeFirst.bat file with the correct
Administrator permissions.
Getting Started
•You will be prompted to install NServiceBus
Studio for building NServieBus projects in
Visual Studio, this plugin is found under /tools:
NServiceBusStudio
•See http://www.i-m-
code.com/blog/blog/2012/03/15/nservicebus-
vs-modeling-tools/
•Also an example on
http://nservicebus.com/GettingStarted.aspx
Core Files
•There are many libraries included with
NServiceBus, some for custom configs, and
many samples to include from GitHub, but
basic 4 libraries included for almost all apps
are; log4net.dll, NServiceBus.Core.dll,
NSeviceBus.dll, and NServiceBus.Host.exe.
•NServiceBus is heavily reliant on Apache’s
log4net for default logging and the correct
version must be installed.
Endpoint
•Normally every NServiceBus has one Endpoint,
which is the Queue name to read or write
messages.
•If not defined, by default, the current
namespace of the project will be used. This
method is sometimes used on Servers reading
queues.
•The name will be followed by an “@” with a
servername to be server specific.
Endpoint
•There are different conventions and ways to
define an Endpoint, I found that this will also
depend on the version of NServiceBus being
used,
http://andreasohlund.net/2012/01/27/convent
ion-over-configuration-in-nservicebus-3-0/
Endpoint – FullDuplex Example
•App.config will normally define the endpoint
in the UnicastBusConfig, here we define the
Message as well in the Client:
Endpoint – FullDuplex Example
•Instead of using App.config, the configuration
can be programmatic by building a class using
IProviderConfiguration:
Endpoint from different places
•So, we could put a UnicastConfigBusConfig, for
messages and an endpoint in an App.config,
and a MessageForwardingInCaseOfConfig like
so:
How do the different configs come
together
•The purpose of all the configs is simply to build
an IBus instance to send or receive the
messages.
•The Bus is normally created by a Handler or
building the bus directly with an arrangement
of Builder calls.
A sample Builder for SendOnly
•Note : The order of which calls happen first
can change the functionality.
•This allows tighter control of the Bus.
A sample Handler for a Reply
Send versus Publish
•After the Bus is built with the configs and
handlers, the clients and server need to Send,
Publish or Reply to messages.
•See http://mookid.dk/oncode/archives/807 ,
NServiceBus for Dummies who want to be
Smarties for some of the differences.
Send with a Destination Server as
it sends
•Notice the “someserver”:
Building the IBus
Start with the Builders
•We will start with Configure.With() from and a
builder type:
•The builders can be Defaultbuilder(),
AutoFacBuilder(), CastleWindsorBuilder(),
NinjectBuilder(), SpringBuilder(),
StructureMapBuilder(), and UnityBuilder().
Information on Builders
•These Builder Objects are the containers in
which to build the bus and configurations.
http://nservicebus.com/Containers.aspx
•First the configurations will be declared for
endpoints, transactional, type of container and
then the CreateBus() and Start() will initiate the
bus.
Types of Builders/Containers
•AutofacBuilder() – is the default container,
same as DefaultBuilder() , that will use internal
extensions in NServiceBus.
•CastleWindsorBuilder() – Castle Windsor is an
Inversion of Control container.
http://en.wikipedia.org/wiki/Castle_Project
•NinjectBuilder() – A Inversion of Control
container, sometimes called the ninja of
dependency injectors,
http://ninject.codeplex.com/wikipage?title=Wh
Types of Builders/Containers
•SpringBuilder() – A Inversion of Control
container for Spring.net.
http://www.springframework.net/
•StructureMapBuilder () – A Inversion of
Control container for StructureMap,
http://docs.structuremap.net/.
•UnityBuilder() – A Inversion of Control
container, Dependency Injection container from
Microsoft. http://msdn.microsoft.com/en-
us/library/dd203101.aspx
Next is normally the Serializers
•Next is normally the Serializers, this will
transfer the message as binary or xml data.
•XmlSerializer() – Serializes the objects into an
XML format, but there are limitations with the
XML serialization in NServiceBus with object
lists, Derived Objects, and arrays of objects,
http://stackoverflow.com/questions/2816895/
nservicebus-serization-issue-of-derived-types ,
the work around is to use the Binary
Next is normally the Serializers
•BinarySerializer() – Serializes the objects into
an binary format, and is done with the standard
.net binary serializer,
http://nservicebus.com/Performance.aspx
•JSonSerializer() – Javascript Object Notation
(JSON) format serialization, uses the
Newtonsoft.json interface,
http://json.codeplex.com/ .
Next is normally the Transport
•Next is normally the Transport, this is the
queuing mechanism, and in many cases will be
MSMQ.
•Transports can be created using
ISendMessages and IReceiveMessages. A
Service Broker example can be seen in
NserviceBus-Contrib that includes a Sample
https://github.com/NServiceBus/NServiceBus-
Contrib
Transport Types
•MsmqTransport() – This is the MSMQ
Transport mechanism commonly used, there
are many samples, see FullDuplex example.
•FtpTransport() – This is a Transport to send
messages across FTP, which has to have a
directory, username and password included for
FTP setup, see the FtpSample.
•AzureQueueMessage() – Using Storage
Queues for Azure, see the Azure examples.
UnicastBusConfig
•Now UnicastBus() must be defined:
•UnicastBus() tells NServiceBus to use unicast
messaging. Used out of the box, see
http://nservicebus.com/SelfHosting.aspx
•Here we have a UnicastBusConfig defining the
message and endpoint in App.config client:
Now for the Bus
•So far these have only been configurations and
the bus still hasn't been created, to create the
bus, CreateBus() must be used, and to start the
bus, then Start() must be used,
For SendOnly
•For SendOnly(), createbus and start are not
needed because not all the components are
needed from the bus.
Publish with
Installers
Why I looked at SendOnly
•I started looking at SendOnly because Publish
was not recommended for the Web interfaces.
http://www.make-
awesome.com/2010/10/why-not-publish-
nservicebus-messages-from-a-web-application/
•Publishing requires a Subscription storage and
the messages are normally handled as
transactional events,
http://nservicebus.com/PubSubApiAndConfigu
ration.aspx
Subscription Storage
•If multiple machines share the same
subscription storage, then Database Storage
needs to be used, .DBSubscriptionStorage().
•The Nhibernate connection strings will need to
be defined in the App.config.
Subscription Storage
•If multiple machines share the same
subscription storage, then Database Storage
needs to be used, .DBSubscriptionStorage().
•The Nhibernate connection strings will need to
be defined in the App.config.
Subscription Storage
•If multiple machines share the same
subscription storage, then Database Storage
needs to be used, .DBSubscriptionStorage().
•The Nhibernate connection strings will need to
be defined in the App.config.
Subscription Storage
•The Manufacturing Example shows an MSMQ
Storage example and in memory:
Installers
•In the Manufacturing and AsyncPages, there is
the Install() for the installation of endpoints
and infrastructure, such as MSMQ and
RavenDB.
•See
http://andreasohlund.net/2012/01/26/installer
s-in-nservicebus-3-0/
MSMQ
NServiceBus supports many types
of messaging Schemes
•NServiceBus supports messaging through
databases, like its native RavenDB, or SQL
Server.
•It also supports Message Queuing mechanisms
like Microsoft Message Queue and Apache’s
RabbitMQ.
MSMQ
•MSMQ is the Message Queuing System built
into the Microsoft Operating System since
1997.
•The Server Operating Systems, like Windows
Server 2008, offers additional features.
•See
http://en.wikipedia.org/wiki/Microsoft_Messag
e_Queuing
Viewing MSMQ
•It is important to administer the MSMQ
Queues when building MSMQ applications. If
the Queue is not built, the application could
error.
•The Queue will normally store its data in XML
or Binary form. XML makes the data readable
for troubleshooting.
Viewing MSMQ
•While there is the Visual Studio View Servers,
he MSMQ MMC, and even the Computer
Management way to view Queues.
•I still like to use IMQT to view the XML, a
commercial tool is Queue Explorer. IMQT is
http://utvecklargodis.blogspot.com/2007/03/m
smq-management-tool.html
Viewing MSMQ in Visual Studio
Viewing MSMQ in IMQT
Programming MSMQ
•Windows will use the System.Message
namespace to program the MessageQueue
class.
•NServiceBus offers extensions of this class as
MSMQUtilities for managing Queues and
MSMQInstallation for installing MSMQ.
•These are in the NServiceBus.Utils namespace,
found in the NServiceBus.Utils.dll.
•Code for MSMQUtilities can be found at
https://github.com/NServiceBus/NServiceBus/
Programming MSMQ
•Here is a small example to check if a Queue is
built, and if not build it with the Administrator
username using both System and NServiceBus
Utils for the client, the server should create its
own queue by default:
Unit Tests
Unit Testing
•NServiceBus normally uses NUnit to test with
handlers that it already has built in for Sends
and Publish. Nunit can be found at
http://www.nunit.org/
•The code for the Handlers can be found at
https://github.com/NServiceBus/NServiceBus/
blob/master/src/testing/Handler.cs
Unit Testing
•To test Nunit in Visual Studio, you will likley
need to install a plugin like TestDriven.Net,
Resharper, or Ncoverage., and the nunit
framework will have to be installed.
Handlers
•Here’s what a typical Test Handler looks like to
test if the message and header is validated:
MOQ
•Another choice besides using the NServiceBus
custom handlers is to use MOQ.
•MOQ is used to mockup a bus, MOQ came
from http://code.google.com/p/moq/
•There are many links for doing this, one with
some sample test code can be found at
http://pastebin.com/CSrN6fR1
Deploying
Installing NServiceBus as Service
•It was mentioned earlier that
NServiceBus.Host.Exe is one of the 4 files to
always be included with NServiceBus.
•This is the file used for running NServiceBus
applications that are non-Console based.
•This file is used for installing, running and
debugging NServiceBus applications.
•See http://nservicebus.com/GenericHost.aspx
NServiceBus.Host.exe debug
•NServiceBus.Host.Exe is needed to debug the
applications:
NServiceBus.Host.exe commands
•A service can be created at the command line
by using NServiceBus.Host.exe /install /serviceName:MyServer.dll
/displayName:"My Super Duper service" /description:"My server
installed by NService Magic”
•See
http://prashantbrall.wordpress.com/tag/nservi
cebus/ for further details on doing this.
Questions?
Appendix

Contenu connexe

Tendances

Istio Service Mesh
Istio Service MeshIstio Service Mesh
Istio Service MeshLuke Marsden
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architectureAbdelghani Azri
 
Oracle DB를 AWS로 이관하는 방법들 - 서호석 클라우드 사업부/컨설팅팀 이사, 영우디지탈 :: AWS Summit Seoul 2021
Oracle DB를 AWS로 이관하는 방법들 - 서호석 클라우드 사업부/컨설팅팀 이사, 영우디지탈 :: AWS Summit Seoul 2021Oracle DB를 AWS로 이관하는 방법들 - 서호석 클라우드 사업부/컨설팅팀 이사, 영우디지탈 :: AWS Summit Seoul 2021
Oracle DB를 AWS로 이관하는 방법들 - 서호석 클라우드 사업부/컨설팅팀 이사, 영우디지탈 :: AWS Summit Seoul 2021Amazon Web Services Korea
 
Serverless with IAC - terraform과 cloudformation 비교
Serverless with IAC - terraform과 cloudformation 비교Serverless with IAC - terraform과 cloudformation 비교
Serverless with IAC - terraform과 cloudformation 비교재현 신
 
Building .NET Microservices
Building .NET MicroservicesBuilding .NET Microservices
Building .NET MicroservicesVMware Tanzu
 
Windows 開発者のための Dev&Ops on AWS
Windows 開発者のための Dev&Ops on AWSWindows 開発者のための Dev&Ops on AWS
Windows 開発者のための Dev&Ops on AWSAmazon Web Services Japan
 
The Journey to DevOps #MFSummit2017
The Journey to DevOps #MFSummit2017The Journey to DevOps #MFSummit2017
The Journey to DevOps #MFSummit2017Micro Focus
 
Ch6 대용량서비스레퍼런스아키텍처 part.1
Ch6 대용량서비스레퍼런스아키텍처 part.1Ch6 대용량서비스레퍼런스아키텍처 part.1
Ch6 대용량서비스레퍼런스아키텍처 part.1Minchul Jung
 
Building Bizweb Microservices with Docker
Building Bizweb Microservices with DockerBuilding Bizweb Microservices with Docker
Building Bizweb Microservices with DockerKhôi Nguyễn Minh
 
CI/CD for React Native
CI/CD for React NativeCI/CD for React Native
CI/CD for React NativeJoao Marins
 
Containers orchestrators: Docker vs. Kubernetes
Containers orchestrators: Docker vs. KubernetesContainers orchestrators: Docker vs. Kubernetes
Containers orchestrators: Docker vs. KubernetesDmitry Lazarenko
 

Tendances (20)

Istio Service Mesh
Istio Service MeshIstio Service Mesh
Istio Service Mesh
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
Oracle DB를 AWS로 이관하는 방법들 - 서호석 클라우드 사업부/컨설팅팀 이사, 영우디지탈 :: AWS Summit Seoul 2021
Oracle DB를 AWS로 이관하는 방법들 - 서호석 클라우드 사업부/컨설팅팀 이사, 영우디지탈 :: AWS Summit Seoul 2021Oracle DB를 AWS로 이관하는 방법들 - 서호석 클라우드 사업부/컨설팅팀 이사, 영우디지탈 :: AWS Summit Seoul 2021
Oracle DB를 AWS로 이관하는 방법들 - 서호석 클라우드 사업부/컨설팅팀 이사, 영우디지탈 :: AWS Summit Seoul 2021
 
Serverless with IAC - terraform과 cloudformation 비교
Serverless with IAC - terraform과 cloudformation 비교Serverless with IAC - terraform과 cloudformation 비교
Serverless with IAC - terraform과 cloudformation 비교
 
MicroServices on Azure
MicroServices on AzureMicroServices on Azure
MicroServices on Azure
 
Automation CICD
Automation CICDAutomation CICD
Automation CICD
 
Windows Azure Service Bus
Windows Azure Service BusWindows Azure Service Bus
Windows Azure Service Bus
 
Packer by HashiCorp
Packer by HashiCorpPacker by HashiCorp
Packer by HashiCorp
 
Building .NET Microservices
Building .NET MicroservicesBuilding .NET Microservices
Building .NET Microservices
 
Blazor and more.pptx
Blazor and more.pptxBlazor and more.pptx
Blazor and more.pptx
 
Windows 開発者のための Dev&Ops on AWS
Windows 開発者のための Dev&Ops on AWSWindows 開発者のための Dev&Ops on AWS
Windows 開発者のための Dev&Ops on AWS
 
Presentation-DEVOPS-par-GDG
Presentation-DEVOPS-par-GDGPresentation-DEVOPS-par-GDG
Presentation-DEVOPS-par-GDG
 
The Journey to DevOps #MFSummit2017
The Journey to DevOps #MFSummit2017The Journey to DevOps #MFSummit2017
The Journey to DevOps #MFSummit2017
 
Zimbra
ZimbraZimbra
Zimbra
 
Ch6 대용량서비스레퍼런스아키텍처 part.1
Ch6 대용량서비스레퍼런스아키텍처 part.1Ch6 대용량서비스레퍼런스아키텍처 part.1
Ch6 대용량서비스레퍼런스아키텍처 part.1
 
Building Bizweb Microservices with Docker
Building Bizweb Microservices with DockerBuilding Bizweb Microservices with Docker
Building Bizweb Microservices with Docker
 
CI/CD for React Native
CI/CD for React NativeCI/CD for React Native
CI/CD for React Native
 
CQRS & EVS with MongoDb
CQRS & EVS with MongoDbCQRS & EVS with MongoDb
CQRS & EVS with MongoDb
 
Azure Messaging Services #1
Azure Messaging Services #1Azure Messaging Services #1
Azure Messaging Services #1
 
Containers orchestrators: Docker vs. Kubernetes
Containers orchestrators: Docker vs. KubernetesContainers orchestrators: Docker vs. Kubernetes
Containers orchestrators: Docker vs. Kubernetes
 

Similaire à NServiceBus

Global Azure Bootcamp: Azure service fabric
Global Azure Bootcamp: Azure service fabric Global Azure Bootcamp: Azure service fabric
Global Azure Bootcamp: Azure service fabric Luis Valencia
 
Kubernetes solutions
Kubernetes solutionsKubernetes solutions
Kubernetes solutionsEric Cattoir
 
Windows azure service bus reference
Windows azure service bus referenceWindows azure service bus reference
Windows azure service bus referenceJose Vergara Veas
 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Coremohamed elshafey
 
AAI-2016 WebSphere Application Server Installation and Maintenance in the Ent...
AAI-2016 WebSphere Application Server Installation and Maintenance in the Ent...AAI-2016 WebSphere Application Server Installation and Maintenance in the Ent...
AAI-2016 WebSphere Application Server Installation and Maintenance in the Ent...WASdev Community
 
WSO2Con 2015 USA: Introducing Microservices Server
WSO2Con 2015 USA: Introducing Microservices ServerWSO2Con 2015 USA: Introducing Microservices Server
WSO2Con 2015 USA: Introducing Microservices ServerWSO2
 
The Microservices world in. NET Core and. NET framework
The Microservices world in. NET Core and. NET frameworkThe Microservices world in. NET Core and. NET framework
The Microservices world in. NET Core and. NET frameworkMassimo Bonanni
 
Datasheet was pluginforrd
Datasheet was pluginforrdDatasheet was pluginforrd
Datasheet was pluginforrdMidVision
 
IBM InterConnect 2015 - IIB Effective Application Development
IBM InterConnect 2015 - IIB Effective Application DevelopmentIBM InterConnect 2015 - IIB Effective Application Development
IBM InterConnect 2015 - IIB Effective Application DevelopmentAndrew Coleman
 
State of the Container Ecosystem
State of the Container EcosystemState of the Container Ecosystem
State of the Container EcosystemVinay Rao
 
Integration in the age of DevOps
Integration in the age of DevOpsIntegration in the age of DevOps
Integration in the age of DevOpsAlbert Wong
 
Effective admin and development in iib
Effective admin and development in iibEffective admin and development in iib
Effective admin and development in iibm16k
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Reviewnetc2012
 
Microservices: How loose is loosely coupled?
Microservices: How loose is loosely coupled?Microservices: How loose is loosely coupled?
Microservices: How loose is loosely coupled?John Rofrano
 

Similaire à NServiceBus (20)

Global Azure Bootcamp: Azure service fabric
Global Azure Bootcamp: Azure service fabric Global Azure Bootcamp: Azure service fabric
Global Azure Bootcamp: Azure service fabric
 
Micro services
Micro servicesMicro services
Micro services
 
Kubernetes solutions
Kubernetes solutionsKubernetes solutions
Kubernetes solutions
 
Windows azure service bus reference
Windows azure service bus referenceWindows azure service bus reference
Windows azure service bus reference
 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Core
 
Containers and Docker
Containers and DockerContainers and Docker
Containers and Docker
 
AAI-2016 WebSphere Application Server Installation and Maintenance in the Ent...
AAI-2016 WebSphere Application Server Installation and Maintenance in the Ent...AAI-2016 WebSphere Application Server Installation and Maintenance in the Ent...
AAI-2016 WebSphere Application Server Installation and Maintenance in the Ent...
 
WSO2Con 2015 USA: Introducing Microservices Server
WSO2Con 2015 USA: Introducing Microservices ServerWSO2Con 2015 USA: Introducing Microservices Server
WSO2Con 2015 USA: Introducing Microservices Server
 
Kubernetes @ meetic
Kubernetes @ meeticKubernetes @ meetic
Kubernetes @ meetic
 
Container Networking Deep Dive
Container Networking Deep DiveContainer Networking Deep Dive
Container Networking Deep Dive
 
The Microservices world in. NET Core and. NET framework
The Microservices world in. NET Core and. NET frameworkThe Microservices world in. NET Core and. NET framework
The Microservices world in. NET Core and. NET framework
 
Datasheet was pluginforrd
Datasheet was pluginforrdDatasheet was pluginforrd
Datasheet was pluginforrd
 
IBM InterConnect 2015 - IIB Effective Application Development
IBM InterConnect 2015 - IIB Effective Application DevelopmentIBM InterConnect 2015 - IIB Effective Application Development
IBM InterConnect 2015 - IIB Effective Application Development
 
State of the Container Ecosystem
State of the Container EcosystemState of the Container Ecosystem
State of the Container Ecosystem
 
Integration in the age of DevOps
Integration in the age of DevOpsIntegration in the age of DevOps
Integration in the age of DevOps
 
App fabric introduction
App fabric introductionApp fabric introduction
App fabric introduction
 
Azure rev002
Azure rev002Azure rev002
Azure rev002
 
Effective admin and development in iib
Effective admin and development in iibEffective admin and development in iib
Effective admin and development in iib
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
 
Microservices: How loose is loosely coupled?
Microservices: How loose is loosely coupled?Microservices: How loose is loosely coupled?
Microservices: How loose is loosely coupled?
 

Plus de Rich Helton

Java for Mainframers
Java for MainframersJava for Mainframers
Java for MainframersRich Helton
 
I pad uicatalog_lesson02
I pad uicatalog_lesson02I pad uicatalog_lesson02
I pad uicatalog_lesson02Rich Helton
 
Mongo db rev001.
Mongo db rev001.Mongo db rev001.
Mongo db rev001.Rich Helton
 
NServicebus WCF Integration 101
NServicebus WCF Integration 101NServicebus WCF Integration 101
NServicebus WCF Integration 101Rich Helton
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101Rich Helton
 
Entity frameworks101
Entity frameworks101Entity frameworks101
Entity frameworks101Rich Helton
 
Tumbleweed intro
Tumbleweed introTumbleweed intro
Tumbleweed introRich Helton
 
Salesforce Intro
Salesforce IntroSalesforce Intro
Salesforce IntroRich Helton
 
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1Rich Helton
 
Learning C# iPad Programming
Learning C# iPad ProgrammingLearning C# iPad Programming
Learning C# iPad ProgrammingRich Helton
 
First Steps in Android
First Steps in AndroidFirst Steps in Android
First Steps in AndroidRich Helton
 
Python For Droid
Python For DroidPython For Droid
Python For DroidRich Helton
 
Spring Roo Rev005
Spring Roo Rev005Spring Roo Rev005
Spring Roo Rev005Rich Helton
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Rich Helton
 
C#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 FinalC#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 FinalRich Helton
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity FrameworksRich Helton
 
C# Security Testing and Debugging
C# Security Testing and DebuggingC# Security Testing and Debugging
C# Security Testing and DebuggingRich Helton
 

Plus de Rich Helton (20)

Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
I pad uicatalog_lesson02
I pad uicatalog_lesson02I pad uicatalog_lesson02
I pad uicatalog_lesson02
 
Mongo db rev001.
Mongo db rev001.Mongo db rev001.
Mongo db rev001.
 
NServicebus WCF Integration 101
NServicebus WCF Integration 101NServicebus WCF Integration 101
NServicebus WCF Integration 101
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
Entity frameworks101
Entity frameworks101Entity frameworks101
Entity frameworks101
 
Tumbleweed intro
Tumbleweed introTumbleweed intro
Tumbleweed intro
 
Salesforce Intro
Salesforce IntroSalesforce Intro
Salesforce Intro
 
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
 
Learning C# iPad Programming
Learning C# iPad ProgrammingLearning C# iPad Programming
Learning C# iPad Programming
 
First Steps in Android
First Steps in AndroidFirst Steps in Android
First Steps in Android
 
Python For Droid
Python For DroidPython For Droid
Python For Droid
 
Spring Roo Rev005
Spring Roo Rev005Spring Roo Rev005
Spring Roo Rev005
 
Python Final
Python FinalPython Final
Python Final
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
 
Adobe Flex4
Adobe Flex4 Adobe Flex4
Adobe Flex4
 
C#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 FinalC#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 Final
 
Jira Rev002
Jira Rev002Jira Rev002
Jira Rev002
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity Frameworks
 
C# Security Testing and Debugging
C# Security Testing and DebuggingC# Security Testing and Debugging
C# Security Testing and Debugging
 

NServiceBus

  • 1. NServicebus Rich Helton June 14, 2012 Buy “Mastering NServiceBus with Persitence”
  • 2. Introduction •By using the .NET 4 Framework, with the combination of the Windows Communication Framework (WCF), Workflow (WF), Model- View-Controller (MVC3), Entity Frameworks (EF4), Azure, AppFabric, and Message Queuing, I believe that Microsoft has brought serious competition to compete against the entire spectrum of all other Enterprise Development Systems.
  • 3. Introduction 2 •Now Microsoft systems can be virtualized to be decoupled form the hardware, be stripped down to run minimum services for the applications, and have many diagnostic and management tools. •This turns the Operating System into an Application Server to be reckoned with from the Application Server vendors. •This could also creates software quality that was never as common as it is now in the Industry, see
  • 4. The need for ESB •An ESB, is a software architecture model used for designating and implementing the interaction and communication between mutually interacting software applications in Service Oriented Architecture, http://en.wikipedia.org/wiki/Enterprise_service _bus
  • 5. The need for ESB •The Bus, is the combination of software that queues messages, routes messages and processes messages to the correct endpoints. •In order to do this ESB software will usually use other frameworks that handle message queuing and standard message queuing mechanisms. •For instance, NServiceBus can use RabbitMQ or MSMQ.
  • 6. Some benefits of ESB •The message bus provides both standardization and integration of messages across an enterprise. •A message could be sent from any endpoint, be it a database or service, and the messages are routed and interpreted to other services through the bus. •The services could be redundant as they could come from any endpoint. •Even though the messages could be complex
  • 7. NServiceBus •NServiceBus is an Open Source Enterprise Service Bus for .Net, http://nservicebus.com/ •Commercial licenses are required based on messages per second, http://nservicebus.com/License.aspx •For the basic code, it can be pulled from https://github.com/NServiceBus/NServiceBus
  • 8. Other Choices •There are many ESB choices, but price and documentation, including blogs and samples usually drive my choice. •For .NET, there is additionally BizTalk, MassTransit, KeystrokeESBNet and SimpleServiceBus. •There are many sites like http://en.wikipedia.org/wiki/Comparison_of_b usiness_integration_software
  • 9. AppFabric •Adding a caching provider and a monitoring service to WCF and WF creates the Microsoft AppFabric Framework and Architecture. •There is a special version that supports Azure. •The Micrsoft.ServiceBus.dll and namespace will be used to extend Service Bus helper extensions to WCF and WF.
  • 10. Biztalk •Biztalk uses a Micrsoft ESB Toolkit to build ESB. This Toolkit intergrates into Visual Studio 2010. http://technet.microsoft.com/en- us/library/ff699598.aspx •NServiceBus also has modeling and Code Snippets that integrate into Visual Studio 2010 as well, more work has been done into Visual Studio 11.
  • 11. Other Choices •Even other choices include not to utilize ESBs at all, but use other technology like Windows Communication Foundation Workflow Services for SOA Binding Services and MSMQ as a message queue system to build a message system. •But standard Message Queue and ESB frameworks provide the pieces that are already built and tested. •The downside is that you may be locked into the technology and the roadmap that the
  • 12. NServiceBus •NServiceBus is an Open Source Enterprise Service Bus for .Net, http://nservicebus.com/ •Commercial licenses are required based on messages per second, http://nservicebus.com/License.aspx •For the basic code, it can be pulled from https://github.com/NServiceBus/NServiceBus
  • 14. Getting Started •The benefit of using a ESB package is that it will normally handle the messaging packages for you, NServiceBus handles a lot of the MSMQ and DTC complexities. •See http://nservicebus.com/GettingStarted.aspx , http://nservicebus.com/GettingStarted2.aspx http://nservicebus.com/GettingStarted3.aspx
  • 15. Getting Started •The installation is usually just running the RunMeFirst.bat file with the correct Administrator permissions.
  • 16. Getting Started •You will be prompted to install NServiceBus Studio for building NServieBus projects in Visual Studio, this plugin is found under /tools:
  • 18. Core Files •There are many libraries included with NServiceBus, some for custom configs, and many samples to include from GitHub, but basic 4 libraries included for almost all apps are; log4net.dll, NServiceBus.Core.dll, NSeviceBus.dll, and NServiceBus.Host.exe. •NServiceBus is heavily reliant on Apache’s log4net for default logging and the correct version must be installed.
  • 19. Endpoint •Normally every NServiceBus has one Endpoint, which is the Queue name to read or write messages. •If not defined, by default, the current namespace of the project will be used. This method is sometimes used on Servers reading queues. •The name will be followed by an “@” with a servername to be server specific.
  • 20. Endpoint •There are different conventions and ways to define an Endpoint, I found that this will also depend on the version of NServiceBus being used, http://andreasohlund.net/2012/01/27/convent ion-over-configuration-in-nservicebus-3-0/
  • 21. Endpoint – FullDuplex Example •App.config will normally define the endpoint in the UnicastBusConfig, here we define the Message as well in the Client:
  • 22. Endpoint – FullDuplex Example •Instead of using App.config, the configuration can be programmatic by building a class using IProviderConfiguration:
  • 23. Endpoint from different places •So, we could put a UnicastConfigBusConfig, for messages and an endpoint in an App.config, and a MessageForwardingInCaseOfConfig like so:
  • 24. How do the different configs come together •The purpose of all the configs is simply to build an IBus instance to send or receive the messages. •The Bus is normally created by a Handler or building the bus directly with an arrangement of Builder calls.
  • 25. A sample Builder for SendOnly •Note : The order of which calls happen first can change the functionality. •This allows tighter control of the Bus.
  • 26. A sample Handler for a Reply
  • 27. Send versus Publish •After the Bus is built with the configs and handlers, the clients and server need to Send, Publish or Reply to messages. •See http://mookid.dk/oncode/archives/807 , NServiceBus for Dummies who want to be Smarties for some of the differences.
  • 28. Send with a Destination Server as it sends •Notice the “someserver”:
  • 30. Start with the Builders •We will start with Configure.With() from and a builder type: •The builders can be Defaultbuilder(), AutoFacBuilder(), CastleWindsorBuilder(), NinjectBuilder(), SpringBuilder(), StructureMapBuilder(), and UnityBuilder().
  • 31. Information on Builders •These Builder Objects are the containers in which to build the bus and configurations. http://nservicebus.com/Containers.aspx •First the configurations will be declared for endpoints, transactional, type of container and then the CreateBus() and Start() will initiate the bus.
  • 32. Types of Builders/Containers •AutofacBuilder() – is the default container, same as DefaultBuilder() , that will use internal extensions in NServiceBus. •CastleWindsorBuilder() – Castle Windsor is an Inversion of Control container. http://en.wikipedia.org/wiki/Castle_Project •NinjectBuilder() – A Inversion of Control container, sometimes called the ninja of dependency injectors, http://ninject.codeplex.com/wikipage?title=Wh
  • 33. Types of Builders/Containers •SpringBuilder() – A Inversion of Control container for Spring.net. http://www.springframework.net/ •StructureMapBuilder () – A Inversion of Control container for StructureMap, http://docs.structuremap.net/. •UnityBuilder() – A Inversion of Control container, Dependency Injection container from Microsoft. http://msdn.microsoft.com/en- us/library/dd203101.aspx
  • 34. Next is normally the Serializers •Next is normally the Serializers, this will transfer the message as binary or xml data. •XmlSerializer() – Serializes the objects into an XML format, but there are limitations with the XML serialization in NServiceBus with object lists, Derived Objects, and arrays of objects, http://stackoverflow.com/questions/2816895/ nservicebus-serization-issue-of-derived-types , the work around is to use the Binary
  • 35. Next is normally the Serializers •BinarySerializer() – Serializes the objects into an binary format, and is done with the standard .net binary serializer, http://nservicebus.com/Performance.aspx •JSonSerializer() – Javascript Object Notation (JSON) format serialization, uses the Newtonsoft.json interface, http://json.codeplex.com/ .
  • 36. Next is normally the Transport •Next is normally the Transport, this is the queuing mechanism, and in many cases will be MSMQ. •Transports can be created using ISendMessages and IReceiveMessages. A Service Broker example can be seen in NserviceBus-Contrib that includes a Sample https://github.com/NServiceBus/NServiceBus- Contrib
  • 37. Transport Types •MsmqTransport() – This is the MSMQ Transport mechanism commonly used, there are many samples, see FullDuplex example. •FtpTransport() – This is a Transport to send messages across FTP, which has to have a directory, username and password included for FTP setup, see the FtpSample. •AzureQueueMessage() – Using Storage Queues for Azure, see the Azure examples.
  • 38. UnicastBusConfig •Now UnicastBus() must be defined: •UnicastBus() tells NServiceBus to use unicast messaging. Used out of the box, see http://nservicebus.com/SelfHosting.aspx •Here we have a UnicastBusConfig defining the message and endpoint in App.config client:
  • 39. Now for the Bus •So far these have only been configurations and the bus still hasn't been created, to create the bus, CreateBus() must be used, and to start the bus, then Start() must be used,
  • 40. For SendOnly •For SendOnly(), createbus and start are not needed because not all the components are needed from the bus.
  • 42. Why I looked at SendOnly •I started looking at SendOnly because Publish was not recommended for the Web interfaces. http://www.make- awesome.com/2010/10/why-not-publish- nservicebus-messages-from-a-web-application/ •Publishing requires a Subscription storage and the messages are normally handled as transactional events, http://nservicebus.com/PubSubApiAndConfigu ration.aspx
  • 43. Subscription Storage •If multiple machines share the same subscription storage, then Database Storage needs to be used, .DBSubscriptionStorage(). •The Nhibernate connection strings will need to be defined in the App.config.
  • 44. Subscription Storage •If multiple machines share the same subscription storage, then Database Storage needs to be used, .DBSubscriptionStorage(). •The Nhibernate connection strings will need to be defined in the App.config.
  • 45. Subscription Storage •If multiple machines share the same subscription storage, then Database Storage needs to be used, .DBSubscriptionStorage(). •The Nhibernate connection strings will need to be defined in the App.config.
  • 46. Subscription Storage •The Manufacturing Example shows an MSMQ Storage example and in memory:
  • 47. Installers •In the Manufacturing and AsyncPages, there is the Install() for the installation of endpoints and infrastructure, such as MSMQ and RavenDB. •See http://andreasohlund.net/2012/01/26/installer s-in-nservicebus-3-0/
  • 48. MSMQ
  • 49. NServiceBus supports many types of messaging Schemes •NServiceBus supports messaging through databases, like its native RavenDB, or SQL Server. •It also supports Message Queuing mechanisms like Microsoft Message Queue and Apache’s RabbitMQ.
  • 50. MSMQ •MSMQ is the Message Queuing System built into the Microsoft Operating System since 1997. •The Server Operating Systems, like Windows Server 2008, offers additional features. •See http://en.wikipedia.org/wiki/Microsoft_Messag e_Queuing
  • 51. Viewing MSMQ •It is important to administer the MSMQ Queues when building MSMQ applications. If the Queue is not built, the application could error. •The Queue will normally store its data in XML or Binary form. XML makes the data readable for troubleshooting.
  • 52. Viewing MSMQ •While there is the Visual Studio View Servers, he MSMQ MMC, and even the Computer Management way to view Queues. •I still like to use IMQT to view the XML, a commercial tool is Queue Explorer. IMQT is http://utvecklargodis.blogspot.com/2007/03/m smq-management-tool.html
  • 53. Viewing MSMQ in Visual Studio
  • 55. Programming MSMQ •Windows will use the System.Message namespace to program the MessageQueue class. •NServiceBus offers extensions of this class as MSMQUtilities for managing Queues and MSMQInstallation for installing MSMQ. •These are in the NServiceBus.Utils namespace, found in the NServiceBus.Utils.dll. •Code for MSMQUtilities can be found at https://github.com/NServiceBus/NServiceBus/
  • 56. Programming MSMQ •Here is a small example to check if a Queue is built, and if not build it with the Administrator username using both System and NServiceBus Utils for the client, the server should create its own queue by default:
  • 58. Unit Testing •NServiceBus normally uses NUnit to test with handlers that it already has built in for Sends and Publish. Nunit can be found at http://www.nunit.org/ •The code for the Handlers can be found at https://github.com/NServiceBus/NServiceBus/ blob/master/src/testing/Handler.cs
  • 59. Unit Testing •To test Nunit in Visual Studio, you will likley need to install a plugin like TestDriven.Net, Resharper, or Ncoverage., and the nunit framework will have to be installed.
  • 60. Handlers •Here’s what a typical Test Handler looks like to test if the message and header is validated:
  • 61. MOQ •Another choice besides using the NServiceBus custom handlers is to use MOQ. •MOQ is used to mockup a bus, MOQ came from http://code.google.com/p/moq/ •There are many links for doing this, one with some sample test code can be found at http://pastebin.com/CSrN6fR1
  • 63. Installing NServiceBus as Service •It was mentioned earlier that NServiceBus.Host.Exe is one of the 4 files to always be included with NServiceBus. •This is the file used for running NServiceBus applications that are non-Console based. •This file is used for installing, running and debugging NServiceBus applications. •See http://nservicebus.com/GenericHost.aspx
  • 64. NServiceBus.Host.exe debug •NServiceBus.Host.Exe is needed to debug the applications:
  • 65. NServiceBus.Host.exe commands •A service can be created at the command line by using NServiceBus.Host.exe /install /serviceName:MyServer.dll /displayName:"My Super Duper service" /description:"My server installed by NService Magic” •See http://prashantbrall.wordpress.com/tag/nservi cebus/ for further details on doing this.

Notes de l'éditeur

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. Microsoft Confidential
  67. Microsoft Confidential