Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed...

25
Windows Communication Foundation Windows Communication Foundation (“Indigo”): (“Indigo”): Writing Reliable and Transacted Distributed Writing Reliable and Transacted Distributed Applications Applications Shy “BAD-P” Cohen Shy “BAD-P” Cohen COM307 COM307 Program Manager Program Manager Connected Systems Division Connected Systems Division Microsoft Corporation Microsoft Corporation

Transcript of Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed...

Page 1: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

Windows Communication Foundation Windows Communication Foundation (“Indigo”): (“Indigo”): Writing Reliable and Transacted Distributed Writing Reliable and Transacted Distributed ApplicationsApplications

Shy “BAD-P” CohenShy “BAD-P” CohenCOM307COM307Program ManagerProgram ManagerConnected Systems DivisionConnected Systems DivisionMicrosoft CorporationMicrosoft Corporation

Page 2: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

2

Moving To Service Moving To Service OrientationOrientation

Threads versus MessagesThreads versus MessagesBAD P! BAD, BAD P!BAD P! BAD, BAD P!

Why don’t you come back? Please Why don’t you come back? Please hurry… ♫hurry… ♫

Keeping it ConsistentKeeping it ConsistentAll together now!All together now!

Page 3: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

3

Challenges Of Challenges Of Implementing Reliable Implementing Reliable Distributed SystemsDistributed SystemsCommunication Communication

IssuesIssuesNetwork unavailableNetwork unavailableConnection dropsConnection dropsNetwork loses Network loses messagesmessagesMessages may arrive Messages may arrive out of orderout of order

Messages may take Messages may take different pathsdifferent pathsRetried messages may Retried messages may arrive after the ones arrive after the ones that followed themthat followed them

Processing IssuesProcessing IssuesMessages lost when Messages lost when processing failsprocessing failsInterrelated Interrelated Messages processed Messages processed individuallyindividuallyFailure may leave Failure may leave the distributed the distributed system in an system in an inconsistent stateinconsistent stateMessages can’t be Messages can’t be retried without side retried without side effectseffects

Retried messages Retried messages arriving twice, arriving twice, reordering, etc.reordering, etc.

Page 4: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

4

Making It ReliableMaking It Reliable

Reliable Reliable SessionSession

ssTransactionTransaction

ss

QueuesQueues

Page 5: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

5

SessionsSessions

ChannelChannel

Service Instance

ChannelChannel

Proxy

SessionSessionSessionSession

Page 6: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

8

Session State And LifetimeSession State And Lifetime

Page 7: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

9

Reliable Sessions Reliable Sessions AssurancesAssurances

Messages are delivered exactly once, in the Messages are delivered exactly once, in the same order as they were sentsame order as they were sent

Alternatively, you can choose to have them Alternatively, you can choose to have them delivered in order in which they were receiveddelivered in order in which they were received

Resilient toResilient toTransport disconnectionsTransport disconnections

SOAP or transport intermediary failuresSOAP or transport intermediary failures

FeaturesFeaturesConnection verification and maintenanceConnection verification and maintenance

Congestion and flow controlCongestion and flow control

Page 8: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

10

Reliable SessionsReliable SessionsEnablingEnabling

Provided on Standard BindingsProvided on Standard BindingsnetTcpBinding netTcpBinding (off by default)

wsHttpBinding wsHttpBinding (off by default)

wsDualHttpBinding wsDualHttpBinding (always on)

Can be added to any custom bindingCan be added to any custom binding

<bindings><customBinding>

<binding configurationName=”ReliabilityHTTP”><reliableSession/><httpTransport/>

</binding></customBinding>

</bindings>

Page 9: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

11

Ordered And Unordered Ordered And Unordered Reliable SessionsReliable Sessions

Page 10: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

13

Keeping It ConsistentKeeping It Consistent

Atomic Transactions versus Atomic Transactions versus CompensationCompensation

