messaging patterns in the cloud

57
itcampro @ itcamp13 # Premium conference on Microsoft technologies Messaging Patterns in the Cloud Radu Vunvulea iQuest Group @RaduVunvulea http://vunvulearadu.blogspot.com

Upload: radu-vunvulea

Post on 13-May-2015

231 views

Category:

Technology


3 download

DESCRIPTION

Presentation for ITCamp 2013. www.itcamp.ro Talking about different patterns that can be used when we need to deal with messages. Sample code is based on Windows Azure Service Bus

TRANSCRIPT

Page 1: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Messaging Patterns in the Cloud

Radu VunvuleaiQuest Group

@RaduVunvuleahttp://vunvulearadu.blogspot.com

Page 2: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudHuge thanks to our sponsors!

Page 3: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• World of Messages• On-Premise and Cloud solutions• Messaging Patterns • Costs, Benefits and Limitations

Agenda

Page 4: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

WORLD OF MESSAGES

Page 5: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudWorld of Messages

Page 6: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudWorld of Messages

Page 7: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudWorld of Messages

Page 8: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudWorld of Messages

Page 9: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudWorld of Messages

Message

Message

Message

Page 10: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

Enterprise Service Bus

?

Page 11: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

Enterprise Service Bus

Interaction and communication between software applications

Page 12: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudEnterprise Service Bus

Topic

Subscriptions

Page 13: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudEnterprise Service Bus

Topic

Subscriptions

Page 14: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudEnterprise Service Bus

Topic

Subscriptions

Page 15: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

Enterprise Service Bus

Page 16: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

ON-PREMISE AND CLOUD SOLUTIONS

Page 17: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Pro– Open Source– Flexible– Good price – Transactional queue read/write– Flexible load distribution

• Cons– No queue management– Document not up to date– Only one queue technology supported

(MSMQ)

NService Bus

Page 18: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Pro– Free for commercial use– Supports MSMQ and RabittMQ– Open Source– Good administration console

• Cons– No commercial support– Not as fast as NServiceBus

MassTransit

Page 19: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Pro– Scalable– Lots of features– Good administration console– Support– Cross platform and multiple environments

• Cons– Is not free– Latency

Azure Service Bus

Page 20: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

MESSAGING PATTERNS

Page 21: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Filter

Page 22: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Filter

Topic

Subscriptions

Page 23: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Custom rules based on message attributes

• Add attributes to message

Message Filter

BrokeredMessage msg = new BrokeredMessage(messageContent);msg.Properties["colorCode"] = 1;

• Create subscription with custom rule

RuleDescription rule = new RuleDescription(){   // 1 - green, 2 - orange   Filter = new SqlFilter("colorCode = 1");}namespaceManager.CreateSubscription(

"itcamp", "greensubscription", rule);

Page 24: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Splitter

Page 25: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Splitter

Topic

Subscriptions

Page 26: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Group messages based on session

Message Splitter

