codepalousa 2012

Upload: joseph-feser

Post on 05-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 CodepaLOUsa 2012

    1/31

    Introduction to Windows Azure

    Service Bus

    Joe Feser

    Logical Advantage@joefeser on twitter and github

  • 7/31/2019 CodepaLOUsa 2012

    2/31

    What is a Service Bus

    An enterprise service bus (ESB)

    is a software architecture model

    used for designing and

    implementing the interactionand communication between

    mutually interacting software

    applications in Service Oriented

    Architecture.

    Source: Wikipedia

  • 7/31/2019 CodepaLOUsa 2012

    3/31

    What is AppFabric Service Bus

    Message Relay

    Brokered Message

    Queues

    Topics (Pub/Sub)

    Do not confuse it with Azure Queues (Queues, Tables and Blobs)

    The Service Bus provides both relayed and brokered messagingcapabilities. In the relayed messaging pattern, the relay servicesupports direct one-way messaging, request/response messaging,and peer-to-peer messaging. Brokered messaging provides durable,asynchronous messaging components such as Queues, Topics,

    and Subscriptions, with features that support publish-subscribe andtemporal decoupling: senders and receivers do not have to be onlineat the same time; the messaging infrastructure reliably storesmessages until the receiving party is ready to receive them. (FromMicrosoft)

  • 7/31/2019 CodepaLOUsa 2012

    4/31

    What makes it cool?

    It does not take weeks to integrate

    You dont have the change your entire

    architecture to use it

    It does not depend on the Azure SDK

    It does not need to run on Azure but it can

    Allows for easy integration with partnerswithout the need for a service to be up 24/7

    Allows for massive scale out

  • 7/31/2019 CodepaLOUsa 2012

    5/31

    What makes it different than a web

    service?

    You can not discover the service

    There is no WSDL

    The message contract must be known up frontby both parties

    A web server is not required. It can run from

    any standard computer or server as a serviceor process.

  • 7/31/2019 CodepaLOUsa 2012

    6/31

    SB does not Require the Azure SDK

    The library built by Microsoft does not depend

    on the Azure SDK.

    The service is also exposed via REST and you

    may build your own if you wish.

  • 7/31/2019 CodepaLOUsa 2012

    7/31

    How does it authenticate

    Azure Service Bus requires the AppFabric ACS

    (Access control Service)

    It is a very powerful namespace based

    provider

  • 7/31/2019 CodepaLOUsa 2012

    8/31

    How does it communicate?

    All communications are outbound

    TCP is used by default and will fall back to

    HTTP if TCP cant be used

    No changes are required to your firewall

    although you may need to configure your

    proxy server

  • 7/31/2019 CodepaLOUsa 2012

    9/31

    Queues Introduction

    A Queue is exactly what you would expect

    Many sources places messages into a known

    common endpoint

    All messages are processed FIFO

    One or many

    receivers pull from

    the queue

  • 7/31/2019 CodepaLOUsa 2012

    10/31

    Topics Introduction

    Topics use the Pub/Sub model

    Many sources publish messages onto a topic endpoint

    Subscribers create subscriptions to the messagesand receivea copy when the filterevaluates to true

    Subscribers then pullmessages from thetopic when they areavailable

  • 7/31/2019 CodepaLOUsa 2012

    11/31

    Difference between Queues and Topics

    Queues cant be filtered. If you need to supporttwo different rules, you need to create twodifferent queues For example, if you have a system interested in new

    orders and shipment notifications, you will need tocreate two queues

    Topics may contain filters, allowing for manytypes of messages to be sent to the same

    endpoint A topic may be created to receive an order object and

    a different topic may be created for a shippingnotification object

  • 7/31/2019 CodepaLOUsa 2012

    12/31

    How are AppFabric Queues

    different from Azure Queues?Comparison Criteria Windows Azure Queues Service Bus Queues

    Ordering guarantee No Yes - First-In-First-Out (FIFO)

    (through the use of messaging sessions)

    Delivery guarantee At-Least-Once At-Least-Once

    At-Most-Once

    Transaction support No Yes

    (through the use of local transactions)

    Receive behavior Non-blocking

    (completes immediately if no new message is

    found)

    Blocking with/without timeout

    (offers long polling, or the Comet technique)

    Non-blocking(through the use of .NET managed API only)

    Receive mode Peek & Lease Peek & Lock

    Receive & Delete

    Exclusive access mode Lease-based Lock-based

    Lease/Lock duration 30 seconds (default)

    7 days (maximum)

    60 seconds (default)

    5 minutes (maximum)

    Lease/Lock granularity Message level

    (each message can have a different timeoutvalue)

    Queue level

    (each queue has a lock granularity applied to allof its messages, fixed for the lifetime of the

    queue)

    Batched receive Yes

    (explicitly specifying message count when

    retrieving messages, up to a maximum of 32

    messages)

    Yes

    (implicitly enabling a pre-fetch property or

    explicitly through the use of transactions)

    Batched send No Yes

    (through the use of transactions or client-side

    batching)

    http://en.wikipedia.org/wiki/Comet_(programming)http://en.wikipedia.org/wiki/Comet_(programming)
  • 7/31/2019 CodepaLOUsa 2012

    13/31

    Advanced Capabilities

    Comparison Criteria Windows Azure Queues Service Bus Queues

    Scheduled delivery Yes Yes

    Automatic dead lettering No Yes

    Message deferral Yes

    (via in-place update of visibility timeout)

    Yes

    (provided via a dedicated API function)

    Poison message support Yes Yes

    In-place update Yes No

    Server-side transaction log Yes No

    Storage metrics Yes No

    Purge queue function Yes No

    Message groups No Yes

    (through the use of messaging sessions)

    Duplicate detection No Yes

    (configurable on the sender side)

    WCF integration No Yes

    (offers out-of-the-box WCF bindings)

    WF integration Custom

    (requires building a custom WF activity)

    Native

    (offers out-of-the-box WF activities)

  • 7/31/2019 CodepaLOUsa 2012

    14/31

    Capacity and Quotas

    Comparison Criteria Windows Azure Queues Service Bus Queues

    Maximum message size 64 KB (Was 8k in SDK < 1.6)

    (48 KB when

    using Base64encoding)

    256 KB

    (including both header and body,

    maximum header size: 64 KB)

    Maximum queue size 100 TB

    (limited to a single storage account

    capacity)

    1, 2, 3, 4 or 5 GB

    (defined upon creation of a queue)

    Maximum message TTL 7 days Unlimited

    Maximum number of queues Unlimited 10,000

    (per service namespace, can be

    increased)

    Maximum number of concurrent

    clients

    Unlimited Unlimited

    (100 concurrent connection limit

    only applies to TCP protocol-based

    communication)

  • 7/31/2019 CodepaLOUsa 2012

    15/31

    Message Limits

    Brokered messages have a 256k limit,

    including the message overhead

    The Header may be up to 64k

    Messages over 64k are sent in chunks of 64k

    and this will affect your performance and cost.

  • 7/31/2019 CodepaLOUsa 2012

    16/31

    What can the message be?

    Any object that can be serialized with a

    DataContractSerializer

    Any Stream of data that you will manage

    yourself

    Any base CLR type (string, int, boolean)

  • 7/31/2019 CodepaLOUsa 2012

    17/31

    Metadata on your message

    Every message supports up to a 64k Name

    Object pair of values that may be used by your

    handler or by the by your Topic Subscription

    filters

    An example key could be Department and

    the value may be Payroll

    For a topic, you could create a subscription that

    only looks for messages with a Department of

    Payroll

  • 7/31/2019 CodepaLOUsa 2012

    18/31

    Read once vs read at least once

    ReceiveAndDelete You will only receive the message once

    Great for logging non critical items

    Very high performance vs PeekLock because a roundtrip is not required

    PeekLock You will receive at least once

    Until you call Complete, it will stay in the queue

    You can read the DeliveryCount count property todetermine how many times you have received themessage.

  • 7/31/2019 CodepaLOUsa 2012

    19/31

    Default Time to Live

    Be VERY careful with this setting. Keep at the

    default unless you want the service to cleanup

    old messages for you.

    More geared toward priority based logging.

    You will pull your hair out if you do not read

    the last to bullet points 10 times. Trust me I

    did.

  • 7/31/2019 CodepaLOUsa 2012

    20/31

    Duplicate Detection

    The MessageId property of the BrokeredMessageis the Primary key of the message

    If duplicate detection is set up and the timeframe is three minutes, only one message withthe same id will be accepted by the Topic orQueue

    The second message will just be ignored

    No error will be returned to the sender

    Make sure you really are sending the samemessage

  • 7/31/2019 CodepaLOUsa 2012

    21/31

    Queues

    A Queue in Azure Service busis nothing more than a Topicwith one subscription withno rules

    Many senders can send amessage to the queue

    To scale the read throughputall you need to do is addadditional receivers. Theservice bus will automaticallyload balance the requestsbetween the clients

  • 7/31/2019 CodepaLOUsa 2012

    22/31

    Load leveling

    The biggest advantage to a queue is load

    leveling. Your back end system can process the

    messages at a constant rate with a consistent

    response time on message acceptance

  • 7/31/2019 CodepaLOUsa 2012

    23/31

    Load balancing

    You can query the queue for the message

    count and determine if more instances of your

    message processor need to be spun up

  • 7/31/2019 CodepaLOUsa 2012

    24/31

    Topics

    Just like Queues, Topics allowfor multiple publishers to sendmessages to a pre definedendpoint

    Messages can be sent in a fire

    and forget manner No need to care if anyone is

    subscribed to your message, ifno filters qualify the message isthrown out

    Any mix and match of receivers

    can process a givensubscription and just likequeues, they will automaticallyscale out

  • 7/31/2019 CodepaLOUsa 2012

    25/31

    How I used Service Bus to extend a web service?

  • 7/31/2019 CodepaLOUsa 2012

    26/31

    Sending a state change to the topic

  • 7/31/2019 CodepaLOUsa 2012

    27/31

    How it can be used for a Workflow?

  • 7/31/2019 CodepaLOUsa 2012

    28/31

    Service Bus Demo

    Demo sample code from Project Extensions

    If time show the emulator

  • 7/31/2019 CodepaLOUsa 2012

    29/31

    Limits to consider

    DTC is not supported

    Transactions work with a group of messages

    but not in a Transaction scope containing any

    SQL server, either Sql Azure or Sql Server.

  • 7/31/2019 CodepaLOUsa 2012

    30/31

    Resources used in the slides

    An Introduction to Service Bus Topics

    http://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspx

    An Introduction to Service Bus Queues

    http://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspx

    How to Use Service Bus Queues

    https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/

    How to Use Service Bus Topics/Subscriptions

    https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/

    Windows Azure Queues and Windows Azure Service Bus Queues - Compared and Contrasted

    http://msdn.microsoft.com/en-us/library/hh767287(VS.103).aspx

    Service Bus Home Page

    http://msdn.microsoft.com/en-us/library/windowsazure/ee732537.aspx

    Wikipedia Enterprise Service Bus http://en.wikipedia.org/wiki/Enterprise_service_bus

    http://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttps://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/http://msdn.microsoft.com/en-us/library/hh767287(VS.103).aspxhttp://msdn.microsoft.com/en-us/library/windowsazure/ee732537.aspxhttp://en.wikipedia.org/wiki/Enterprise_service_bushttp://en.wikipedia.org/wiki/Enterprise_service_bushttp://msdn.microsoft.com/en-us/library/windowsazure/ee732537.aspxhttp://msdn.microsoft.com/en-us/library/windowsazure/ee732537.aspxhttp://msdn.microsoft.com/en-us/library/windowsazure/ee732537.aspxhttp://msdn.microsoft.com/en-us/library/windowsazure/ee732537.aspxhttp://msdn.microsoft.com/en-us/library/hh767287(VS.103).aspxhttp://msdn.microsoft.com/en-us/library/hh767287(VS.103).aspxhttp://msdn.microsoft.com/en-us/library/hh767287(VS.103).aspxhttp://msdn.microsoft.com/en-us/library/hh767287(VS.103).aspxhttp://msdn.microsoft.com/en-us/library/hh767287(VS.103).aspxhttps://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/http://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspxhttp://blogs.msdn.com/b/appfabric/archive/2011/05/25/an-introduction-to-service-bus-topics.aspx
  • 7/31/2019 CodepaLOUsa 2012

    31/31

    Items covered if time allows

    Dead Lettering

    PrefetchCount You can use PrefetchCount to fetch multiple messages

    from the server in the same round-trip. This can be useful

    in scenarios that need lower latency for receiving existingmessages from a queue or subscription. Prefetch can alsoimprove throughput depending upon the scenarios as thenumber of round-trips to the server are reduced.

    Prefetch is disabled by default. You can enable it by usingthis property on the client. You mustset PrefetchCount before receiving the first message.

    Defer Support

    Session Support