Trading off coupling and complexityTrading off coupling and complexityAtomic Transactions: simpler, tighter Atomic Transactions: simpler, tighter couplingcoupling

Compensation: more complex, looser Compensation: more complex, looser couplingcoupling

Both have their placeBoth have their placeChoose the right model for the situationChoose the right model for the situation

Page 11: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

18

Transacted OperationsTransacted Operations

Page 12: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

19

TransactionsTransactionsSummarySummary

Service Developer (Code)Service Developer (Code)Declares willingness to participate in an incoming Declares willingness to participate in an incoming (client initiated) transaction on contract (client initiated) transaction on contract operationsoperations

No transaction sharing on one-way operations! *No transaction sharing on one-way operations! *

Specified implementation behavioral aspects at Specified implementation behavioral aspects at the service and method levelthe service and method level

Client Developer (Code)Client Developer (Code)Creates transactionsCreates transactionsIncludes services & local TX-ed resources in their Includes services & local TX-ed resources in their scopescope

Service Administrator (Config)Service Administrator (Config)On/Off switch controls TX flow support for an On/Off switch controls TX flow support for an endpointendpointIt’s about TrustIt’s about Trust

Page 13: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

20

QueuesQueues

Increase availabilityIncrease availabilityMask network or service unavailabilityMask network or service unavailability

Support scale outSupport scale outMultiple readers from a single queueMultiple readers from a single queue

Provide load levelingProvide load levelingHandle average, not peak loadHandle average, not peak load

Are a building block for compensating Are a building block for compensating business transactionsbusiness transactions

Reliable, durable messaging to capture Reliable, durable messaging to capture distributed distributed state changesstate changes

Need to compensate for errorsNeed to compensate for errors

Page 14: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

21

QueuesQueues

Make one-way operations possible even when Make one-way operations possible even when the service isn’t availablethe service isn’t availableSupported via MSMQSupported via MSMQ

Programmer uses regular WCF channelsProgrammer uses regular WCF channelsIT Pro manages the familiar MSMQ serviceIT Pro manages the familiar MSMQ service

MSMQMSMQMSMQMSMQ

ClienClientt

ServicServicee

Page 15: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

24

Basic Queued MessagingBasic Queued Messaging

Page 16: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

25

QueuesQueuesComposing with TXsComposing with TXs

Operation requires 2 transactionsOperation requires 2 transactionsTX between client and queue to sendTX between client and queue to send

Another TX between service and queue Another TX between service and queue to receiveto receive

If a transaction abortsIf a transaction abortsMessage sent under the TX are Message sent under the TX are discardeddiscarded

Messages received under the TX are Messages received under the TX are retriedretried

Page 17: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

26

QueuesQueuesMEPsMEPs

DatagramsDatagramsStandalone messagesStandalone messages

Can be sent and received with or without Can be sent and received with or without using a transactionusing a transaction

““Exactly Once” or “Best Effort” deliveryExactly Once” or “Best Effort” delivery

““Sessiongram”Sessiongram”A grouping of related messagesA grouping of related messages

Always processed together under a Always processed together under a single TXsingle TX

““Exactly Once, In Order” deliveryExactly Once, In Order” delivery

Page 18: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

29

Queues, Transactions, Queues, Transactions, And SessionsAnd Sessions

Page 19: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

30

QueuesQueuesThe dead letter queueThe dead letter queue

Stores messages that could not be Stores messages that could not be delivereddelivered

Can be processed like any other queueCan be processed like any other queue

New in Windows VistaNew in Windows Vista: User specified DLQ: User specified DLQIf not specified, the default is the system-wide If not specified, the default is the system-wide DLQDLQ

With a shared DLQ, processing service needs to With a shared DLQ, processing service needs to implement all the contracts for all the messages implement all the contracts for all the messages

going into itgoing into it