MessageSession msgSession = msgReceiver.AcceptMessageSession();BrokeredMessage message;while ((message = msgSession.Receive()) != null){   // Process message   }msgSession.Complete()

BrokeredMessage message = new BrokereMessage(content);message.SessionId = "sessionId";

• Consume messages based on session id

Page 27: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Group messages based on session

Message Splitter

MessageSession msgSession = msgReceiver.AcceptMessageSession();BrokeredMessage message;while ((message = msgSession.Receive()) != null){   // Process message   }msgSession.Complete()

BrokeredMessage message = new BrokereMessage(content);message.SessionId = "sessionId";

• Consume messages based on session id

Transactions Support

Page 28: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Aggregator

Page 29: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Aggregator

Topic

Subscriptions

Page 30: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Group messages based on session

Message Aggregator

BrokeredMessage message = new BrokereMessage(content);message.SessionId = "sessionId";

• Use correlation id and filtersBrokereMessage message = new BrokereMessage(content);message.CorrelationId = “CJ"topic.Send(message);

namespaceManager.CreateSubscription(     “itcamp”,     “iquestsubscriptioncar”,     new CorrelationFilterExpression(“CJ"));

Page 31: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Resequencer

Page 32: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Resequencer

Page 33: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Resequencer

Topic

Subscriptions

1234

1234

1234

Page 34: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Resequencer

Topic

Subscriptions

1234

1234

3412

Page 35: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Session, message index and message count

Message Resequencer

• Mark message as dead letter when in incorrect order

• Iterate dead letter queue to access a message with a lower index

BrokeredMessage message = new BrokereMessage(content);message.Properties["index"] = 2;message.Properties["count"] = 10message.SessionId = “CJ-15-IQU";

Page 36: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Resequencer

MessageSession messageSession = queueClient.AcceptMessageSession();int currentIndex = 1;while(true){    BrokeredMessage message = messageSession.Receive();    if(int.Parse(message.Properties[“index”]) != currentIndex)    {        message.DeadLetter();        continue;    }    …    message.Complete();    if(int.Parse(messsage[“count”]) == currentIndex)    {        break;    }    currentIndex++;}

Page 37: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudMessage Recipient

Topic

Subscriptions

Page 38: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Use a property to specific the list of groups

Message Recipient

• Define custom filters using LIKE operator

BrokeredMessage message = new BrokeredMessage(content);message.Properties[“groups”] = “orange magenta”;

SqlFilter filter = new SqlFilter(“groups LIKE ‘%orange%’”);

topic.AddSubscription(“subscription3”, filter);

• OR different properties for each group type

SqlFilter filter = new SqlFilter(“EXISTS orange”);

topic.AddSubscription(“subscription3”, filter);

Page 39: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Use a property to specific the list of groups

Message Recipient

• Define custom filters using LIKE operator

BrokeredMessage message = new BrokeredMessage(content);message.Properties[“groups”] = “orange magenta”;

SqlFilter filter = new SqlFilter(“groups LIKE ‘%orange%’”);

topic.AddSubscription(“subscription3”, filter);

• OR different properties for each group type

• Use only one property and a prime number for each group

Page 40: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudContent-Based Router

Topic

Subscriptions

Page 41: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudContent-Based Router

Topic

Subscriptions

?

Page 42: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudScatter-Gather

Topic

Subscriptions

Queue

Page 43: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudScatter-Gather

Topic

Subscriptions

Queue

?

Page 44: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudDynamic Router

Topic

Subscriptions

Page 45: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudDynamic Router

Topic

Subscriptions

Page 46: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public CloudDynamic Router

Topic

Subscriptions

Page 47: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• [key, values] properties

• Store properties

• Decorate properties

Dynamic Router

Page 48: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

COSTS, BENEFITS AND LIMITATIONS

Page 49: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• What are the costs of processing:– 24kB message size– 10M messages– 1 Topic- 8 hours

Costs

Page 50: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• 10$ Sending • 27.46$ Bandwidth (sending)

Costs

Page 51: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• 10$ Sending • 27.46$ Bandwidth (sending)

• 10 $ Receiving• 0 $ Bandwidth (receiving)

Costs

Page 52: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• 10$ Sending • 27.46$ Bandwidth (sending)

• 10 $ Receiving• 0 $ Bandwidth (receiving)• 47.46$ Costs related to Service Bus

Costs

Page 53: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• 10$ Sending • 27.46$ Bandwidth (sending)• 10 $ Receiving• 0 $ Bandwidth (receiving)• 47.46$ Costs related to Service Bus

• 8.64$ 4 Medium Worker Roles used to consume messages

• 56.1$ Total cost

Costs

Page 54: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Cheap • 99.9% Uptime • Extremely scalable and flexible• No message is lost• Filters and actions support• REST API• Death-letter and transaction support• Same API for on-premise and cloud

Benefits

Page 55: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Private & Public Cloud

• Not for real-time application• When processing more than 1M

messages on the same topic in a 30 minutes time interval latency increases

• You need to pay for each send/receive command

• Batch maximum size – 100 messages

Limitations

Page 56: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

Q & A

Page 57: Messaging patterns in the cloud

itcampro@ itcamp13# Premium conference on Microsoft technologies

THANK YOU