Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

47
Message System Fundamentals By John Staveley 27/07/2017 https://uk.linkedin.com/in/johnstaveley/ @johnstaveley

Transcript of Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Page 1: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Message System Fundamentals

By John Staveley27/07/2017

https://uk.linkedin.com/in/johnstaveley/@johnstaveley

Page 2: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Who am I?

John StaveleyContract Mvc.net developerOrganiser @LeedsSharpUser of messaging systems for the last 4 years (MSMQ,

Rabbit, Azure Service Bus etc)

Page 3: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Overview

Why use messaging systems?What are they? Benefits?Demos (Azure Storage Queues, Azure Service Bus,

RabbitMQ)Azure FunctionsInfrastructure as code.Net Core and DockerOther Messaging implementationshttps://github.com/johnstaveley/MessagingPresentationSlides on SlideShare

Page 4: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Use cases and benefits

Distributed workloads Increased reliability (cf fallacies of distributed networking) Synchronous vs Asynchronous processes Loosely coupled systems (Microservices) The promise of fast reads and fast writes LinkedIn, CompareTheMarket.com, Facebook

Page 5: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Demo: Azure Storage Queues

What is Azure? What is Serverless / FaaS - Azure functions? What are Azure Queues? Message patterns - One way/competing consumers Demo

Page 6: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

What is Azure?

Second largest cloud provider in the world IaaS (Windows or Linux VMs), PaaS, FaaS Data storage, Notifications, Load Balancing, Active

Directory, Application insights SQL Azure, DocumentDb, HDInsight, Azure data lakes,

Azure machine learning, Cognitive services ARM Templates Message Queues

Page 7: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Azure Functions (1)

Serverless – paradigm shift FaaS = Function as a Service Azure function = Event + Code Triggers – Schedule, Http, Queues, Storage Bindings – connecting to data Programmed in JavaScript, C#, Python, PHP, Powershell Functions are stateless Try it for free - monthly grant of 1,000,000 executions and

400,000 GB-s Execution limited to 5 minutes

Page 8: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Azure Functions (2)

Monitoring for free Try online: https://functions.azure.com/try Can be edited inside of the Azure portal Can be edited and deployed from Visual Studio

Page 9: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Azure Queuing technologies

Storage Queues- Supports Get/Put/Peek- Can store over 80Gb in queue- No ordering guarantee- Cheap (100x cheaper than Azure Service Bus)

Service Bus Queues- Can support message exchange patterns e.g. Pub/Sub,Topics- Doesn't require polling- 80Gb queue limit- AMQP- Apps can support at-most-once delivery- Partitions to overcome broker limitation

Event Hubs- Can handle huge scale or event streaming needs- AMQP or HTTP

Page 10: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Messaging pattern – One way

One-way

S Q C

Message Broker

Page 11: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Azure Storage Queue Demo

Workload: Calculate factors of numbers90 = 1, 2, 3, 5, 6, 9, 10, 15, 18, 30, 45, 90

Source RestAPI Queue

FactorCalc Queue Consumer

Page 12: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Azure Queues Demo

Page 13: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Azure Function auto-scaling

Scales using heuristics

Source RestAPI Queue

FactorCalc Queue Consumer

Page 14: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Messaging – Competing Consumers

Competing Consumers (a.k.a Worker queues)

S Q

C

CMessage Broker

Page 15: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Types of messaging pattern

One-way Competing consumers RPC Pub-Sub Routing Topics Scatter-Gather

Page 16: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Messaging – Pub sub

Publish-subscribe

S

Q C

CQ

E

Message Broker

Page 17: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Messaging – Routing

Routing

S

Q C

CQ

E

Message Broker

Large

Medium

Small

Page 18: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Messaging – RPC

Remote Procedure Call

S

Q

C

Q

Message Broker

Request queue

Response queue

Page 19: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Messaging – Scatter-Gather

Scatter-Gather

S

Q C

CQE

Message Broker

Dynamic response queue

Q

Page 20: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Demo: Azure Service Bus

Infrastructure as code: What are ARM templates? Azure Service Bus Topics message pattern Demo

Page 21: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

ARM Templates (1)

Azure Resource Manager templates Infrastructure as code JSON Schema

https://github.com/Azure/azure-quickstart-templates

Page 22: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Azure Service Bus

Queues → Single Consumer Topics & Subscriptions → Multiple consumers Patterns– Topics– Routing– Pub/Sub

Page 23: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Messaging – Topics

Topics

S

Q C

CQ

E

Message Broker

*.*.mail

*.small.*

high.*.*

Q C

High.small.mail

Low.large.post

Low.small.post

Page 24: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Azure Service Bus Demo

S

All Products C

COrange, White, Yellow

E

Azure Service Bus

Large C

All Products

SubscriptionsTopics

Expensive

Light Colour

Large

Cost > 80 C

Products:Colour.Size.Cost

Page 25: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Azure Service Bus Demo

Page 26: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Break!

Page 27: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Demo: RabbitMQ in Docker