Alternatively, use System.Messaging to process Alternatively, use System.Messaging to process messages from the Dead Letter Queuemessages from the Dead Letter Queue

Page 20: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

31

QueuesQueuesPoison messagesPoison messages

Messages for whom processing fails, Messages for whom processing fails, repeatedly, are considered “poison”repeatedly, are considered “poison”

Failure = the processing transaction Failure = the processing transaction abortedaborted

Message properties indicate how Message properties indicate how many times a message was deliveredmany times a message was delivered

MsmqMessageProperty msmqMessageProperty;msmqMessageProperty = OperationContext.Current.IncomingMessageProperties[MsmqMessageProperty.Name]

as MsmqMessageProperty;if (prop.TotalAbortCount > myRetryThreshold) { /* Do something */ }

Page 21: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

32

QueuesQueuesPoison messagesPoison messages

New in Windows VistaNew in Windows Vista: Automatic : Automatic protection against repeated failuresprotection against repeated failures

By limiting NUMBER By limiting NUMBER of retriesof retries

By controlling HOWBy controlling HOWretries are doneretries are done

<netProfileMsmqBinding> <binding configurationName=“QB" maxImmediateRetries="2" retryCycleDelay="0:0:10" maxRetryCycles="3" rejectAfterLastRetry="false" /></netProfileMsmqBinding>

10 seconds between attempts

3 retry cycles

2 retrie

s

To Poison Message Queue

1st attempt

Page 22: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

33

Q’sQ’sFailure compensationFailure compensation

Set up compensation services on the Set up compensation services on the sending and receiving sidessending and receiving sides

<binding configurationName="MyQueueBinding“ ... timeToLive="0:2:0" deadLetterQueue= "net.msmq://MyClient/private/myCustomDLQ"/>

<endpoint address ="net.msmq://MyServer/private/MyQueue;poison/” bindingSectionName="netProfileMsmqBinding" bindingConfiguration ="MyQueueBinding" contractType="Queue.IPurchaseOrder, Queues" />

Page 23: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

34

When Faced With When Faced With ChallengesChallenges

WCF provides sophisticated session WCF provides sophisticated session mgmtmgmt

Session lifetime and associated stateSession lifetime and associated state

WCF assuresWCF assures… … that messages arrive exactly oncethat messages arrive exactly once

… … in the order in which they were sentin the order in which they were sent

WCF provides transacted state WCF provides transacted state managementmanagement

Computation and communicationComputation and communication

WCF provides high availabilityWCF provides high availabilityDurability, atomicity, and error handlingDurability, atomicity, and error handling

Page 24: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

35

Community ResourcesCommunity Resources

At the PDCAt the PDCMore on Windows Communication FoundationMore on Windows Communication Foundation

Attend the other WCF presentationsAttend the other WCF presentations

Talk to me and the other WCF folks at the Lounge, Ask The Talk to me and the other WCF folks at the Lounge, Ask The Experts, or at any other timeExperts, or at any other time

More on System.TransactionsMore on System.TransactionsGo talk to Max (COM lounge) or Jim (FUN lounge)Go talk to Max (COM lounge) or Jim (FUN lounge)

Attend FUN320 tomorrowAttend FUN320 tomorrow

Do the HOLs: WCF HOLs, FUN HOL13 (TXF & TXR)Do the HOLs: WCF HOLs, FUN HOL13 (TXF & TXR)

After the PDCAfter the PDCMSDN dev center: MSDN dev center: http://msdn.microsoft.com/webservices/http://msdn.microsoft.com/webservices/

MSDN ForumsMSDN Forums

Channel 9 tag: http://channel9.msdn.com/tags/IndigoChannel 9 tag: http://channel9.msdn.com/tags/Indigo

Contact me: [email protected] me: [email protected]

Page 25: Windows Communication Foundation (“Indigo”): Writing Reliable and Transacted Distributed Applications Shy “BAD-P” Cohen COM307 Program Manager Connected.

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.