Introduction to Docker Introduction to RabbitMQ Setup .Net core on docker Routing message pattern Demonstration of RabbitMQ Management UI Creation of Exchange and Queue using UI and powershell Running rabbitmq, producer, receiver in docker

Page 28: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Infrastructure

Infrastructure: How we used to do it– Windows image, Packer, Boxstarter, Chocolatey, Vagrant = 6Gb

What is Docker?– Lightweight containers– Run on a host operating system (either Linux or Windows)– Inside of VirtualBox or HyperV host– Extensive support - lots of images available on docker hub– Very fast to setup and start images– Docker is scriptable

What is kitematic?

Page 29: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

RabbitMQ

AMQP – Advance Message Queuing Protocol Built on Erlang Easy to setup - runs on Linux, Windows and containers Exchanges Queues Routing Key Virtual Hosts Web based Management UI EasyNetQ (https://www.infoq.com/presentations/RabbitMQ-NET-EasyNetQ) Powershell management

Page 30: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Docker and .Net Core

.Net Core runs on Linux Choose the right NuGet package Build .Net core to run inside docker:

– Build a container image to build the C# solution (DockerFile.build)– Create an instance of the build container– Copy the .Net core build output from the docker build container– Use the .Net core build output to create images with .Net core (DockerFile)– Run the containers (docker run or docker-compose)

Page 31: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Messaging – Routing

Routing

S

Q C

CQ

E

Message Broker

Large

Medium

Small

Page 32: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

RabbitMQ Demo

S

Q C

E

Large Products

Products:Colour.Size.Cost

*

Large

Page 33: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Rabbit MQ Demo

Page 34: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

… and now!

Reliability patternsWhat is a service bus?Messaging jargonTypes of messaging systemsHow to select a messaging system?Event sourcing

Page 35: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Reliability patterns (1)

S Q C

Message Broker

What could possibly go wrong?

Page 36: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Reliability patterns (2)

Acknowledgement levelsConnection failures -> Client automatically reconnect, use heartbeatsFailure at broker/queue -> Persist to diskMessaging hardware failure -> Clustering (e.g. RabbitMQ and MSMQ)Producer failure -> Ack will not be received so need Idempotent messagingBad Config (Message not routed) -> Set ack to confirm message routedEasyNetQ - Error handling, connection management, publisher confirms for reliable messaginghttps://www.rabbitmq.com/reliability.html

Page 37: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

What is a service bus?

Layer on top of messaging systems– Handles Retries, transaction management

nServiceBus and MassTransit Sagas (aka transactions across messaging)

Page 38: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Messaging fundamentals

Brokered vs non-brokered Persisted vs non-persisted Dead letter queue

Page 39: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Messaging systems

Azure Storage Queue Azure Service Bus RabbitMQ MSMQ ZeroMQ WebSphereMQ / IBM MQ Kafka Azure Event Hubs AWS Simple Queue Service

Page 40: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

ZeroMQ

Concurrency framework using socketsFaster than RabbitMQ, but you have to work harder for itUsed by Cisco, AT&T, NASA, Spotify, Microsoft

Page 41: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

MSMQ

Store and forward: can do point to point or fan outBrokerless, but for reliability you need a cluster plus MSDTCLimited to windowsUsed by Microsoft, nServiceBus

Page 42: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Kafka

Distributed streaming platform (but can do queuing and pub/sub)Used by thousands of companies like LinkedIn, Yahoo, Twitter, Netflix, Spotify, Pinterest, Uber, Paypal etc etcStreams data efficiently in real time to a replicated commodity cluster running LinuxCan form ecosystems with Hadoop, Spark etcApache projectAppend Onlyhttps://kafka.apache.org/uses

Page 43: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

How do I select a messaging system?

Performance Messaging patterns Brokered/Non-brokered Platform Other features

− Duplicate detection− Can it be used with a Service Bus?

Ecosystem

Page 44: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Event Sourcing

Append Only – Store the history of events Don't hold state, build up state from the history of events Useful when holding a log of everything is useful EventStore LMAX architecture:

https://martinfowler.com/articles/lmax.html

Page 45: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Further Resources

Pluralsight₋ https://app.pluralsight.com/library/courses/rabbitmq-by-example₋ https://app.pluralsight.com/library/courses/rabbitmq-dotnet-developers₋ https://app.pluralsight.com/library/courses/message-queue-

fundamentals-dotnet₋ https://app.pluralsight.com/library/courses/docker-web-development

SyncFusion RabbitMQ succinctly bookhttps://github.com/Azure/azure-quickstart-templates

Page 46: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Summary

Demos of Messaging patterns– One Way– Competing Consumer– Topics– Routing

Messaging systems– Azure Storage Queues– Azure Service Bus– RabbitMQ

Hipster tech– FaaS – Build auto-scaling apps without the hassle of any infrastructure– ARM Templates – Infrastructure as code– Docker – fast setup of infrastructure

Page 47: Messaging - RabbitMQ, Azure (Service Bus), Docker and Azure Functions

Any Questions?

@johnstaveley