Вы находитесь на странице: 1из 395

Windows Azure:

(Dominic Betts)
(Julian Dominguez)
(Grigori Melnik)
(Fernando Simonazzi)
(Mani Subramanian)

Patterns & Practices


CQRS

CQRS

Windows Azure: ,


CQRS

Windows Azure:
,

(Dominic Betts)
(Julian Dominguez)
(Grigori Melnik)
(Fernando Simonazzi)
(Mani Subramanian)

978-1-62114-017-7
. ,
, URL-
- ,
.
, ,
.
.

,
Microsoft.

. .
Microsoft, 2012 . .
Microsoft, MSDN, SQL Azure, SQL Server, Visual Studio, Windows
Windows Azure
Microsoft.
.

xvii

xxi

xxiii


?
CQRS

xxiii
xxiii
xxiv

CQRS

xxv
xxv

CQRS
CQRS

xxv
xxvi
xxvi

xxvi
xxvii
xxviii

xxix

1. :
Contoso
?
Contoso

2.
,

,
Contoso
?

3.

1
1
2
3

3
4
4

4
4
5
5
5

7
7
8

9
10
11
11

13
13
14
v

vi
( )

15
17
18
18

23
24
25
25
25

26

1.

27

2.

28

3.
4. -
5.
6.

28
29
29
29

Windows Azure

CommandBus EventBus?
?
?
?
?

4.

31
31
34
40

42
44
48
48
48
48
49
49
52
52


53

53

53
54


54
,
55


55




IQueryable
DAO


CQRS

55
56

56
56
57
57
59

60
61
62
62

vii



ASP.NET MVC


SeatsAvailability
AddSeats ( )


SpecFlow


: ,

5. V1

63
64
66
69
72
73
74
74

74
74
76

81
84

84
85
87
91
91

125

Contoso, V1

125

125
126


CRUD


Windows Azure

126
126
126

127
131
131

131
132

133
135
135
136
138
138
139

139
139

140
140
140

141
141
142

142
142

143

viii
-,
145

Windows Azure

147
147
151
152

154
156
157

157
157
158
158

6.

159

159
160

160
160
160

160
161

162
162
162

162
163

165
167
167

168

RegistrationProcessManager

168
168
170

172


172

174

174

V1 V2

175
176
180
180
180
182

184

185
-
185

185

185

SpecFlow

186

ix

7.



1
2




ES


SeatsAvailability





RegistrationProcessManager

189
189
189

157
157
158
159

161
161
162

162
163
164
165

165
165
166
166
167
167
167
167
168
168
169
171
172

173
174

174

SeatsReserved
175
OrderPlaced
178
Registration-Process-Manager

178


memento


SessionSubscriptionReceiver
SeatsAvailability

181
186
186
186
186

186
189
191
192
193
194
195

196

GUID
196
MVC- ASP.NET
198
Windows Azure 198

x


MakeSeatReservation

199
199
199
199
200

200
200

200
200

8. :

201

201


201

202
,
203
CQRS
204

205

206
CQRS
206
-, ?
207


207

207

208

208

208
, CQRS

208

208

209
,

209
,
210

1. CQRS
- ?
- :



, -






CQRS DDD

2. CQRS:

210

211
212
212

213
213
214
215
215

217
218
218
219
220
220
221

223

xi
CQRS?


CQRS -
,
CQRS



CQRS
CQRS?




CQRS?

3. ES:
?

ORM

, ES
CQRS ES

4. CQRS ES



- (DDD)



223

225
227
228
230

230
231
231
232
232
232
232

233
233
234
234
234
234

235
236

236
240
242
243
245
245

245
245
245
246

247
247

247
247
248
248
248
248
249

249
250
253

254
254

255
257
257

257
259

260

xii




CQRS


CQRS

260

261
261
262
264
267
268

268
269

269

269
270
270
270





,
Windows Azure


Windows Azure


270
271
271
271
272
273

274
274
275
276
277


Windows Azure
279

280

5.

6.

CQRS
?
?
?
CQRS

7. ,
Windows Azure

280

281
281
281
281
282

282
282
282
282
283

285
285
286

286
286
290
290
290
290

291
291

xiii


API




292
293
294
294
294
294
294
295

295

Unity Application Block

296

296

. Twilio

. Lokad

-



ES

. DDD CQRS


(Inversion of Control, IoC)

. TOPAZ Technologies

296

297
297
297

297
297
298
298
298
299
299

300
300
300

301
301
301
301
301
301
301
302
302
302

303
303
304

304
304
304
304
305
305

306
309
309

310

xiv
CQRS ES?


. -?

. eMoney Nexus
eMoney Nexus: CQRS
eMoney Nexus

1.




SQL Express
Windows Azure SQL
Settings.xml

310
310
311
311
311
311

312
312
312
313
314
320
321

323
323
323
324
325
325

325
325
327
327

328

Release
Debug
DebugLocal

328
328
328
328

1. -, SQL, SQL
328
2. -, Windows Azure,

329
3. , SQL, SQL
329
4. , Windows Azure,

329
5. Windows Azure, Windows Azure,

329

2.
V1 V2



V2 V3

329

329
330
330
330

331
331

331
332
333
333

335

, Patterns & Practices.


, .
-
CQRS Event Sourcing. , ,
. ,
Windows Azure, .
!
(Scott Guthrie), -, Azure, Microsoft
Patterns & Practices CQRS
. ,
. ,
, CQRS.
, , ,
. ,
CQRS.
, , Auth10
CQRS ,
CQRS .
, ,
CQRS.
.
(Dan Piessens), , Zywave
.
( ),
. ,
, . , .
.
(Ksenia Mukhortova), -, Intel
CQRS . ,
. ,
. ; .
,
. ,
.

xvii

xviii
(Christopher Bennage), , Microsoft
Windows Azure: SQL (
), ( ) ( ).
,
( API-), .
(Bill Wilder), MVP,
,
Microsoft,
.
(Adam Dymitruk),
, Patterns & Practices, . ,
.
CQRS.
, CQRS .
(Glenn Block), , Microsoft, Windows Azure
SDK Node.js, ALT.NET
, Patterns & Practices
. ,
, .
.
, !
(Josh Elster), , Liquid Electron
CQRS ,
. ,
, (, , ,
). , CQRS
. , Patterns & Practices
Microsoft
.
CQRS.
(Shy Cohen), , Shy Cohen Consulting
Patterns & Practices ,
CQRS. ,
.
,
Patterns & Practices .
, GitHub.
, .
Patterns & Practices , ,
.
(Kelly Sommers),
. P&P
Twitter, .
, P&P. , ,
.
(Neil Mackenzie), MVP Windows Azure

xix
CQRS , .
CQRS.
( : )
,
. ,
, .
,
. ,
. , ,
.
(Clemens Vasters), , Microsoft
, Patterns & Practices, . ,
8, .
, Patterns & Practices
. , (Greg
Young) (Udi Dahan), , 8,
.
. ,
.
(Jon Wagner), SVP , eMoney
CQRS, Patterns & Practices,
CQRS. ,
. ,
, ,
CQRS. ,
.
, .
,
CQRS, .
(Chris Keyser), - , CaseNetwork
,
.
(Rinat Abdullin), , Lokad
.
.
(Truong Nguyen), , Nepsoft
. .
(Christian Horsdal Gammelgaard),
, Mj0lner Informatics

, 3 . Patterns & Practices.


Command and Query Responsibility Segregation (CQRS) Event Sourcing (ES).
. .
, Windows Azure, 200 ,
, . .
Twitter.
, Microsoft CQRS.
Patterns & Practices .
GitHub .
.

. DDD, CQRS ES
. .
. , , ,
. ,
. ,
Event Store ( ) Transaction Log ( ).
, . ,
.
, .
. ,
. .
, ,
. , ,
CQRS. .
, .
. Patterns & Practices
,
.

xxi

xxii

,
. , .
, .
, .
, ,
.
1 2.
. .
-? , ,
. ,
. .
, ,
. , :
. ,
,
. ,
Windows Azure.
CQRS/ES,
.
, . ,
Patterns & Practices, .
,
, , ,
CQRS ES.
.
. ,
, . ,
, . .
, .
OSS. ,
. ,
.
, Patterns & Practices , .
.
.
. Windows Azure,
.

.
-


Command Query Responsibility Segregation (CQRS) Event Sourcing (ES)
,
. , , ,
CQRS Event Sourcing.
, , .
, , ,
,
.
CQRS Event Sourcing.
CQRS Event Sourcing. ,
CQRS Event Sourcing .
.
.
.
CQRS Event Sourcing ,
.
. , CQRS.

?
, .
(Reference Implementation, RI),
CQRS Event Sourcing
.
, , ,
.

xxiii

xxiv

, , , :
CQRS, CQRS ,
CQRS . , 1,
: ,
.

CQRS
7.

2.


6.

5.
V1

8.
4.

SQRS
3. BC 1:

1.

1.
CQRS

CQRS
. ,
. ,
, ,
. ,
.
CQRS
, .

xxv

. ,
, .
,
.
, CQRS,
.
. CQRS
. , ,
, .
,
cqrsjourney@microsoft.com.
.
.

CQRS
,
. .
, CQRS.


, ,
CQRS Event Sourcing .
, .
, .
.

CQRS

1. Contoso.
( ).
2. .
.
3. .
, CQRS
.
4. .
.
5. V1.
; , .
.
6. .
.
7. .
, , ,
. .
8. . .
.

xxvi

CQRS

1. CQRS . CQRS,
- .
2. CQRS. CQRS.
3. Event Sourcing.
(Event Sourcing, ES).
4. CQRS ES. CQRS
ES.
5. .
.
6. . :
. .
7. , .
, Windows Azure.
1. . ,
.
2. .
Contoso.

1. Twilio. ,
. CQRS,
CQRS.
2. Lokad Hub. ,
- , CQRS ES ,
.
3. DDD/CQRS . ,
- CQRS
. CQRS
, .
4. .
. , ,
CQRS.
5. TOPAZ Technologies. , CQRS ES
.
6. Emoney Nexus.
CQRS ES. ,
, ,
CQRS.



. .
,
CQRS.
.
:

xxvii

. , ,
, .
: , ,
.
, , .
. ,
.
. ,
.
.
. Windows Azure
CQRS .
.
, , CQRS.

(CQRS, CQRS/ES CRUD) .
, , .
. ,
.
. 1
: Contoso.

:
. .






2.
:

xxviii


.
. ,
. .
MSDN: http://msdn.microsoft.com/en-us/library/jj619274.

(1913 .) :
5000 ...
,
. 70
( ,
)

,
!
.
,

:
( Microsoft)
( Microsoft), (Clarius
Consulting)
( Microsoft), (Digit Factory),
(Infosys Technologies Ltd.)
(Content Master Ltd.), , ,
( Microsoft) (Clarius Consulting)
(JetStyle)
, ( Microsoft),
(Content Master Ltd.) (Linda Werner & Associates Inc)
.
,
, .
DDD/CQRS. ,
, , .
. .
, . . ,
. . ,
.
.

xxix

xxx

,
:
,
;

,
;

,
;

GitHub ;

OSS
;

MIL (Messaging
Intermediate Language) ;


, ;

,
;

Node.js;

, ;

GitHub
, Excel
;

, , , ,
;

CQRS Patterns &Practices


;

CQRS SpecFlow;

,
;

, , , , .
- .

.
!

1.

:

: ,
?

Contoso. Contoso,
Contoso. ,
, .
.
, Contoso
CQRS ES. , Contoso
CQRS ES.
.
Contoso.
, .

Contoso
Contoso ,
20 . Microsoft.
Contoso Microsoft,
.NET Framework, ASP.NET MVC Windows Azure.
- , CQRS.
-, Contoso
. Contoso ,
-.
. ,
. ,

. Contoso
Windows Azure, .

?
, CQRS
. .
CQRS, , , , IT -. .

CQRS. , CQRS
.
, .

CQRS . ,
CQRS, .

.
. , .
, ,
, ,
. ,
- .
, , -,
, ,
.


CQRS. ,
.
. . ,
.
, .
, .

. ,
. ,
. :
, - .

, , ,

.

-, .
,
, .
,
. ,

(SLA).

-. .
, , ,
. . ,
.
.
-,
.
- ,
.

Contoso
Contoso ,
. CQRS. , ,
, . :
.

, ,
.


Contoso - ,
, , .
Contoso :
.
.
Contoso ,
. - ,
.


- . -
, , -,
. - , .
,
, .
: ,
.

.


- , ,
. -
Contoso ( ) ( ).
, - .
- :
;

Contoso ;

, .


Contoso :
. , CQRS
.

. ,
.
, Windows Azure,
( ) . ,
.
, CQRS Contoso Azure,
. ,
.
Contoso
Windows Azure.

Contoso
.
, Contoso

. , ,
:
Contoso
.


,
,
.
, ,
,
.

Contoso
.
.

Contoso ,
.

Contoso
:
,

.

Contoso

,

. Contoso



.


CQRS.
Contoso,
.
Contoso.


http://msdn.microsoft.com/en-us/library/jj619274.

CQRS ,

CQRS .

2.

Contoso.
,
.
-
(Domain-Driven Design, DDD), Domain-Driven Design: Tackling Complexity in
the Heart of Software (Addison-Wesley Professional, 2003). -
CQRS? .
, ,
, CQRS.
, CQRS , -
CQRS.

,
, .
1 CQRS .
. - Contoso
( ). 1 : Contoso
.

CQRS

,
.

,


.




,
.
,
,

.

.
.
;
.

.

:

.
. ,
,

. .
,
,
.

.
,
.
, .
.

.
,
. .
15 ,
, .
15 , ,
.
.
-
. - ,
,
.
-.

- :
, ( URL-,
).
.

, .

, - ,
.
- -
.
.
.

.
.
, -
( , ) -
.

,
,
Contoso.
. CQRS.
, - CQRS
cqrsjourney@microsoft.com.
.
.
.
.
. ,
.
.

Node.js.
. ,
.
- CQRS.

10


CONTOSO

,

CQRS
,

.


,
,

.


.




.



. ,
,


,
,


(

,
,
4


).

1 ,
,
.
. ,
, ,
.
, CQRS ES, .
1 ,
Contoso.
,
.

(CRUD)


(CQRS/ES)

(CQRS)
1.
Contoso

11


1. ,
.
1. , ,
. ,
.
2. , .
, .
3. .
4. , .


?
,
.
.
, . ,
,
.
,
, .
, , ,
.
V2. ,
,
. OrderPaymentConfirmed (
) OrderConfirmed ( ).
, .
,

: CQRS, CQRS/ES,
, CRUD.



http://msdn.microsoft.com/en-us/library/jj619274.

,


,

.
:


,

, ,

(Create, Read, Update and
Delete, CRUD).



.
. 5
V1.

Contoso .
,
.

3.



CQRS.
. .


,
.
() .
( 5 V1).
CQRS.
.
. .
, .
: ,
.
Contoso, ,
. ,
. .
,
. ,
- .
,
.
- CQRS.

13

14


,


,
6

.

, .

CQRS ES.
.
, .
; MakeSeatReservation
( ).

, ,
.
.
, .

.
. , OrderConfirmed,
.
.
.
.
;
,
.
.
.
,
. ,
, ,
, .
-.
.
,
,
.

, 312321
(Gregor Hohpe) (Bobby Woolf) Enterprise Integration
Patterns: Designing, Building, and Deploying Messaging Solutions (AddisonWesley Professional, 2003).

, ,
.


4
.


.

CQRS .

( )
, .

.
. , .
, ,
.
;
, , .
(, , ,
).
. , ,
. ,
. .
. , ,
, , - .
.
, .
, ,
.
. ,
.

.
.
, . ,
.
.
. .
.
: , .
. ,
,
.
,
.


,

.


,


.


.

15

16

. ,
, . -
. - .
. .
. ,
.
. ,
, . ,
, .
. .
.
. , . -
; .
.
. ,
, URL-. .
,
.
.
1: : ,
. , ,
.
1: . ,
; , , .
, .
1: , , .
1: , , ?
2: .
.
1: , ?
1: , ,
, . , ,
, , , .

1: . ,
. ,
, .
; ,
, . (,
, , ).


, , .
: , , .
, ,
.
1 ,
.

1.

17

18

:

.


CQRS
,



,


.

,

,

:

.


Windows
Azure, ,

(Domain Driven Design,


DDD) CQRS.
(Josh
Elster),
CQRS

, .

, .

- .

Windows Azure.
-, ASP.NET MVC, ,
.
Windows Azure SQL ,
.
Windows Azure
.

Windows Azure.
- MVC
,
.
SQL Server Express SQL,
, SQL
Server Express.

. 1 .


,
.

, .
(ES) CQRS
, .
, ,
, .

,
.
.

. :
.

, .
, .
.

, , 2. .
: X Y 157

: 423

:

157


:
157

2.
1:



.
.

19

20

:
1.
X Y 157.
Order ().
2. Order , .
SeatsAvailability ( ).
3. SeatsAvailability 157
.

4. SeatsAvailability
.
5. SeatsAvailability
.
6. Order 4239
.


Memento.

3 , . .
: X Y 157


AggregateConference: 157

:

157

3.
2:

:
1. X Y 157.
Conference 157.
2. Conference 157 .
3. Order , SeatsAvailability
,
Conference.
4. SeatsAvailability .
5. Conference .

21

22

4.
.
: X Y 157

: 423

:

157


157


:
157

4.
3:

:
1. X Y 157.
Order.
2. Order 4239 .
3. Order , RegistrationProcessManager (
).

4. RegistrationProcessManager
SeatsAvailability 157.
5. SeatsAvailability .
6.
SeatsAvailability, .

. 6 .
:
:
Order SeatsAvailability?

,
?

,
.
. -
:

.

RegistrationProcessManager
.


Sagas,

-(Hector
Garcia-Molina)
(Kenneth Salem).

. ,


;


.

,

MVC (Model-View
Controller), .

23

24


,

.

: ,
Contoso
,


Contoso.


Order SeatsAvailability. Order
SeatsAvailability
.
SeatsAvailability Order
, Order (
) .
, ,
Order SeatsAvailability Conference
().

.

. , ,
, .


-
. ,

:
Order,
SeatsAvailability.
,

.
,
.

.
,
.
.

:
.
. :
( );
, ; .
(,
).
,
.
,
, .


, Order SeatsAvailability, ,
, . :
SeatsAvailability Order
. , .
.
.


,
. .
.
GitHub: mspnp/cqrs-journey-code.
,
. CQRS. ,
, .

25

26


,
CQRS, (ES). 5
: - MVC,
Windows Azure SQL , , .
.

- (MVC)

MVC

MVC

(
MVC)

( MVC)

MVC

(
MVC)

ORM

5.

SQL

, 5.

1.
ConferenceController ( ) Display (),
, .
, :

,
(Data Transfer Object, DTO).

27

28

2.
- .
, .
, .
RegistrationController RegisterToConference (
) .
. RegistrationController ,
, . . 6
.
, RegistrationController RegisterToConference:

3.
;
.
OrderCommandHandler ( ) RegisterToConference,
. , .
, OrderCommandHandler
RegisterToConference:

4. -
OrderCommandHandler Order. Order
,
. , .

5.
Order, Save ()
. Save , Order.

6.
,
RegisterToConference. ,
. , .
, RegistrationController
, .
WaitUntilUpdated ( ) ,
, , .

29

30

,
Post-Redirect-Get (--).
StartRegistration ( ).
Post-Redirect-Get . Post/Redirect/Get .

SpecifyRegistrantDetails ( )
. SpecifyRegistrantDetails
, .

, Post-Redirect-Get StartRegistration,
:
. ,
, MVC.

Order.

31

32

, . Id
(), UserId ( ), ConferenceId ( ) State
() .
.
1: , (Object-Relational Mapping, ORM). ,
. ,
.
2: , .
, .
. .NET, , .
.
1: CQRS .
.
2: CQRS (ES).
, , ,
?
1: ES, - .
, .
2: . ,
, . ,
, .
1: . ,
. , .
, ,
-
(ORM). , -:
, .
.
2: Order Order Items (
). , , ""?
, ?
1: Order Items ? , ,
. ,
Order Items , :
. ,
.
(Jeremie Chassaing) (Craig Wilson)

33

34


6 , . , Order
SeatsAvailability, . RegistrationProcessManager
.
6
.

RegisterToConference

ExpireOrder
PaymentReceived
(
(
ReservationAccepted

)
( )
()
()
)
MarkOrder
AsBooked (
Reservation

()
)
Rejected
()

RejectOrder
( )

Order
Aggregate Root
( )

Order

MakeSeat
Reservation
(
)

OrderPlaced
( )

CancelSeat
Reservation (


. :
- NotStarted
( )
- AwaitingReservation
Confirmation (
)
- AwaitingPayment (
)
- Completed (
)

CommitSeat
Reservation
(
)


ConferenceSeats
Availability

Reservation(s)
()

Conference
Seats
Availability

()

MakeSeat
Reservation

()

()

()

6.


RegisterToConference. Order.
Order. Order OrderPlaced ( ).
Order , . ,
GUID .

35

36

7 .
RegistrationProcessManager .
RegistrationProcessManager .

MakeSeatReservation,

SeatsAvailability. ,
, ,
.
SeatsAvailability MakeReservation,
. ,
SeatsAvailability
.

,


(Globally Unique Identifier, GUID)

.
GUID



.

37

38

RegistrationProcessManager ReservationAccepted ReservationRejected.


, .
. ,
.

, ,
ExpireOrder ( ),
MarkOrderAsBooked Order. ,
ReservationRejected Order.
,
ExpireOrder.
.
Order,
SeatsAvailability RegistrationProcessManager.
: ,
.

, ,
.
,
CQRS.

39

40

, 7,
.

( MVC)

Send

()
Handle
()

IRepository

Save

()

Handle
()

Save

Handle
()

7.

, MVC
. Send .
,
. ,
. , OrderCommandHandler
RegisterToConference, MarkOrderAsBooked, RejectOrder.
MarkOrderAsBooked.
, .

, IRepository,
.
.

RegistrationProcessManager.
.
RegistrationProcessManager.
,

,
,
.


,


Windows Azure
.
Windows
Azure

.

5
V1.

41

42

,
, ,
. IRepository
,
.

WINDOWS AZURE

Contoso

Windows Azure,



.


,

.
,



.
Windows
Azure Windows
Azure
MSDN Windows Azure Queues
Windows Azure Service Bus
Queues Compared and
Contrasted.

Windows Azure

.
Windows Azure, ,
.
8
. MVC
CommandBus ( ) EventBus (
) BrokeredMessage (,
)
Windows Azure.
CommandProcessor ( )
EventProcessor ( ),
SubscriptionReceiver ( ).
CommandProcessor , ()
; EventProcessor ,
.
.
Windows Azure
. Windows Azure
,
. ,
.

CommandBus Send
(Envelope<ICommand>)

EventBus
Publish(IEvent)

Reservation Rejected
(
)

MakeSeat
Reservation
( )

MakeSeat Reservation

TopicSender
Send(BrokeredMessage)

( )

Reservation
Rejected
(
)

TopicSender
Send(BrokeredMessage)

Windows Azure
: conference/command

: conference/events

(/)

(/)

MakeSeat
Reservation

MakeSeat
Reservation

SubscriptionReceiver
MassageReceived(BrokeredMessage)

SubscriptionReceiver
MassageReceived(BrokeredMessage)
CommandProcessor
ProcessMassage

EvenProcessor

Reservation
Rejected

SeatsAvailabilityHandler
Handle(MakeRecervation)
OrderCommandHandler
Handle(MakeRecervation)

ProcessMassage

Reservation
Rejected

RegistrationProcessHandler
Handle(ReservationRejected)
WaitListProcessHandler
Handle(ReservationRejected)

8.
Windows Azure

CommandBus EventBus .
Send Publish , Send , Envelope ().
Envelope .
. , 8,
ReservationRejected RegistrationProcessManager, WaitListProcessManager (
) . EventProcessor
. ,
.
. 8 MakeSeatReservation
SeatsAvailability. , .
CommandProcessor , .
.

43

44

:
?

CommandBus EventBus,
?

?
.

, ,



.

,

.

.
.
7

,
Windows Azure.

, .
, 8.
,
. -, Windows Azure
conference/commands ;
,
. -, CommandProcessor
.
Windows Azure
.
,
.
SubscriptionReceiver,
.
SubscriptionReceiver
,
Receive SubscriptionClient
.
,
Windows Azure,
. Windows Azure
,
, .
,
.

SubscriptionReceiver
.

45

46


Transient Fault
Handling (
)


.

SubscriptionClient ( ) Windows
Azure
. Receive
. .
Receive .
, Complete (),
. ,
Abandon (),
. .
(Complete Abandon)
, .
MessageReceived
SubscriptionReceiver,
Complete Abandon .
MessageProcessor

Complete

Abandon

BrokeredMessage, Message-Received
.

Complete Abandon
BrokeredMessage .

47

48


EventBus?

CommandBus


CommandBus EventBus . :
? ,
-.

,

:



.
, ,
. -

.
.


.


SubscriptionReceiver
Windows Azure. .
CommandBus,
EventBus TopicSender Windows
Azure.

Windows Azure . MSDN Best
Practices for Performance Improvements Using Service Bus Brokered Messaging.

?
:
Windows Azure
.
,
.
,
,
.
, .
Complete,
.


,

.
Windows Azure


,
-
Windows Azure.

(conference/commands)
(conference/events)
. ;
, .

CommandProcessor EventProcessor.
,
, ,
, ,
. ,

.

?
Contoso Json.NET.
, ,
. , .


, .
.
(Test-Driven Development, TDD).
TDD
CQRS .

,

Windows Azure .
,
,

.


.


.
,
Patterns & Practices

1: , TDD
. (,
), ,
. :
ORM.
2: ? .
, .
,
.
1: . , CQRS,
! ,
ORM , .
.
2: , .
1: , . ,
, ,
.
2: ; , , ,
, ORM
.
1: , .

49

50

2: : ,
, . , ,
, ORM .
,
ORM. , -,
, - ,
ORM.
.
Mocks Aren't Stubs.
Point/Counterpoint, (Steve
Freeman), (Nat Pryce) (Joshua Kerievsky).
, ,
xUnit.net.
,
, .

.

SeatsAvailability.
MakeReservation
. , MakeReservation ,
.
, , .
, ,
, . ,

.
, .
.

51

52

SeatsAvailability MakeReservation.
, .
, .
SeatsAvailability, .

CQRS.
, .
,
. ,
.



http://msdn.microsoft.com/en-us/library/jj619274.

4.




.
, , - .
,

,
.
, CQRS.
:
RegistrationProcessManager.
.

, ,
. .
, .

,
. ,
.

. ,
.
, - .

CQRS. MVC CQRS


.

Contoso, , .
, .
.


, .
4 CQRS ES.

53

54




;



, .



,



.

.
, .
; MakeSeatReservation.

,
, .
.
, .

.
. , OrderConfirmed,
.
.
.
.
;
,
.
.
.
,
. ,
, ,
, .
-.
.
,
,
.

.

, 312-321 (Gregor
Hohpe) (Bobby Woolf) Enterprise Integration Patterns:
Designing, Building, and Deploying Messaging Solutions (Addison-Wesley
Professional, 2003).



. ,
.




,
.

,
. , ,
, .

,
, .
. ,
( ), .
, ,
.



, .
,
.

Windows Azure.
-, - ASP.NET MVC, ,
. Windows
Azure SQL , .
Windows Azure . 1
.
SQL

- Windows Azure

- Windows Azure

- MVC

SQL

Windows
Azure
1.
Contoso

55

56


Windows Azure.
- MVC
,
.
SQL Server Express SQL,
, SQL
Server Express.

. 1 .


,
.
, .


,
.
.
.

.
,
;
.



;
.
, MVC.
CQRS
SQL
, MVC
. ,
, SQL
.
,
.



.
BLOB- Windows Azure
SQL
SeatAssignmentsViewModelGenerator.


,
,
. .
,
.
. ,

.
, ,
MVC, .

CQRS


.
,


MVC

ViewRepository
(
)

2.

2 (, MVC)
ViewRepository ( ), .
ViewRepository, ,
.
Contoso
ViewRepository: IQueryable
(Data Access Objects, DAO).

IQueryable
ViewRepository
IQueryable. LINQ (Language-Integrated
Query). IQueryable ORM, Entity
Framework NHibernate, .
.




-


(JOIN).

,
JOIN -


.


,
. .
(Martin Fowler) Catalog of Patterns of Enterprise Application
Architecture, Repository.

57

58

.
ORM .
.


Query.

.
,

.

LINQ,
, ,
.

LINQ .


Entity
Framework.


IQueryable. ,


ViewRepository


,
IQueryable.
- ,
.

IQueryable,
,
. ,
.

IQueryable .
,

.

,
Query.

DAO
, Find ()
Get () ViewRepository, .

DAO. .

. ,
IOrderSummaryDAO, IViewRepository.

.
.

Get Find ,
( - (ORM) SQL-
). .

Get Find ORM, LINQ IQueryable,


. .

, Find Get.

.
MVC- LINQ .

Find Get,
LINQ, .

DAO, .

59

60

:
IQueryable
, ,
.
,
.
.
,
. ConferenceDao
OrderDao Registration.



,
.

: , .
,
.
,
.
,
.
,
SQL, ,
.
, ,
.
3 ,
Order SeatsAvailability. ,
Order
.

HTTP,

, .


-
-

-
-

-
-



AccessCode

OrderPlaced
OrderUpdated
OrderPartiallyReserved
OrderRegistrantAssigned
OrderReservationCompleted

OrderViewModelGenerator

< >

<
>

ORM

Qwery <DraftOrder>
(
< >)


RequestedSeats
ReservedSeats

<
>

Display Action
(
)

3.

OrderViewModelGenerator ( )
OrderPlaced ( ), OrderUpdated (
),
OrderPartiallyReserved
(

),
OrderRegistrantAssigned ( ) OrderReservationCompleted
( ), DraftOrder
( ) DraftOrderItem ( )
.

CQRS
,
.
.
, ,
ASP.NET MVC.

5
V1 ,




,

(ES).

61

62

-. :
-
.

- .

, ,
, .
- -.
:


Patterns & Practices
Microsoft,


.



Windows Azure SQL,
Windows Azure,
Windows
Azure
Windows Azure.


. ,




.

. The
Transient Fault Handling
Application Block.

-
, .

,

.


,
. - ,
.
, .
, .

. ,
, , ,
.


,
.
.
.
, .
GitHub: https://github.com/ mspnp/cqrs-journeycode.
.
,
.
CQRS. ,
,
.


-

.
,


,
. , .
, .
Order.
Order.

Order,
. . .
OrderController ( ) -
MVC LocateOrder ( )
OrderId ( ). Find ()
OrderId Display (), .

63

64


.
RegistrationProcessManager, ,
SeatsAvailability, Order ,
. , Order ,
.

ReservationExpiration-Date
(
)


15
Order.

Order.
RegistrationProcess-Manager


.


Order
MarkSeatsAsReserved.

RegistrationProcessManager MarkSeatsAsReserved
Order ,
,
, .
ExpireRegistrationProcess (
)
. ,
RegistrationProcessManager

.
RegistrationProcessManager
Expiration ( )
MarkSeatsAsReserved ( )
, Delay ()
ExpireRegistrationProcess
.

MVC RegistrationController . DraftOrder


( ) ,
ViewBag, .

65

66

MVC JavaScript
.

ASP.NET MVC
, ,
MVC , .
MVC ,
, .

AssignRegistrantDetails ( ),
DataAnnotations ( ).
,
FirstName (), LastName () Email (
) .
, ,
.
.

.

MVC .
SpecifyRegistrantDetails.cshtml .

67

68

Web.config DataAnnotations ,
.

.
RegistrationController IsValid ()
. ,
.

RegisterToConference
StartRegistration RegistrationController.
. Models and Validation in ASP.NET MVC
MSDN.


. ,
, .
, SQL :
, , .
SQL :
OrdersView ( ) OrderItemsView ( ). OrderItemsView
RequestedSeats, , .

OrderId

ReservationExpirationDate

StateValue

. : Created, PartiallyReserved,
ReservationCompleted, Rejected, Confirmed (, ,
, , , )

RegistrantEmail

AccessCode

OrdersView

OrderItemID

SeatType ( )

RequestedSeats

ReservedSeats

OrderID

OrderId OrdersView

OrderItemsView

, ,
, . 3 .
OrderViewModelGenerator .

69

70

ConferenceRegistrationDbContext.

, ConferenceRegistrationDbContext
Save,
,
OrderViewModelGenerator.

71

72


DAO, MVC
.
ConferenceRegistrationDbContext.

SEATSAVAILABILITY
CQRS
ConferenceSeatsAvailabilty,
. ,
ConferenceSeatsAvailabilty SeatsAvailability,
, : ,
, .
4 SeatsAvailability .

, ConferenceDao ,
. MVC,
.

Seats Availability

MakeSeatReservation

CancelSeatReservation

CommitSeatReservation

SeatsReserved

(
)
(
, )

( )

( )




()
(
, )

( )

( )

4.
SeatsAvailability

:
.

PendingReservation
s (

73

74

SeatQuantity ( ),
.
ReservationAccepted ( ) ReservationRejected
( ) . SeatsReserved (
), , . ,
.
, , .

AddSeats ( )
, , 3 SeatsAvailability AddSeats
. AddSeats . -
.
, .
SeatsAvailability AddSeats .


, .


3
,
. ,
.
:
, ,
.


SpecFlow.

SpecFlow
SpecFlow.
.feature Visual Studio.
ConferenceConfiguration.feature, Features\UserInterface\Views\
Management. .
SpecFlow Given ( ), When () Then ().
, .

.feature- SpecFlow
Gherkin -
(Domain Specific Language, DSL),
.

75

76

,
Visual Studio Conference.AcceptanceTests.
, .

.feature ;
, .feature SpecFlow
.

Steps
()

Conference.Specflow

Conference.AcceptanceTests.
.
,
. -
WatiN .
.
, . ,
.


.
. Given, When
Then, .feature. SpecFlow
Given, When Then, .feature
:

77

78

, -.
, MVC-.
.
, .
.
SelfRegistrationEndToEndWithControllers.feature,
Features\UserInterface\Controllers\Registration:

SelfRegistrationEndToEndWithControllersSteps:

79

80

,
RegistrationController.

MVC

. ,

.feature SpecFlow.
xUnit.net.
Visual Studio,
, xUnit.net, ReSharper, CodeRush
TestDriven.NET.


, , CQRS
,
.
.
Order:

,


.

.


81

82

Order UpdateSeats.
, , , .
, , :

, Order.
, , , RegisterToConference
OrderUpdated.

83

84

: ,
, CQRS.
Contoso.

- , , .
, , , .
.
,
. . ,
.
.
, .
,
, .
.
!

. Conference
Visual Studio Conference.AcceptanceTests, SpecFlow.
.feature. ,
-.
.


.feature, :

85

86

, ,
:

, ( )
.
,
. ,
, (Behavior-Driven
Development, BDD).
,
-,
:
-
, .
,
.



. ,
.


. ,
-.


.
, , .
.
,
.

Contoso .

. ,
.
- , ,

.



, (. Meszaros, G.,
Melnik, G., Acceptance Test
Engineering Guide).


BDD ( ) .
. , SpecFlow
, ,
.
. .
ICommandBus AzureCommandBus.
.
, .
.


. ? ,
. ; ,
,
. , , IProcess ,
- ( ),
- . ,
,
. IoC DI
, , ,
, :
?

,
.
, .
RegistrationProcessManager.
1. , , ,
ProcessState. , NotStarted ( ).
, :
( ?)

( ?)

87

88

2. , (
). , Handle RegistrationProcessManagerRouter. : ,
!
(Aggregate Root, AR) AR. ,
ICommandHandler, .
3. , ,
; , .
, MakeSeatReservation
RegistrationProcessManager.

, .
.

,
.

4. find references ( ) OrderPlaced, ()


, Send
ICommandBus.
( ) .
, - , Send,
.
, . ,
.
. ,
, .
. ,
( 4 8). ,
:
+ + (NotStarted) + new() +
+ + 2 *N^n
(, , ) + ( !) > 8.
,
. , ?
- .
, :
, ,
.

, ,
.

, , (Messaging Intermediate
Language, MIL).

MIL LINQPad,
.
. ,
. Patterns & Practices.
- (Domain-Specific Language, DSL)
. , SawMIL toolbox,
, , MIL
. SawMIL toolbox http://jelster.github.com/
CqrsMessagingTools/.
MIL .
, ?,
DoSomething?. , ,
, SomethingHappened!.
MIL . ,
( Windows Azure, NServiceBus . .)
&&&&>.
. , ( .).
, , .
:

. ,
. MIL
, ,
:

, , ,
. , CQRS -
. ,
.

89

90

@. , - Twitter.
, .
, -, .
,
. .
, -.
:
, , ,
. AggregateRoot:

,
@AggregateRoot. (::).
. .
@Invoice CustomerSent!
CustomerInvoiceHandler.
, :

,
:

, State Change ( ).
, . MIL
. , *. ,
MIL, .
State Change:

,
. MIL .

, . ( )
, . ( <->
) .
, .
OSS.
OSS, http://jelster.github.com/CqrsMessagingTools/,
!



http://msdn.microsoft.com/enus/library/jj619274.

91

5.

V1

V1.
, , ,
, . ,
.

Contoso, V1
,
Contoso.
, ,
.
, ,
.
, CQRS .
V1 CQRS ES,
, V1 . ,
V1.
(User Interface, UI),
- . ,
.


, .
4 CQRS ES.
. - ,
. -
- .
, -
, .
(Event Sourcing, ES).
. , ,
. .
,
. , .

125

126

, ,
,
.
. ,
.
,
. ,
, .


,
.


-. - ,
.
. ,
.
. , , .
, .

- . -
, ,
. -.
- :
, ( URL-,
).
.
, .
, - ,
.
- -
.

, . ,
,
. , ,
.
,
.
, ,
-. Contoso
; -
-. Contoso -
. Contoso
.

. .
, .
.

1 Contoso
V1. - .
Windows Azure SQL ( SQL),
.
( 1) ,
(, MVC-,
).
. (,
OrderCommandHandler),
.


(CRUD)


(MVC 3)


(CQSR/ES)

Order
()

(CQRS)

1.
V1

ORM

Seat Availability
(
),

SQL

Seat Assignments
( ),

View model generator


DataAccess object
-ConferenceViewModelGenerator
-ConferenceDAO
-OrderViewModelGenerator
-OrderDAO
-PriceOrderViewModelGenerator
-SeatAssignmentsViewModelGenerator

SQL

()

()

ORM

ORM

-PaymentDAO

ORM

SQL

: Windows Azure

(MVC 4)

127

128

ConferenceController

MVC

ConferenceDetails

OrderController

MVC

AssignSeat
UnassignSeat

DraftOrder
OrderSeats
PricedOrder

RegistrationController

MVC

RegisterToConference
AssignRegistrantDetails
InitiateThirdPartyProcessorPayment

DraftOrder PricedOrder
SeatType

PaymentController

MVC

CompleteThird PartyProcessorPayment
CancelThirdPartyProcessorPayment

Third PartyProcessorPaymentDetails (
)

Conference Management

CRUD Bounded
Context

ConferenceCreated
ConferenceUpdated
ConferencePublished
ConferenceUnpublished
SeatCreated
SeatUpdated

OrderPlaced
OrderRegistrantAssigned
OrderTotalsCalculated
OrderPaymentConfirmed
SeatAssigned
SeatAssignmentUpdated
SeatUnassigned

Order

Aggregate

OrderPlaced
*OrderExpired
*OrderUpdated
*OrderPartiallyReserved
*OrderReservationCompleted
*OrderPaymentConfirmed
*OrderRegistrantAssigned

RegisterToConference
MarkSeatsAsReserved
RejectOrder
AssignRegistrantDetails
ConfirmOrderPayment

SeatsAvailability

Aggregate

SeatsReserved
*AvailableSeatsChanged
*SeatsReservationCommitted
*SeatsReservationCancelled

MakeSeatReservation
CancelSeatReservation
CommitSeatReservation
AddSeats
RemoveSeats

SeatAssignments

Aggregate

*SeatAssignmentsCreated
*SeatAssigned
*SeatUnassigned
*SeatAssignmentUpdated

AssignSeat UnassignSeat

RegistrationProcessManager

MakeSeatReservation
ExpireRegistrationProcess
MarkSeatsAsReserved
CancelSeatReservation
RejectOrder
CommitSeatReservation
ConfirmOrderPayment

OrderPlaced
PaymentCompleted
SeatsReserved
ExpireRegistrationProcess

RegistrationProcessManager

MakeSeatReservation
ExpireRegistrationProcess
MarkSeatsAsReserved
CancelSeatReservation
RejectOrder
CommitSeatReservation
ConfirmOrderPayment

OrderPlaced
PaymentCompleted
SeatsReserved
ExpireRegistrationProcess

OrderViewModelGenerator

DraftOrder

OrderPlaced
OrderUpdated
OrderPartiallyReserved
OrderReservationCompleted
OrderRegistrantAssigned

PricedOrderViewModelGenerator

SeatTypeName

ConferenceViewModelGenerator

Conference
AddSeats
RemoveSeats

ConferenceCreated
ConferenceUpdated
ConferencePublished
ConferenceUnpublished
**SeatCreated
**SeatUpdated

ThirdPartyProcessorPayment

Aggregate

PaymentCompleted
PaymentRejected (
)
PaymentInitiated

InitiateThird PartyProcessorPayment
CompleteThirdPartyProcessorPayment
CancelThird PartyProcessorPayment

* .
** ConferenceViewModelGenerator SeatCreated SeatUpdated
, .

129

130

Contoso:
.
.
DTO .
Windows Azure.
-, - ASP.NET MVC, ,
. SQL
, .
.
Windows Azure.
Windows Azure .

Windows Azure. - ASP.NET MVC
, .
SQL Server Express SQL,
, SQL
Server Express.
. SQL
,
.
.
. 1 .



-, CRUD. ASP.NET MVC 4 Entity Framework.

, CQRS.


,
. ,
.


Contoso
.
,
.
4
,
.
OrderViewModelGenerator ,
Order,
, .
,

.

.
.
,
Windows Azure. Windows Azure
BLOB- SQL
Windows Azure.




,
ASP.NET
MVC 3.
,
V3,

ASP.NET
MVC 4.


.



,



.
,
CQRS

V1
.
Windows Azure
.
.

131

132


,
,
,
,

Windows Azure .
SQL . BLOB- Windows
Azure .
,
. ,
.
, ,
.


,


SQL.

Windows Azure.
SQL Server,

,
.
,
CQRS


Windows Azure,
V1, ID
. ,
.
.
, ,
, .

Order Registration, .


.

Order.

133


,
.
. .
.


,


. , .
, ,
, .


.
Microsoft Inductive User Interface Guidelines Index of UX guidelines.

,
,
.
CRUD . .
CRUD , ,
2 ().

Patterns & Practices

29
2012 .

450,00

50

1
2012

48,00

50

29
2012 .

450,00

50

2.

CRUD,
Submit ().
, .
, .
, Add .

134

, , (Data Transfer Object,


DTO) .
. DTO. DTO
. DTO , CRUD
.
-:
, .
CQRS.
. .
, CQRS,
, DTO .
OrderDTO

ConferenceDTO
_______


(DTO)


(DTO)

-ID
-
-

-

( )

ConferenceDTO

_______
-

-
-

-
- ( )

RegisterToConference

- ID
- ID
- ( )

AssignRegistantDetails
-

ID

AssignRegistantDetails

3.
- ID

-
-
-

SetOrderPaymentDetails
- ID
-

- ID
-

3 ,
.
.
,
.
, , , .

, .
, 3, ,

. , ,
, , ,
.
. 4 CQRS ES
.

CRUD
CQRS .
,
. Contoso

, .

CRUD-.
CRUD
Why CRUD might be what they want, but may not be what
they need.



. , -
,
.
, ,
.

135



.

CRUD.
,



,
CQRS,


-

.

,
CQRS

CRUD.

CQRS
,

CRUD (

).


.
,

,
CQRS,

CQRS,
Task
UIs, Event Sourcing
Based

agh!

-

,
CQRS


.
.
CQRS
CRUD (


).

136



, .
1:
, CRUD. , -

, , ,
. -, - ,
.
2: ,
. .
1: .
2: ?
1: , , . , .
- .
, -
.
2: ?
1: CRUD.
,
.
- .
2: ? .
.
, .
.
1: ,
. , ,
, .
, .
2: , , ,
, . , -
50. , , , ,
?

1: , , ,
.
. , ,
.
2: ? ,
.
1: ,
.
2: , , ,
. -, Windows Azure
.
. -,
, .
: ,
. ;
.
1: ? ,
, , ?
2: .
,
. ,
. ,
.
,
. , ,
,
, .
, ,
.

. :
,
.
, .

,
.

CRUD
, .
,
,
.

.
,

(,


CRUD)

.
,

Patterns & Practices

,

.
,

(,


CRUD)

137

138

Windows Azure
,
. .
Windows Azure ,
. RequiresDuplicateDetection
PeekLock .
.

Microsoft (Microsoft Message Queuing,
MSMQ). MSMQ Windows Azure.
MSMQ Windows Azure
, Windows Azure AppFabric SDK.
Windows Azure . 7 ,
.



.
:
OrderPlaced, OrderRegistrantAssigned, OrderTotalsCalculated, OrderPaymentConfirmed, SeatAssignmentsCreated,
SeatAssignmentUpdated, SeatAssigned SeatUnassigned.
.
,
.
, ,
SQL, -
.
,
.
,
.
Contoso V1,
. :

, .


.
, .
. , OrderEventHandler
Conference.


-
. SeatUpdated,
ConferenceViewModelGenerator
; ,
.
.
(,
), .



.
, ,
,
.
:
,
, ,
.

,
.

;
,

.
;
,

.



.
,
.

,
. ,
, .

. -
.






PricedOrderViewModel
Generator ,

SeatUpdated

.






PricedOrderViewModel
Generator ,

SeatUpdated

.
, .
, Windows
Azure, , .
, .
, Windows
Azure, , .

139

140

:
.



.

, .
-
(, )
.

.

.
:
. -

.



.

.



,

.

,




.


.

.



,

, ,
(
) .
.

.
,

.
:

.
,
, .


-.
-
.
, .


, .

.



SQL
.

: , , BLOB Windows Azure.
BLOB- Windows Azure
.
. SeatAssignmentsViewModelGenerator
BLOB-.
SeatAssignmentsDao
.


,
.
,

.
. ,
. , .

Contoso

.

-


.





.
Contoso

.

-


.


,

( ).
,


.



,

( ).
,


.

141

142

,
,
, , ,
, .



, ,


(
).


, ,


(
).

,
.
.
.
, .
GitHub: https://github.com/mspnp/cqrs-journeycode. V1 Tags GitHub.
.
,
.
CQRS. ,
,
.


.
CRUD-,
ASP.NET MVC 4.
Visual Studio Conference ,
Conference.Web MVC.


, .
ConferenceCreated. -
.

ConferenceUpdated. -
.

ConferencePublished.
-.

ConferenceUnpublished.
-.

SeatCreated. -
.

SeatsAdded. -
.

ConferenceService Conference
.



, . V1

( , PayPal),
. ,
.
, 4,
, .
:
.


.

ThirdPartyProcessor
Payment
ThirdPartyProcessor
RegistrationControllers
PaymentControllers
(
( )
( )
( )
)


RegistrationControllersGetOrderDetails
PaymentControllers
IntitiateThirdPartyProcessorPayment
(

ThirdPartyProcessor
( )
( (
)

)
ThirdPartyProcessor Payment
( )
)
(
ThirdPartyProcessor
WaitUnitAvailable
GetOrderDetails

( )
( )

(
)

ThirdPartyProcessor
( )

)
IntitiateThirdPartyProcessorPayment
(

ThirdPartyProcessor)
)
Payment (
)

PaymentDetails
WaitUnitAvailable (
( )
)
(

PaymentDetails
ThirdPartyProcessor)
(
)
Payment (

PaymentInitiated
( )


PaymentInitiated
( )


ThirdPartyProcessor
( )

)
ThirdPartyProcessor

( )
PaymentAccepted ( ) ThirdPartyProcessor
ThirdPartyProcessor (
( )
)
PaymentRejected ( )

ThankYou
( )
SpecifyPaymentDetails
( )
ThankYou
( )
4.SpecifyPaymentDetails
( )

ThirdPartyProcessor

(
)
CompleteThirdPartyProcessorPayment
PaymentAccepted
(
)

)
ThirdPartyProcessor
(
CanselThirdPartyProcessorPayment
)
( )
PaymentRejected ( )

CompleteThirdPartyProcessorPayment
( )
CanselThirdPartyProcessorPayment
( )


PaymentCompleted (
)
PaymentRejected (
) (

)

PaymentCompleted (
)
PaymentRejected (
) (

)

143

144

4 ,
. ,
.
,
3. PaymentController ,
ThirdPartyProcessorPayment.
, , .
, CQRS
. RegistrationController Payment-Controller
.
RegistrationProcessManager .
CQRS .
ThirdPartyProcessorPayment, :
ThirdPartyProcessorPayment ThirdPartyProcessorPaymentItem.
SQL Entity Framework. PaymentsDbContext Entity Framework.
ThirdPartyProcessorPaymentCommandHandler ( )
.
Entity Framework. PaymentDao
.
GetThirdPartyProcessorPaymentDetails.

145

5
.

Entity Framework
PaymentReadDbContext
Entity Framework
PaymentReadDbContext



PaymentDAO
- ThirdPartyProcessor
- GetThirdPartyProcessorPayment
Details (
)

( )
PaymentDetails
( )

PaymentDAO

- GetThirdPartyProcessorPayment
Details (


)
- PaymentInitiated

( )
- PaymentCompleted
( )
- PaymentRejected
( )

Entity Framework
PaymentsDbContext
Entity Framework
PaymentsDbContext

( )
- PaymentCompleted
ThirdPartyProcessor

( )
(
)
Payment

()- PaymentRejected
( )
ThirdPartyProcessor

ThirdPartyProcessor
( )
PaymentItem (
)

5.

-RegistrationController
-PaymentController
( )

- PaymentInitiated

( )
ThirdPartyProcessor
Payment
(
() )
PaymentItem (
)

- ThirdPartyProcessor
( )
PaymentDetails
( )

-RegistrationController
-PaymentController
( )

- InitiateThirdPartyProcessorPayment
(
)
- CompleteThirdPartyProcessorPayment
( )
- CancelThirdPartyProcessorPayment (
)

- InitiateThirdPartyProcessorPayment

-,

, -
:
- CompleteThirdPartyProcessorPayment
,



(

)
- CancelThirdPartyProcessorPayment
(
.

.
)
.
, .

API.
. , .
, , .
, ,
.

146

Contoso , -
. .

, .
.
, - :
- .
.
,
.

( ,
).
,
.

,

- .

:
,
.
,
.
()
. :
.
,
.


,



.



,



-

.

,



.

,
. :
. ,
,
.
:

.

,
,
: , ,
. -:

, .
,
,
. ,
.
, .

,
.
.
.



:
.
, .
:
, ,
.

,
.

(,
) .


Order ,
OrderCommandHandler .
Order; ,
Order. MarkAsReserved
, ,
.

.



,

147

148

Order Update.
, Id Version EventSourced.

Update Id 1.
,
.

,
,

.
,
,

.

149

150

Order,
, .

.
, .
Order , Order.


Update EventSourcedAggregateRoot,
. IEnumerable
EventSourced Events.
OrderCommandHandler ,
Order , Order
.

Save SqlEventSourcedRepository.
. SQL-.
. ,
Windows Azure. SQL-
.
Windows Azure.

151

152


,
, .
,
.
,
Visual
Studio, , .
,



.

OrderCommandHandler


,
Find.
Visual
Studio, , .

SqlEventSourcedRepository ,
.


, Windows
Azure SqlEventSourcedRepository.

Windows Azure.

, Windows
Azure SqlEventSourcedRepository.

Windows Azure.

Order,
Invoke .

LoadFrom EventSourced, .
Order
.

153

154

,
, .
,
.
Save SqlEventRepository ,

. ,
, .

,
. .

,
, .
.

AZURE

Windows
Azure


.
Windows
Azure


.

WINDOWS

Windows Azure
,
SQL.
.

.
Windows Azure.
EventStore
.
, ,
Windows Azure.
Save EventStore.
Unpublished ,
.

155

156

. ,
.
Save . .
Save, , SendAsync EventStoreBusPublisher.

EventStoreBusPublisher
Windows
Azure, Windows Azure
.
Windows Azure
,
.
, ,
Windows Azure .

,
.

,


.




,
.

,


.

.

.

157

, -
, .

(.

ConferenceViewModelGenerator ).
Order
, . .
MarkAsReserved Order PricingService.


,
. : ,
.
:
ConferenceCreated, SeatCreated ConferencePublished.

. ,
,
.
Windows Azure
FIFO , .
, .
- ,
Windows Azure .

.
V2
. ,
,
.


4
,
;
.





.
,
JavaScript.

,
Order.




.
,
JavaScript.

,
Order.


.

CQRS

.


.

.
CQRS

V1.
.
,

.


.

158

.

. , ,
, ,
-
.


Contoso. ,
,
.
. CQRS
V2 .



http://msdn.microsoft.com/en-us/library/jj619274.

6.

, ,
CQRS .
, .
. , .
, Windows Azure.


, .
4 CQRS ES.
. , ,
. , MakeSeatReservation.
,
, .
. ,
.
.
. , OrderConfirmed, .
. .
, .
.
; ,
.
.
. , ,
. , x 10
, x .
, ( -
, ).

159

160


2
. ,

(
V3).


.
.



,
.
.

Windows Azure.
-,
- ASP.NET MVC, ,
.
Windows Azure SQL
, .
Windows Azure
.
1.

SQL

SQL

Windows
Azure

- MVC
- MVC
- Windows Azure
Conference.Web.Admin ( )

- Windows Azure Conference.Web.

Admin (- )
- Windows Azure

Conference.Web.Admin (
)
- Windows Azure Conference.Web.

Admin (- )

MVC

MVC

Windows
Azure



- Windows Azure WorkerRole

CommandProcessor (

-
Windows Azure
WorkerRole

CommandProcessor
(

Windows

Azure

Windows Azure

1.
V2


Windows Azure. - MVC
, .
SQL Server Express SQL,
, SQL Server Express.
. 1 .


, V1 V2.
.

161

162


V2,
:

. RegistrationProcessManager
.

ES, V2
.
,
.

:




.

.
,
. ,
.

.



. ( , )
,
, .
,
.

V2. .



.



.



.



.


V2
. V1
,
.

.
, 100
500.
,
.
.

Windows Azure,
. Windows
Azure, .
, Contoso , .
. ,

. ,
Windows Azure.
, :
1. ,
.
.
2. .
3. .

,
.
3 ,
.


V1
.
, .
Windows Azure.
2.

163




,
,
CQRS ES.

.
CQRS
ES.

. 7

.




.

. 7

164

V1

V1

/
:
:

EventProcess
(

)
EventProcess
(

RegistrationProcessrouter
( )
)
OrderViewModelGenerator

(
RegistrationProcessrouter
)

( )
)

OrderViewModelGenerator
ConferenceViewModelGenerator
(

(
)
)
SeatsAssignmentsHandler
(

ConferenceViewModelGenerator

)
)

V2

: RegistrationProcess router
(
)
: OrderViewModelGenerator
RegistrationProcess router
:
(

)
)
: ConferenceViewModelGenerator
( OrderViewModelGenerator

:
)
(

)
:
: ConferenceViewModelGenerator
SeatsAssignmentsHandler
(

)
)
: SeatsAssignmentsHandler
(
)

2.

EventProcess

V2
(
)
EventProcess
EventProcess
(
(
)
)
EventProcess
EventProcess
(

(
)
)
EventProcess
EventProcess
(
(
)
)

SeatsAssignmentsHandler (
)

EventProcess
(
)

RegistrationProcess router
(
)

OrderViewModelGenerator
RegistrationProcess
(
router
()

)
ConferenceViewModelGenerator
OrderViewModelGenerator
(

)
SeatsAssignments
Handler
ConferenceViewModelGenerator
(

)
)
SeatsAssignments Handler
(
)

V1 :
1. EventProcessor ( ) OrderPlaced ( )
.
2. EventProcessor RegistrationProcessManager
( ) OrderViewModelGenerator (
). Handle ().
3. Handle OrderViewModelGenerator .
4. Handle RegistrationProcessManagerRouter .

5. EventProcessor .
.
6. EventProcessor OrderPlaced .
7. EventProcessor Handle,
RegistrationProcessManagerRouter , OrderViewModelGenerator
.
8. , RegistrationProcessManagerRouter ,
OrderViewModelGenerator .
V2 : ,
EventProcessor , .
EventProcessor ,
. .


V1 ,
.
,
.
V1 ConferenceViewModelGenerator
, SeatsAvailability
.
,
. ,
, .
, .
:
,
,
. -
,
.
-, . .
.
,
.

ES.
.

165

166




,

.



,

.

, ,

ES.

,

.


.
, ,

ES.

,

.


.

.
,
,
.

. .
,
, .
,
. . ,

. ,
. 5
.
,
.

. ,
, .
:
,
.

,
.

,
.

.
: .
.
,
( ).

.
.


.

.

.

167


V1
, .

;
.
,
.
.
Windows Azure ,
, .


. ,

, . ,
,
.
.


Windows Azure.
.
. ,
.


,
.
.
. ,
. GitHub:
https://github.com/mspnp/cqrs-journey-code. V2
Tags GitHub.
.
, .
CQRS. ,
,
.



,




.


,




.

168


,
, :
RegistrationProcessManager
, .

,
.

, V2
, .

RegistrationProcessManager

,
ConfirmOrderPayment
( )

ConfirmOrder (
).
, Order
.

. ,

OrderConfirmed (
)
OrderPaymentConfirmed
( ).
,
ConfirmOrderPayment
( )

ConfirmOrder (
).
, Order
.

. ,

OrderConfirmed (
)
OrderPaymentConfirmed
( ).

RegistrationProcessManager
ConfirmOrderPayment ( )
,
.
ConfirmOrder ( )

Order.

RegistrationProcessManager ConfirmOrder Order


.
ConfirmOrder, Order
OrderConfirmed ( ). ,
:
OrderViewModelGenerator,
;

SeatAssignments ( ),
SeatAssignments;

RegistrationProcessManager,
.



MVC RegistrationController ( ),
SpecifyRegistrantAndPaymentDetails (
).

InitiateRegistrationWithThirdPartyProcessorPayment
(
).
, IsFreeOfCharge () Order
,
CompleteRegistrationWithoutPayment ( ).

CompleteRegistrationWithThirdPartyProcessorPayment.

CompleteRegistrationWithThirdPartyProcessorPayment
ThirdPartyProcessorPayment ( ), CompleteRegistrationWithoutPayment
ThankYou ( ).

169

170




PricedOrders ( )
Windows Azure SQL.
OrderPaymentConfirmed.
OrderConfirmed,
IsFreeOfCharge.
.

ConfirmOrderPayment , Order
. ,

.

,
RegistrationProcessManager

SQL.


. ,
.
StateValue

().

)
PaymentConfirmationReceived

ProcessState
(
)

.
RegistrationProcessManager,

.

,

.



.



V2


ConfirmOrderPayment

V1.


V2


ConfirmOrderPayment

V1.

V1 , ES
Order, OrderPaymentConfirmed. ,
.
V2 OrderPaymentConfirmed
OrderConfirmed.
V2

. , ,

.

SeatAssignmentsHandler ( ):

OrderViewModelGenerator.
Order ,
, .

protected () Order:



:

.
,
.
Contoso

,


.


:

.
,

171

172


, , :
.

, V2 .


, , .
SeatCreated (
) SeatUpdated ( ) , -
.

SeatsAvailability ( )
SeatsReserved ( ), SeatsReservationCancelled ( )
AvailableSeatsChanged ( ) .
. ConferenceViewModelGenerator SeatCreated SeatUpdated.

ConferenceViewModelGenerator
,
.
SeatAssignmentsHandler:

173

174

UpdateAvailableQuantity (
) ,
.


, ,
.



, ,

.
.
, .
, MVC- RegistrationController AvailableQuantity SeatType.


, , ,
. ,
, .

SeatsAvailability, .


Windows Azure.
Windows Azure Service Bus ConferenceProcessor
, ServiceBusConfig (
):

. DuplicateDetectionHistoryTimeWindow (
) Settings.xml ,
Topic (). .
, .
MarkSeatsAsReserved ( ):

175

176

BuildMessage ( ) CommandBus ( )
.
Windows Azure :


,
Windows Azure.
Windows Azure OnStart ()
ConferenceProcessor. Settings.xml , .
ServiceBusConfig .

SessionSubscriptionReceiver ( )
:

177

178

,
.
,
BuildMessage EventBus.



ReceiveMessages (
),
,

SubscriptionReceiver
( ).


ReceiveMessages (
),
,


, .
,
. ,
.
.
, ,
EventStoreBusPublisher ( )
,
.
TopicSender ( ):

V2 Windows Azure.
SubscriptionReceiver , .
.
, .
V2 Windows Azure.
SubscriptionReceiver , .
.
, .

179

180


Windows Azure . Windows Azure Queues Windows Azure Service
Bus Queues Compared and Contrasted ( Windows Azure
Windows Azure ).

. Windows Azure Service Bus Splitter and
Aggregator ( Windows
Azure).



Transient
Fault Handling (
)


.


Transient
Fault Handling (
)


.


.


. ,

,
.


.
,
.
.
, , .
EventBus,
CommandBus.







.





.

conference/commands
(/)
conference/events (/) Windows
Azure. Windows
Azure. ,
AzureMessageLogWriter ( Azure)
:

Kind ( ) . MessageId
CorrelationId .
.
:

,
,
.


.

,
.

.

.

,
.

.

181

182

,
Contoso

,

(,


).
,
Contoso

,

(,


).

V1 V2, Contoso


.
,
ConferenceCreated (
), ConferenceUpdated ( ),
ConferencePublished
(

),
ConferenceUnpublished ( ),
SeatCreated ( ) SeatUpdated (
),
.

SeatCreated SeatUpdated,
.
V1 ,
V2 .
,
,
. , V2
ConferenceCreated.

.
GeneratePastEventLog (
) MessagesForConferenceManagement (
) Migrator ( )
MigrationToV2 ( V2).
RegenerateViewModels (
) Migrator .
, Query
(),
ConferenceViewModelGenerator
(

) PricedOrderViewModelUpdater (
).

, ,
Contoso
.
, ,
Contoso
.


,

.

,

.

183

184





,

.



MaintenanceMode
( )
V2.




,

.



MaintenanceMode


(
)

V2.
,

V1
V2
.


V2 V3
.

,
V1
V2
.


V2 V3
.

,
NullCommandBus
ConferenceViewModelGenerator;
.

PricedOrderViewModelGenerator ConferenceDao,
SeatCreated
SeatUpdated .
.
PricedOrderViewModelUpdater
SeatCreated SeatUpdated,
.

V1 V2
V1 V2
.

. :
1. V1 Windows Azure.
V2 MaintenanceMode,
.
, ,
.
2. V2 ( )
Windows Azure.
3. V1 (
) .
.
4. (. ).
5.
MaintenanceMode .
6. V2 Windows Azure.
V1
V2. ,
.
V2
,
.
.

,
,
, .
,
,
, .

185

.
,
Windows Azure. ,
Windows Azure
. Windows Azure
. MSDN Using Remote Desktop with Windows Azure Rotes
( Windows Azure).



,
V1 , .
V1 ,
,
. ,
, .
.
" " .

-
V2
, .
.

, V2.
.
MigrateEventSourcedAndGeneratePastEventLogs (
) Migrator
MigrationToV2.


V2
. MigrationToV2

.
.
" " .


.
, .






Windows Azure.
,



(
). ,

,
.



.





Windows Azure.
,



(
). ,

,

.
.

.
.

186

SPECFLOW
SpecFlow

-
MVC.
(. 4 "
").
,
. ,
.

-.
.
,
:
.
SpecFlow.
,
.

SelfRegistrationEndToEnd-WithDomain.feature

Features\Domain\Registration Conference.
Visual Studio. , When () Then
() .

, ,
When , Then
.
, .
,
.
, ,
When , Then
.
, .
,
.

187

188

feature.
.

189


,
:
.
. , ,

. ,

- .
.
,
, V1 .
.
.
, V1
.
V2
.


V2. ,
. ,
.
, . ,

.
.
V3.




http://msdn.microsoft.com/en-us/library/jj619274.




,
.



,
.

157

7.



: .


,
. RegistrationProcessManager
. ,
.


.
4 CQRS ES.
. , ,
. , MakeSeatReservation.
,
, .
.
. ,
.
. , , OrderConfirmed, .
. .
, .
.
; ,
.
.

158

. ES.
, ,
, .
, .
. , ,
. , x 10
, x .
, ( -
, ).
. ,
.
,
. ,
, .

Windows Azure.
-, - ASP.NET MVC, ,
. Windows
Azure SQL , . ,
Windows Azure BLOB-
. Windows Azure
. 1.

159

SQL

SQL

- Windows Azure
Conference.Web.Public
(-
)
- Windows Azure

Conference.Web.Public
(-
)

MVC

MVC

- Windows Azure Conference.Web.Admin

(-
)

- Windows Azure Conference.Web.Admin

(- )

MVC

1.


V3

Windows Azure


WorkerRoleCommandProcessor

(
)

Windows

Windows Azure

WorkerRoleCommandProcessor
(
)

Azure

Windows

Azure


Windows Azure

Windows Azure

MVC

Windows Azure. - MVC ,
.
SQL Server Express SQL,
, SQL Server Express.
. 1 .


RegistrationProcessManager.
,
.
.

160




,
. :

(

)

.



,
. :

(

)

.

, ,
,
.
.

RegistrationProcessManager.

,
,
. ,
.
.
-
.
.

RegistrationProcessManager. :
,
.
,

.


.
,
,
.
.

.
,
.


.
.

, .

.

161

:
RegistrationProcessManager ,
. RegistrationProcessManager ,
Windows Azure.

RegistrationProcessManager , ,
.


,
. ,
.
.
, , .
.
, .
, .
, . .
V1 ;
. OrderPlaced
SeatsReserved. V3 .


, RegistrationProcessManager .
. ,
Windows Azure SQL
.
, V3, ,
RegistrationProcessManager, RegistrationProcessManager.
, . ,
RegistrationProcessManager ,
.

162



.

,



. ,



.



.

,



. ,


. CQRS



.

,
,

, .
CQRS



.

,
,

, .


Visual Studio 2010,
. Visual Studio Load Test,

.
.
Windows Azure,

Windows Azure.
Contoso ,

.
,
.




.
1. .

.
.
2. . :
, ,
.
.
3. .
.
4. .
. ,
,
.

. 5
V1.
V2
, :
RegisterToConference (
)
OrderPlaced ( )
MakeSeatReservation ( )
SeatsReserved ( )
MarkSeatsAsReserved ( )
OrderReservationCompleted ( )
OrderTotalsCalculated ( )

163

, RegisterToConference
MVC
.
Visual Studio Load Test
,
.
,
. , V2
-
:

.

-
.

-
(
. .)
.

,
,
.


,
.
.
,
.


, ,

RegisterToConference .
,
. (
)
. , CQRS
.
,
.

. ,
.
,
. (
)
. , CQRS
.
,
.

. ,
.

164

,
, .
, , .
,
.
.

1

.

,
.
-
,


.
Contoso

,
. ,
,
,
,

.

.

.

,
.
-
,


.



Contoso
,


.
,

.
,

,
,
-

,

.
.


.


.
,
, -

, ,

. ,
,
.
, ,
,
. V2
,
, ,
.
.
RegisterToConference
, ,
,
.

165

2
V2 MVC ,
OrderTotalsCalculated
. ,
, .

, .
Order ,
,
.


,
. .

, ,
.

. .


,
.

. ,
Transient Fault Handling ,
.



.


Transient Fault
Handling
,

C# 4.5.


.


Transient Fault
Handling
,

C# 4.5.



Windows Azure
Best
Practices for Performance
Improvements Using Service Bus
Brokered Messaging
(




).



Windows Azure
Best
Practices for Performance
Improvements Using Service Bus

166

7

;
.

,
,
, ,
.

.
, Why do lots of
developers use one-way
command messaging (async
handling) when its not needed?,
DDD/CQRS Group

;
.

,
,
, ,
.

.

of

,
Why do lots

developers
use
one-way


command
messaging
(async

handling)
when
its not
needed?,

DDD/CQRS
Group ,


CQRS,

.



.



.
,


CQRS,

.



.


V2
Windows
Azure.
.

Windows Azure .
( ) ?

,
?

,
- .
,
( ,
) -
.
.

ES

SeatsAvailability.
.

, .

.
,
.
Contoso ,
SeatsAvailability.
Memento SeatAvailability.
SeatAvailability Memento,
Memento .
,
.

ES

.
ES

.

167



. ,
:
1. Parallel.ForEach,

, .
API
Windows Azure.

2.
API.
.
3. ,
,
.
API Windows Azure.



Windows Azure, ,
.

SeatsAvailability
SeatsAvailability
.
, SeatsAvailability
.
.


,
- .
,
: ,
, ,
.



SubscriptionReceiver
( )
SessionSubscription-Receiver
( )

.


SubscriptionReceiver
( )
SessionSubscription-Receiver
( )

.




Windows
Azure.



Windows
Azure.

,
. .
.
,
. .
.

168


,
,
,
.
Windows Azure,
.
:
.


.



,

.


.

.



,

.


.

. 11
Asynchronous Communication and Message Buses (
) Scalability Rules: 50 Principles for Scaling Web
Sites ( : 50 ) Martin L. Abbott Michael T. Fisher (Addison-Wesley, 2011).
,
Order SeatAvailability,
, .


,
.

.

. ,
,
. -,
, ,
,
Windows Azure.


.
. , ,
.
, .

.

.
. , ,
.
, .

.

169


.
,
,
. -
V3.

, Windows Azure.
- ,
.
. ,
, async await Visual
Studio 2012 RC ( .NET 4.0 Visual
Studio 2010).



. ,
Windows Azure ,
,
, ,
.

, -
.
. CQRS
.

, .


SeatsAvailability. ,
, , ,
.
,
,
. ,
. ,
.
,
, .


,



.


.


SeatsAvailability.
,
Order,

,





.

,
.

,

,
.

,



.


.


SeatsAvailability.
,
Order,

,

170




(, ,
Autoscaling
(
)),


.

,


,


.



(, ,
Autoscaling
(
)),


.

,


.
,

,
.



, .
, .

,
. , ,
.

,
SQL, GUID.

GUID, .
GUID . The Cost of GUIDs as Primary Keys.


,
.
, .


,
.
,
Transient Fault Handling.
,
EventStoreBusPublisher.
,
, ,
,
.



.
-. ,
SeatsAvailability
, Order (
Order OrderPlaced OrderTotalsCalculated).
;
, ,
,
. ,

.

171


Contoso
- ,
.
, ,
, .
,
. -
V3.
.
. ,

SQL.

SQL. ,
,
. ,

SQL .
SQL
.

.

.

. :
,
. . 11
Asynchronous Communication and Message Buses (
) Scalability Rules: 50 Principles for Scaling Web Sites
( : 50 -)
Martin L. Abbott Michael T. Fisher (Addison-Wesley, 2011).

.
,
. ,

, ,
.





SaaS.
,
, Twilio, Scaling
High-Availability
Infrastructure in the Cloud




SaaS.
,
, Twilio, Scaling
High-Availability
Infrastructure in the Cloud


,

Windows Azure.

.


SQL

,
SQL,

Windows Azure,
BLOB-.

,

Windows Azure.

.


SQL

,
SQL,

172





EventStoreBusPubliser (

),
SubscriptionReceiver
SessionSubscription-Receiver
DynamicThrottling
(
)


.





EventStoreBusPubliser (

),
SubscriptionReceiver

(
SessionSubscription-Receiver
Windows

DynamicThrottling
Azure,
SQL
(
Windows Azure)
)


.
.

, ,
SQL Azure
Throttling (
SQL Azure).



.


. Transient Fault
Handling .

Windows Azure, SQL
Windows Azure.

.

.
, .

SQL,
Windows Azure.

.:
Windows Azure Storage Abstractions and their Scalability Targets
( Windows Azure ).

Best Practices for Performance Improvements Using Service Bus Brokered


Messaging (

).


.
.
.
,
.



.

V2
V3 Windows Azure .
,
Windows Azure .
-
, V2
V3. , ,

V2 V3. ,
,
.
. 1 .

Business SQL

Azure

( Web. ,
Windows

Windows

.
Azure,

SQL

,
.
Windows Azure)

Business SQL

Windows Azure
Web. ,

173


V2 V3
DraftOrder ( ) PricedOrder ( ).

V3. .

. ,
, - V2
V2 ,
- V3. -
V3 V3
.

, Windows Azure
. .
MigrationToV3 Conference. :
,
V3.
,
V3.


V3 .

V2
V3;
V2 .


V3.
V2, , ,
V3 .
, ,
V2 ,
- V2 . V3
- V3. -
V3 .




.



.

174

.


.
,


,

.
,

.
.

,
.

V2

V3.
.


V3
.
,
. , V3
, .
,
, ,
.
.
,
V3.

V2 .
,
V3 ,
.


,
.
.
.
, .
GitHub: https://github.com/mspnp/cqrs-journeycode. V3 Tags GitHub.
.
,
.
CQRS. ,
,
.

REGISTRATIONPROCESSMANAGER



.
Registration-ProcessManager.


,
SeatsReserved OrderPlaced.


.
,

V2
V3.
,
V3 V2 V3.
:
,
V3
.
,
V3 V2 V3.
:
,
V3

175

SeatsReserved
RegistrationProcessManager MakeSeatReservation SeatAvailability,
SeatAvailability


SeatsReserved,
RegistrationProcessManager . RegistrationProcessManager
MakeSeatReservation , . SeatsReserved
. ,
. RegistrationProcessManager
Seats-Reserved , .
MakeSeatReservation, RegistrationProcessManager
Id SeatReservationCommandId, :

176

SeatsReserved CorrelationId
SeatReservationCommandId, :


:
EventProcessor

dynamic

.
V3

EventDispatcher (
),


.

:
EventProcessor

, Handle Envelope
SeatsReserved. V3
Envelope, CorrelationId.
DoDispatchMessage

EventDispatcher

CorrelationId.

, SeatsReserved. - ,
, SeatsReserved
. Handle ,
,
.
, else if,
:

177


.
,
SeatReservationCommandId,

.
,

.

.
,
SeatReservationCommandId,

.
,

.

178

OrderPlaced
OrderPlaced RegistrationProcessManagerRouter ,
. V3 .


Registration-Process-Manager

Windows Azure ,
RegistrationProcessManager .
, .

. ,
.

V3



.

V3



.

179

SqlProcessDataContext ,
:

180

SqlProcessDataContext ,
:

181

DispatchMessages ( ) Find ()
SqlProcessDataContext ( SQL).

RegistrationProcessManager.


,
. StartRegistration
RegistrationController
RegisterToConference. :

182

, ,
.
SpecifyRegistrantAndPaymentDetails RegistrationController.
V2 .
, WaitUntilSeatsAreConfirmed (
):

183

184

V3.
.

.
.

185

, ,
. SpecifyRegistrantAndPaymentDetails WaitUntilOrderIsPriced ( ),
,
, .
Order. Order
CalculateTotal ( ) OrderTotalsCalculated (
), :

V2 Order MarkAsReserved,
CalculateTotal.

186

-
Windows Azure.


SubscriptionReceiver SessionSubscriptionReceiver
, ReceiveMessages,
.
.
ReceiveMessages

SubscriptionReceiver,

ReceiveMessagesAndCloseSession SessionSubscriptionReceiver.


Transient Fault Handling



.


,
.
.


async,
C# 4.

SeatsAvailability

Transient
Fault Handling

Registration-ProcessManager
.

.
SeatsAvailability.
.



SeatsAvailability async,

C# 4.
,


Registration-ProcessManager



SeatsAvailability.


Windows Azure .

ReceiveMessages

SubscriptionReceiver SessionSubscriptionReceiver.
API.



.
. TopicSender.


V2
Windows Azure. ,
. V3 MVC
.

. ,
ConferenceProcessor Order
, .

187

, SynchronousCommandBusDecorator
( ) CommandDispatcher ( ).
-, OnCreateContainer
Global.asax.Azure.cs:

. Conference.Azure.cs
.

SynchronousCommandBusDecorator:

188

:
, .
, CommandDispatcher :

189

MEMENTO
Contoso
,
.
SeatAvailability.
Save AzureEventSourcedRepository ( Azure) ,
memento,
IMementoOriginator.

memento,


memento.

Find

AzureEventSourcedRepository
memento, :


memento,


memento.

190

, ,
. ,
, memento.
, memento.
, SeatsAvailability
memento :

191


5 V1 ,
.
. ,
.
. Start EventStoreBusPublisher ,
:

SubscriptionReceiver SessionSubscriptionReceiver DynamicThrottling


, .

192


Windows Azure.
, .
Settings.Template.xml, :

193

SESSIONSUBSCRIPTIONRECEIVER SEATSAVAILABILITY
V2 ,
. . ,
SeatsAvailability . ,
, .
Conference.Processor.Azure.cs ,
SessionSubscriptionReceiver , SeatsAvailability:

SeatsAvailabilityCommand,
, , :

194

,
SeatsAvailability.


V3,
,
.
.
GetPublishedSeatTypes
CachingConferenceDao ,
:
RegistrationProcessManager, OrderPlaced,
. ,
.
RegistrationProcessManager, OrderPlaced,
. ,
.

195


PricedOrder-ViewModelGenerator.


,
, ,
,
Order SeatAvailability.
. Settings.xml
:

,
:
,
.


,
:
,
.

196


,
:
GUID.

MVC- ASP.NET.

Windows
Azure.

GUID
GUID
Guid.NewGuid. GUID . GUID
SQL .
. V3 ,
GUID.
SQL. .
GuidUtil:

197

. The Cost of GUIDs as Primary Keys Good Page Splits and Sequential
GUID Key Generation.

198

MVC- ASP.NET
MVC - ,
. ASP.NET
Task () ASP.NET MVC 4.
,
.

Windows Azure
, Windows
Azure.
Windows Azure.
SubscriptionReceiver .

199


V2 SessionSubscriptionReceiver
Windows
Azure.
,
. V3
SessionSubscriptionReceiver .
.
.
AcceptSession ( ) SessionSubscriptionReceiver.


,
RegistrationProcessManager.
RegistrationProcessManager ,
:

AcceptSession

Transient Fault
.
AcceptSession

Transient Fault
.

. Code First Data Annotations -


MSDN.

C# Session-SubscriptionReceiver,
.

MakeSeatReservation

Windows Azure
TimeToLive ( ),
.

MakeSeatReservation, .


PricedOrderViewModelGenerator
.
SQL ,
.

200


Conference.Specflow
Visual Studio Conference.AcceptanceTests
.

Features\Integration

Conference.Specflow,
.
.
, ,
.

. ,
,
.
Conference
, Registration
.


UserInterface.
4
" ". Controllers ,
MVC, Views WatiN
.


,



.

.

,



.

.

CQRS
V3.
.
, ,
.



http://msdn.microsoft.com/enus/library/jj619274.

8.

:
? ?
? ?

, .
, ,
, ,
Contoso.
;
CQRS. ,
CQRS ,
Windows Azure
.
,
. ,

. ,
.
, ,
CQRS ES.

?
, .
- .


,
, .
,
CQRS:

CQRS,


.


.
(Kelly
Sommers),
CQRS
CQRS,


.


.
(Kelly

201

202



.

,


.


.

,


.







.






.


.
.
,
. ,

,
CQRS.
.
. ,
CQRS,
,
. CQRS
. ,
,
. ,
.
, ,
,
CQRS.
7

.
, .


. ,

.
, ,
. , ,
.
, -
.

,
. 4

, .
, (MIL),
.

203

, , ,
CQRS.

.

,
.
,
. :
.
ACID-
(, , )
. ,
. 5
V1,
7
.

,
.
7
.


,
, .

.
,
. ,
,

.


.
,
.
.
Visual Studio. .
,
.


,


,

.
. 7


.

:
Windows Azure Storage
Abstractions and their Scalability
Targets (
Windows Azure
)
Best Practices for Performance
Improvements Using Service Bus
Brokered Messaging
(




).


,


,

.
. 7


.

:
:


Windows
Azure Storage
,
,

Abstractions
and their
Scalability
, .

Targets (
, ICommandBus CommandBus

Windows

SynchronousCommandBusDecorator. 7
Azure

)

Best Practices for Performance
SynchronousCommandBusDecorator.
Improvements Using Service Bus
Brokered
Messaging
:


(
,
,

204

CQRS

CQRS
;
.
CQRS
;
.

, CQRS
; .
.
.
, CQRS,
.

.
ACID,
.
, . 5
V1 7

.
CQRS .
, .
,

, .
,

.
,
CQRS . 5
V1

.
,


. ,
.
.
,
.

CQRS
. ,
,
CQRS.
,
-. ,
, 7
.
.

.
CQRS. ,
.
2
,
Contoso.
CQRS ,
CRUD (Create, Read, Update, Delete , , , ).
CQRS
. , CQRS
.
, CQRS .
CQRS
, .


,
.

. :
,
. ,
, . 4 CQRS ES.

205

(,
,
)

.


,

.
(,

)
,

CQRS

CQRS
,


,

.
,
,
,
,


CQRS
.
CQRS
,


,

.

206



.



,


.


.



,


.
,


,

.

.

,
.



,
.
.

CQRS
.

, .

, .

-
,

,

.


. 4

.

,
, ,
. ,


.

CQRS
, ,
CQRS
.
,
CQRS .

-,
?


, ?
,
- ?

- ?

,
?

-?

CQRS
?

207

-, ?
.
, CQRS ES,

.



.
.
. ,

.
,
.
CQRS- . ,
,
EventStore .
, ,
: .


,
. ,

Windows Azure .
.
, ,
:
, ,
.
,
.
,

.

,
,

,




,
.
,
,

,




,
.

208


.
.
. ,
, .
RegistrationProcessManager .
3 .
.


.
, - ( 4
) .
( 7 )
.
,
-, .


CQRS: , , ,
. ,
.
.

CQRS


, (,
), CQRS.
, ,
, .


. , :
.

.
. 7
.

,
.
. ,
, . ;
, -
( ).
.

,
.

-.

. ,
,
.
.
7 .

, (,
).

.


(. 5 V1) ,

,
.
, ,

.
( ,
) ,
.



,

. ,



,

,
StreamInsight SQL
- .


,

. ,



,

209

210

,
V3 .
, ,
.
: (.
), Contoso
.



http://msdn.microsoft.com/en-us/library/jj619274.

1.

CQRS


CQRS. , , CQRS,
. , CQRS
. CQRS
, .
,
, ,
. -
(Domain-Driven Design, DDD).
:
DDD , CQRS .
, CQRS.

, ,
.

DDD CQRS.
DDD CQRS . ,
DDD CQRS.

DDD .
DDD CQRS
. DDD.

DDD
Domain-Driven Design: Tackling Complexity in the Heart of Software, Eric Evans (Addison-Wesley
Professional, 2003). Applying Domain-Driven Design and Patterns, Jimmy
Nilsson (Addison-Wesley Professional, 2006). DDD
.NET.
.
, QCon London 2009.
DDD, , .
Domain-Driven Design Quickly,
Abel Avram, Floyd Marinescu (C4Media, 2007).

211

212



DDD

.
,
What Ive learned about
DDD since the book (
DDD
)




!
,

!
,
What Ive learned about
DDD since the book


DDD

.
,
What Ive learned about
DDD since the book (
DDD
)




!
,

!
,
What Ive learned about
DDD since the book

, DDD
,
- .
DDD
,
. .
DDD
. DDD
.
:
DDD
- . DDD

-.


, .

.

DDD
.
,
.

DDD
, .
,
.

DDD.

DDD,
CQRS.
,
.

CQRS

213


DDD.
, .
- ,
.
:
.

DDD
-.
, .
,
.
DDD ,
. ,
, , - .
.



.
.

(, , , , ,
) .
,
. , :
. ,
,
.


SpecFlow,

.




.

. 4



CQRS
ES.

SpecFlow,

.


214

, -



.
,

-
DTO: Power Use
of Value Objects in DDD.


.
,

-
DTO: Power Use
of Value Objects in DDD.

DDD
( , ),
.
. ,
. ,
;
(, , ),

. , ,
;
, .
-.
. , , . ,

(
, , ,
). : ,
, . -, , .
.
. ,
.
,
. :
,
( -).
. ,
,
, .
DDD -;
.

CQRS


, - DDD
. .
, ,
, .
,
.
. ,
.
. ,
,
:
, - .
, , ,
?

, -
. , ,
. , ,
, ?

DDD -,
. ,
.
( ) - .
;
; .
, , DDD
- .


DDD ,
. ;
.
DDD .
.
.
. (
DDD) , , ,
.

215

216

- -

- -

- -

1.


- -
- -

-


,
,

.

,




. -


.
,
CQRS


,
,

-
- -

-
-

1 ,

. ,
, .

.
, .

CQRS

:
:
,
.

,
.

.
, .


. :


,
.
(Eric Evans), Domain-Driven Design: Tackling Complexity in the
Heart of Software, . 383.

, (,
CQRS ) , .



. ,
, , ,
.

.

217




(
).

,
.
,

Patterns & Practices



(
).

,
.
,

Patterns & Practices

BC


(bounded context).
-

(business
components).
.
BC
.

BC


(bounded context).
-

(business
components).
.
BC
.

218


,


.


.
,
What Ive learned about DDD
since the book





,
.

(Alberto Brandolini), Context
Mapping in action
,


.


.
,
What Ive learned about DDD
since the book





,
.

(Alberto Brandolini), Context
Mapping in action


, .

. ,
.

, .
.
,
, ,
.
-, ,
.
,
.


, .



,
.
DDD,
. ,
.
:
.

. ,

,
. ,

. ,
,
.
. ,
, , .


. ,
DDD,
CRUD,
CQRS. 2
,
.
. ,
,
.

CQRS



B C
D

DDD

DDD

CRUD
(,

DDD
(

CQRS
(

2.
CRUD
DDD



CQRS
(,
(

)
.

) ,
. , ,
, .


,
,
.
;
.

219

220




. ,
.
.

.

,
,


,
. DDD

,
.
.

,
.

DDD . Part IV: Strategic
Design ( 4. )
Domain-Driven Design: Tackling Complexity in the Heart of Software
(- :
).

CQRS DDD



, ,
,

.

(Jos Miguel Torres),





, ,
,

,
CQRS
DDD.
, CQRS,
,
DDD. DDD ,
CQRS
.

CQRS.
, DDD
CQRS.

CQRS


CQRS, DDD
.
, DDD
CQRS, .




http://msdn.microsoft.com/en-us/library/jj619274.


.
DDD

CQRS.
CQRS

DDD.
DDD


.
,

CQRS

. ,

,

,
CQRS


.

.

,
DDD

.

(Alberto Poblacin),



.
DDD

CQRS.
CQRS

DDD.
DDD


.
,

CQRS

. ,

,

221

2.

CQRS:


(Command Query Responsibility Segregation, CQRS),
. ,
. , CQRS

. CQRS
. CQRS,
. 2
CQRS ES
, Contoso
Contoso ,
CQRS.
CQRS ES
CQRS
.

CQRS?
Object Oriented Software Construction ( )
: ,
. ;
, .
, ,
, .
CQRS
.


CQRS
.
,

(

: "
,

"; "
,

").
, CQRS,
Task Based UIs, Event Sourcing
agh!


CQRS
.
,

(

: "
,

223

224

CQRS
,


,

,


(
)
.
,






.

,

.
,


.

REST,

:
GET

PUT, POST
DELETE.

(Clemens Vasters),
CQRS

CQRS
,


,

,


(
)
.
,



.
,
, ,
-
.

CQRS:
: CQRS
, ,

.
: . CQRS
. CQRS ;
SOA
EDA [-
].
: . ,
CQRS,

( ,

). : CQRS,

, ,
.
,
.
NoSQL
,
.
CQRS,
CQRS.

CQRS:

: CQRS ?
, ? :
CQRS, ,
. CQRS .
. , .
. ,
CQRS .
. , CQRS .
, , .


1 CQRS .
CQRS .

1.
CQRS

225

226

1 .
,
.
:
-
. .
. ,
.

, -, ,
. .
,
.
.

.
, (Third Normal Form, 3NF)
, ,
.
. 1 . CQRS
- ,
, NoSQL (, ,
, NoSQL, , BLOB ). CQRS ,
.

1 , .
.
,
.
; ,
.
, 1, .
, .
,
. ,
?

, ?

, ?


CQRS. .

CQRS:

CQRS -
CQRS
- (DDD),
CQRS.
. .
Domain-Driven Design: Tackling Complexity in the Heart
of Software (Addison-Wesley Professional, 2003)
, . (
;
, .)
.

, .


,
.

1 ,
-. .
.
DDD
( ).
.
.
. ,
(SOA)
DDD.

CQRS
,

-
.
, Twitter,
2012 .



.
,

.


,



.
, Domain-Driven
Design: Tackling Complexity in
the Heart of Software
(
:

),
. 23.

CQRS , ,
CQRS .

,
.


,



,

.
,

.
, Domain-Driven
Design: Tackling Complexity in
the Heart of Software,
. 335.
CQRS
,

-
.
, Twitter,

227

228

2


,
,

.

,




. -


.

CQRS,

.
,
CQRS


,
,

.

,




. -


.

CQRS,

.
,
CQRS


,
CQRS. DDD
.
CQRS
. ,
. -
CQRS -,
.
,
-.
.
,
CQRS.
, , CQRS
.
,
, CQRS ,
.

,
DDD ,
, ,
. DDD -.
,
.
.

,

.
. DDD ,
,

. CQRS
DDD, DDD
CQRS.
,
. :
X Y Z.
, .

CQRS:

; , .
: 200
X. , .
, .
DDD -.
-.
CQRS .
.
( ) .
,
, . 2
CQRS.

()

()

2.
CQRS

()
(
)

()

(
)

229

230

.
.
.

.

CQRS
,
DDD
( )
-. ,
,
.
CQRS
,
CQRS .
-,
CQRS,
, ,
.



CQRS
.


,




,
.



,
Amazon,
Google Facebook.


MySQL, SQL Server
Express
.
, When
to avoid CQRS (
CQRS).



CQRS
.


.
,
. ,
Windows Azure
, ,
.

CQRS:



, , .
-
.
. -
,
, ,
, ,
. -

.
.
, CQRS
,
,
.
, .

CQRS
.
(,
) ,
-.
-, ,
.
-
.
- .

DDD.

,
.



.


:

,
,

, ,
.

:

,
. .

.
(Martin
Fowler), Command-Query
Separation



.




.
, DomainDriven Design, . 342.


.


:

,
,

, ,
.

:

231

232


CRUD
. CQRS

.
,
.
.


CQRS, ES
DDD
.


,

.
(Pawe
Wilkosz),

.


.
,


-,

.
(Jos
Miguel Torres),

,


CQRS, ES
DDD
.


,

.

CQRS (
),
. ,
. ,

X ,
CRUD.
.

CQRS
CQRS
,
, ,
.

CQRS?
CQRS
.
,
CQRS .
CQRS
, ,

-
.
-, ,
,
CQRS .
.
, ,
.

CQRS:

CQRS.
CQRS ,

. ,
,
? , ,
,
.
.
CQRS;
.
,
, .

CQRS. CQRS
. , CQRS
, .






.




;

.
, Why
you should be using CQRS
almost everywhere...
( CQRS

)



.
. , ,
.
.
.
,
, .
,
.

. CQRS
. ,
. ,
,
,
. CQRS ,

.
CQRS ES

.




.


, Clarified
CQRS





.

233

234



CQRS.
, ,
,
.
CQRS. , ,
(Platform as a Service, PaaS),
CQRS.
,
.

CQRS?
,
CQRS (
),

.
,
When to avoid CQRS
(
CQRS)

, ,
, ,
. CQRS,
, ,
.
CQRS, ,
.
, -.

,

.



.
, CQRS
and CAP Theorem
( CQRS CAP)
,
CQRS (
),

.
,
When to avoid CQRS
(
CQRS)

,

.



.
, CQRS
and CAP Theorem
( CQRS CAP)

CQRS
( ) . CQRS,

. CQRS
,
, -
.
CQRS .
,

.



http://msdn.microsoft.com/enus/library/jj619274.

3.

ES:

(Event Sourcing, ES) CQRS . ,


. , ES.
, CQRS ES. ; 4
CQRS ES CQRS .
ES ,
:
. , , ,
. , .

. ,
. .
, , ,
.

. (),
. ().

, , . ,
E23 .

-. ,
E23 ,
, E23, "".

, , , ; ,
CQRS . ,
:
,
, ,
( ) .

.
, .

235

236


, . ,
DDD. DDD ,
.

?
. ,
. ,
.
.
:

.
, ,
.


. ,
.

ORM
1 .
:
1.
157 .
SeatsAvailability.
2. - (Object-Relational Mapping, ORM)
. ORM ( )
. .
3. - , .
4. SeatsAvailability .
.
5. ORM . ORM
( ) .
. 6 .

ES:

:

157

:

157

ORM

SeatsAvailability

( )


157

ORM

SeatsAvailability
( )
157

237


623

157

CQRS

157

CQRS

623


1.
-

1 . ORM
. , ,
, , .

:

157

:

157

SeatsAvailability

( )
157


SeatsAvailability
157

5
1


SeatsAvailability
157

1
5

21


SeatsAvailability

( )

157

238

2.

2 , ORM
.
. .
, , ORM .
.

ES:

, 2.
, 1, 3 4 ,
ORM.
1.
157
.
SeatsAvailability.
2. ,
SeatsAvailability 157.
3. - ,
.
4. SeatsAvailability .

.
.
5. , ,
, , .
, ORM
. ,
.

. -
.

.
.
(
,
).
.
,
.

CQRS ES

.
,




;



Windows Azure.
CQRS ES

.
,




;



Windows Azure.

239

240





Events as a Storage
Mechanism (

).

Events
as a Storage
Mechanism
(

).

,

.



.
(Pawe
Wilkosz),


.


,

.
,




.
, Why use
Event Sourcing?




.



. ,
.
,

.
, ,
:
,
.
.


,
,
. (
) .

.
.

.
,
.
.
. ,
.
.

,
.

. , ,
. ,
,
, .

ES:

.
. ,
.

. ,
.
,
. ,
,
.

.
,
, ,
.

. , ,

-. ,
.

.
,
.
,
,
.

. ,
.

,
.
,
.

.
. ,
.

.
.

241




,
,

.
,
,

(. .
).


,


.

(Alberto Poblacin),


,

,

SQL. ,

JSON,

.
,
Why Event Sourcing?



,
,

.
,
,

(. .
).

242

3
,
ORM

,
ES

.

. ,
(
)

.


,

.


.


,
.
,


,
.



-.



.

.

.
(Yves Reynhout),
CQRS
,
ORM

,
ES

.

. ,
(
)

.


,

4 CQRS ES
.
,
CQRS ES.

, ES
,
ES. ES .
:
. ,
.
,

, .

.
.
.
CQRS ES.

. ,
.

.

.
(
)
.
, 250
.
CQRS .
, , ,

.

ES:

CQRS ES
CQRS ES
.
2 CQRS
.
.
. ,
,
.
,
, .
, ,
,
.

ES


.
,

.


.
ES


.

ES .
CQRS


. ES
.
(Clemens
Vasters),
CQRS


,




,
.


,


.
,
CQRS
ES


.
,

.


.
ES

243

244

3.
CQRS ES


, , .
, ,
.
, .
. 4 CQRS ES
.
,
.
,
.

,
. .
, .

ES:

: CQRS
.
.

.


, CQRS.
-.
. .
CQRS.



, . ,
. .
,
EventStore . .
.
8 : ,
.


, CQRS ,
, , ,
. ES .
,
, .
, .
.
. .
.
, ,
.


.
, , ,
.
. NoSQL, .

,
, ,
.
.

245

246

, .
, , . . ,
.
,
.
.
.
, .
, , 100 .
.
.
,
.
,
.
.
( ).

,
. ,

.
.
.
. Your Coffee Shop Doesn't Use Two-Phase Commit (
) .
.
, Windows Azure
:
, .
, ,
, .
, , ,
, .
, , ,

. .
, .
CAP
. CQRS ES.



http://msdn.microsoft.com/en-us/library/jj619274.

4.

CQRS ES

, .
,
(Command Query Responsibility Segregation, CQRS) (Event Sourcing, ES).


CQRS
: .
, :
, .

,
.



(Data Transfer Objects, DTO):
DTO, DTO ,
DTO , .
DTO Implementing Data Transfer Object in .NET with a DataSet (
DTO .NET DataSet).
CRUD: , ,
, . ,
CRUD DTO-.
.
, DTO,
. , , ,
, ,
DTO.
CQRS DTO.
( DTO) .

247

248

- (DDD)

.
DDD,
.

.
DTO
.


CQRS .
,
, . . .
,
,
, .
:
( ),
(
), .
.
, .

( ,
,

, )

,


.
,

( ,
,

, )


CRUD

.

,
Insert.

.
, ,
.


,
, .
,
.
, -
.
, :
.

CQRS ES

, , ,
, .
.
,
.


- .
, CQRS .
.
, .
(, ,
).
.
, .
.
. .

-
- (Object-Relational
Mapping, ORM), Entity Framework.
.
IAggregateRoot ,
Order. , ORM.

249

250


,
, .
IEventSourced, EventSourced ,
Order. ,
.

CQRS ES

251

252

CQRS ES

UpdateSeats OrderUpdated,
. Update

, ,
OnOrderUpdated .
, ,
.
LoadFrom ( )
,
.


CQRS,
C#.



,
.



.


,
.



.

253

254

,
. :
X Y Z.
, .

.
,
.
, -
, .
,
, .


ICommand
. :
, .

,
( )

.



.
,


.

.
(Julian
Dominguez),
CQRS

.

,

.


.
(Mark
Seemann),
CQRS
,
( )

.



.
,


.

.
(Julian
Dominguez),
CQRS

CQRS ES


.
,


,
.



.
,



,


.
(Jeremie
Chassaing),
CQRS

.
,


,
.



.
,



,


.
(Jeremie
Chassaing),
CQRS


,
. :
1.
.
2. .
3. , .

.
4. ,
.
5. .

,
.

.
.
,
Order.

255

256

Order. RegisterToConference
, . ConfirmOrder ,
. Save .
ORM, Find Save
.
, Find
, Save .
. ,
.

CQRS ES


. ,
, ,
. , ,
.
. ,
.
, ,
, ,
(, ). ,
, , .
, .
. ,
,
. ,
, .
, , , .


CQRS .
. , ,
,
.

.
.
, .

: ,
.


, ES . ,
.

257

258

1: , ,
. , ,
.
2: . , ,
. , ; ,
.
1: , ,
. , ,
. ,
? , ,
, .
2: , . -
, . ,
, .
1: ?
.
2: , , ,
-.
1:
, , ?
2: . .
.
ES .
1:
?
2:
. ,
? ,
?. - ;
.
1: . - ,
, ?
2: , ,
. .
, .

CQRS ES


. ,
SOAP REST, .
. SOAP REST,
.
:

1. , SOAP.

2. , REST.

, .
resource ()
.
. , . . .
.
:
.

259

260

:
.

, - .

. : SeatsUpdated, PaymentCompleted EmailSent.


,
.
IEvent.


,

.
,


.

!

,

.
,


.

!

. ,
DTO C#.
.

CQRS ES

,
. VersionedEvent.

Version () . ,
.


, .
:
1. Event () .
2. , .
.
3. ,
.
4. .

261

262

ORM, Find Save



.
,
Find ,
Save .


-
. ,
: ,
, , (Atomicity, Consistency, Isolation,
Durability, ACID). , ,
. ,
,
,
. :
, , .

. CAP ,

:
(Consistency, C). ,
.

(Availability, A). ,
, .

(Partition Tolerance, P).


, ,
.

CAP . CAP
CAP Twelve Years Later: How the "Rules" Have Changed (12 :
) (Eric Brewer) InfoQ.



CAP:

,


.


,

CAP:

,
;

,

.
(Werner
Vogels),
Amazon,
Eventually
Consistent, Communications of
ACM, 52(1): . 40-44,
2009 .
,


;
,


.
(Werner
Vogels),
Amazon,
Eventually
Consistent, Communications of
ACM, 52(1): . 40-44,
2009 .

CQRS ES


.

,
-

.
...
-
,
,

.


.
.

.
,

,
, . .
.
, Quick
Thoughts on Eventual Consistency
(
)


. CAP
,
. ,
.
,
.
-: ,
,
, . -
: -
, , ,
. ,
- ,
,
. ,
, , .
. CAP, .
IEEE Computer ( 45, 2,
2012 ).


.

,
-


.
(Domain Name Servers, DNS).
...

,
-

, ,
,
.
,
, ,

DNS .
.
DNS ,

.

.

.
(Domain Name Servers, DNS).

,
.
, ,
.
,
, ,

DNS .
,
DNS ,
, . .

263

264

CQRS
CQRS? CQRS
, ,
.
. ,
; .
(
), , ,
1.

1.

, .
-, , .
, .

CQRS ES

265

. ,
, .
-, - ,
. CAP, ,
.

, . 2 ,

.

2.

266

.

, .
,
( ), ,

.
, ,
.
.
/,
,
.
( 3)
.


,



.

3.

,

CQRS ES

:
, .
CQRS .
, ,
.


. :
.

, CQRS ,
.
, ,
. ,
.
, .
4 .
,
. Windows Azure
. ,
. ,
.
, , 7
.
,
CQRS .
. ,

.
:
SQL Windows Azure, Windows Azure BLOB- Windows Azure.
.

267

268



. ,
.
,
,
.

:
.
, ,
.
.

.
.

, ,
.
. ,
. ,
. ,
, , , . ,
,
.
,
, .
.


,
. ,
, .
,
.
. ,
, .

, , . ,
.
, .

CQRS ES

.


.
(Rinat
Abdullin),
CQRS


.


.
(Rinat
Abdullin),
CQRS


.
: ,
,
.

: ,
,
.

CQRS
CQRS ES : .
,
,

CQRS,

.

( ) ( ).
.
, ,
.
, ,
Windows Azure.
7 ,
Windows Azure.
Windows Azure
,
, .


.

CQRS.



.
.
,
.




.



.




.



.

.

.
,
.


. (Pat Helland) Idempotence Is Not a
Medical Condition ( ).

269

270



.
,
.
:

, .



, .
. ,

. ,
, .
,
, .
,
.


.
.

.
, .

.
.
.
.
, .



. :
,
.

,
.



,


.


,


.

CQRS ES


, .
,
; . ,
. -
,
.


.
, .



. , ,
;
. .
, :
.

.
. , ,
.

:

, .
, .
,
. ,
.

271

272

:
. ,
. ,
.

. .
,
.
,
, , ,
.
. ,
JSON (JavaScript Object Notation) ; ,
, .

,
3 CQRS:
, DTO .
.
CRUD
DTO . DTO
. DTO .
. ,
CRUD, DTO,
CRUD . :
CRUD.

CRUD
, .


, CRUD.

CQRS ES


.
,



.

,



.

.
,
Tasks, Messages, &
Transactions (,
)



CQRS.
.


.



.
, CQRS,
Task Based UIs, Event
Sourcing agh!



.
,



.

,



.

,
CQRS
:
CRUD .


,
.

,
, .


, ,
.

CRUD

. CQRS

.
.

.
CQRS
.
,
.
.

CQRS.
CRUD.

Windows Azure
2 CQRS ,
CQRS
.
,
.
Windows Azure ,
CQRS.

273

274


Windows Azure Windows Azure.
Windows Azure .
. CQRS
,
.
Windows Azure , (
) .
, .
CQRS
. Windows Azure
. MSDN The Autoscaling Application Block ( Autoscaling Application Block).

WINDOWS AZURE
Windows Azure.
, .
:
.

,
.

Windows Azure , :
.

. ,
.
Windows Azure . Data Storage Offerings in
Windows Azure.

CQRS ES


Windows Azure.

275

276

:
(
)
.


. . The
Transient Fault Handling Application Block (
).

,
Microsoft.WindowsAzure.StorageClient.
Windows Azure SQL
Windows Azure.

Microsoft.WindowsAzure.StorageClient.
Windows Azure SQL
Windows Azure.

, .

CQRS ES


,
Windows Azure.
. ,
.

277

278

:
,
.
.

CQRS ES

:
.


. ,
.


WINDOWS AZURE
Windows Azure
CQRS.
-
.
Windows Azure ,
.
, CQRS ES, Windows
Azure . .
CQRS ES.
3

7 ,
.

279

280

, ( 6 )
.
.

. Windows Azure
. ,
,
.
,
.

...
,
CQRS

...
,
CQRS


http://msdn.microsoft.com/en-us/library/jj619274.

5.

,
.
.
. CQRS :
, , ,
. (, ,
, )
. ,
.


, ,
. ,
, .


.
, .
, ,

.
.
.
. , ,
, .

281

282

.
:
- .

,
, , -.


, CQRS, ,
. ,
, . ,
, , .
, .
.
,
, CQRS.


.
, CQRS, ,
, . ,
API .
.


,
, .
,
.
, .


, .
, .
, .

.


, CQRS, ,
, , .
, ,
. , .
.

283

,
, : .
, , ,
.
, .
.
, CQRS.



http://msdn.microsoft.com/en-us/library/jj619274.

6.


CQRS
,
.
.
:
,
, CQRS.

,
.


Sagas. - (Hector Garcia-Molina)
(Kenneth Salem). , ,

-. , ,
,
.
-
- ,
.
.
,
-
. , -
,
, .
, -,
.




CQRS,

.



,

.



CQRS,

.



,

.

285

286

,
, CQRS. ,
,
-, .
. ,
CQRS.
.
, .
Enterprise Integration Patterns ( )
(Gregor Hohpe) (Bobby Woolf).


. , CQRS
.

CQRS
, CQRS
: .
, .
: X Y Z.
, .
; , - .
: X . ,
. .
, .
, , .
CQRS ES
.

?
, ,
-, ,
. - . , -
, . ,
.
1 ,
. .
. .

2. MakeReservation
()

1 .PlaceOrder
( )

6. OrderConfirmed
( )

2. MakeReservation
()

.PlaceOrder
6.1 OrderConfirmed
(
)
(
)
6. OrderConfirmed
( )

6. OrderConfirmed
( )

3. SeatsReserved
( )

3. SeatsReserved
( )

5. PaymentAccepted
( )
5. PaymentAccepted
( )

4. MakePayment
()
4. MakePayment
()

1.

, 1, ,
. Order MakeReservation
Reservation, . ,
Reservation () SeatsReserved ( ), Order.
Order MakePayment () Payment ().
, Order OrderConfirmed, Reservation ,
, , .

287

8. OrderConfirmed
( )

7. PaymentAccepted
6. MakePayment
( )
()

6. MakePayment
()

8.
OrderConfirmed
1. PlaceOrder
(
)
(
)

8. OrderConfirmed
( )

2. OrderCreated
CreateOrder
3.
( )
( )

2. CreateOrder
( )

1. PlaceOrder
( )

3. OrderCreated
8. OrderConfirmed
)
(
)
(

7. PaymentAccepted
( )

288

4. MakeReservation
()
4. SeatsReserved
MakeReservation
5.
()
(
)
5.
8. SeatsReserved
OrderConfirmed
(
)
( )
8. OrderConfirmed
( )


2.

2 -, 1,
. ,
.
: ( )
. .
-, . Order
, , Payment.
, .
-, ( ),
.
-, 1 2,
. -, ,
. ,
-.
.

289

, (. 3).
,
. , Reservation ,
SeatsNotReserved ( ) ,
. SeatsReserved, ,
. WaitList,
.


2. CreateOrder
( )

3
10
5

OrderConfirmed
3.10.
OrderCreated
()
)
(

1. PlaceOrder
10. OrderConfirmed
( )
( )

4. MakeReservation

()

5. SeatsReserved

3. OrderCreated
2. CreateOrder
( )
( )

10

PlaceOrder
10.1.OrderConfirmed
(
)
(
)
10. OrderConfirmed
( )

7. AddSeatsToWaitList
(
)
7. AddSeatsToWaitList
(
)

10.SeatsNotReserved
OrderConfirmed
6.
( )
(
)
10. OrderConfirmed
( )

8. MakePayment
()
9. MakePayment
PaymentAccepted
8.
()
( )
9. PaymentAccepted

3.

4. MakeReservation
(
)
()
6. SeatsNotReserved
5. SeatsReserved
( )
( )

8( )

,
- -.
. ,
SeatsNotReserved AddToWaitList ( ).

290

?
:
,
.

.
.

?
, :
,
, .

-
. - .

CQRS
, ,
, CQRS. ,
,
-, .



http://msdn.microsoft.com/en-us/library/jj619274.

7.

Windows Azure
Windows Azure.
, CQRS ES.
.
Windows Azure ,
. :
. ,
-,
.

.
, .
,
/.

CQRS
.
Windows Azure .

291

292

Windows Azure
.
1 .

2
M3
3

M8
1

M8

1
M7
2

M6
M6

M7

2
1.
Windows Azure

M5

M4

M5
M4

Windows Azure

M3
3


Windows Azure

1
1

1
1

2
2

.
,
(First In, First Out, FIFO).

,
. .

.
.


Windows Azure
.
2 .

M8
1

M8

M7
2
2

M7

M3

M6

M5

M4

M6

M5

M4

M5

M4

M5

M4

M6

M5

M4

M6

M5

M4

M6
M6

M3

M3
M3

2
1
1
1
2

2
2
1
2

M3
M3

Windows Azure

2
1 3

Windows Azure

2.
Windows Azure

.
.

,
.
.

.
.

, ,
.

293

294

API
API Windows Azure,
.


:
ReceiveAndDelete ( ) PeekLock ( ).
ReceiveAndDelete :
.
, :
.
PeekLock : ;

. , ,
. ,
, . , ,
.
PeekLock . ,
.
, ,
. , ,
.
PeekLock.

.


RequiresDuplicateDetection (
) Duplicate-DetectionHistoryTimeWindow ( )
QueueDescription ( ) TopicDescription ( ).
, .
, , .

, .
.


BrokeredMessage ( )
ExpiresAtUtc ( UTC) TimeToLive (
). .


, .
ScheduleEnqueueTimeUtc ( UTC)
BrokeredMessage.


Command () Event ()
Windows Azure.
Contoso Json.NET ,
. -
.
Common,
Json.NET.


Windows Azure . Service Bus ( )
MSDN.
. Overview of Service
Bus Messaging Patterns ( ) MSDN.
Windows Azure .
MSDN Best Practices for Performance Improvements Using Service Bus Brokered Messaging.
Json.NET . Json.NET.

295

296

Unity Application Block


- MVC Contoso
Unity Application Block (Unity). Global.asax.cs ,
. MVC Unity,
:

MVC .
RegistrationController ( ):


Unity Application Block . Unity Application Block, MSDN.



http://msdn.microsoft.com/en-us/library/jj619274.

Twilio


Twilio API- SMS .
Twilio CQRS ES. Twilio
CQRS ( ,
. .).

, Twilio API .


, CQRS, Twilio
: . ,
. ,
, ().
. , .
. .
,
.
, .
. .
. ,
.


Twilio
. :

(Evan Cooke), Twilio.

297

298


. , , ,
.
, Twilio, , ,
.
, .

. Twilio
, : ,
; ,
; ,
.
. ,
.

Twilio : ,
,
. , .
Twilio
API Twilio. .


, Twilio
. ,
- , API REST
. Twilio
.
.
. ,
, .
, .

Twilio : , ,
. , ,
.
.
,
: .
,
, .

Twilio

Twilio .
,
.
. Twilio ,
.

Twilio :
Twilio.com

Twilio

Amazon Web Services Twilio



http://msdn.microsoft.com/en-us/library/jj619274.

299

Lokad


Lokad , ,
, , Lokad. Lokad
- Lokad.
Lokad , ,
, .
Lokad:

- (DDD),
CQRS (ES). ,
CRUD.
, Lokad ,
,
-.

, Lokad .

(Rinat Abdullin).

300

Lokad

-
Lokad - .
.
,
.
CQRS ES.
Lokad - .
.
-
.


- Lokad.CQRS.
- -
, .
.


Lokad ,
. Lokad
CRUD , .


Lokad , .
.
.

ES
Lokad SQL
.



.
, ,
.


,
. :

.

, .
,
.


, .

301

302

,
.
.

.
, ,
. ,
, .

( Lokad),
, . ,
, .
BLOB- .
100 000 .
.

Lokad :
: Lokad

Lokad.com

Lokad



http://msdn.microsoft.com/en-us/library/jj619274.

DDD CQRS


. :
.
, , , ,
.

SOLID ( , /,
, ).

, ,
(Application Lifecycle
Management, ALM).

, (
) ( AppFabric Windows
Server).

, .

CQRS, ,
.
, ,
. ,
. .
- .
,
,
.
. ,
,
.
, : .

(Alex Dubinkov) (Tim Walton).

303

304

,
.
,
.



( ), ,
.
, . , ,
, 1,6 .
:
IIS, , Open
Data Protocol (OData).

, ,
SQL .

,
, .
.

. ( Windows
Azure NServiceBus) .
.


API GUID. DBA
.
, , . ,
:
.

GUID
.

(INVERSION OF CONTROL, IOC)



. .
ICommandHandler<CommandType>
Unity. , .
.

DDD CQRS

,
. ,
, .

CQRS .
, ,
.

(SLA),
.


. OData JSON, AtomPub.

SOLID.



http://msdn.microsoft.com/en-us/library/jj619274.

305

.
, .
CQRS . .
. , (Customer Facing Portal, CFP),
CQRS.
CQRS DMS. :
(View Object, VO).
, ;
. ,
SQL Server . .
.
.

SQL. 20 .
.

.
, . ,
--.
: .
. ; ,
. . ,
. . ,
. ,
. . ,
, .
. ,
. .
, CQRS
.
, :
(Dependency Injection, DI) .

(Scott Brown).

306

DI.
. ,
. . ,
. .
.
CQRS, .
.
. ,
CQRS , .
, CQRS, .
.
,
. ; NuGet,
TeamCity. ,
, .
,
. .
. , .
, .
CQRS.
. .
, (,
). .
CQRS . ,
. .
CQRS, , .
, : , ,
. ,
.
(IoC),
. .
.
,
.
.
,
. .
, .
. ,
.
; .

307

308

, ;
. , ,
, .
. ,
.
, .
( ) ,
. , ,
.
. , .
? ,
?
?
, .
CQRS. .
, ,
. . ?
, .
, . CQRS
, .
, . DDD,
CQRS.
. .
.
.
.
.
, ;
. :
() ( ).

. ;
SQL , .
,
. ,
.
.
. ,
. RabbitMq .
, .
, .
, Redis. ,
Redis .
. .
, ,
.

, : .
.
, .
. ,
,
.
, .


, :
.

, .



http://msdn.microsoft.com/en-us/library/jj619274.

309

TOPAZ Technologies

CQRS ES?
.
, , ,
Oracle SQL Server.
.
. -, .
- . :
-, ;
.
. ,
(, ) ,
().

, .
, ,
.
.
.



. . ,
. , ,
.
, CQRS ES.
, .
, .

. (Gabriel N. Schenker),
TOPAZ Technologies.

310

TOPAZ Technologies

.
CQRS ES.
, ,
.
, . ,
CQRS .

. CQRS ES
. CQRS ES?
.
.


,
.

. , , ()
, ( ) .
, - , :
SQL .
, .
. -,
.
.

. -?
CQRS ES ,
- . -
. . .
CQRS ES, .
,
. .
. CQRS ES,
.



http://msdn.microsoft.com/en-us/library/jj619274.

311

eMoney Nexus

eMoney Nexus: CQRS


, CQRS Microsoft Patterns & Practices ,
CQRS ES. .
Patterns & Practices.

eMoney Nexus
eMoney Advisor ,
.
,
. .
.
, .
, ,
, . eMoney Nexus
.
Nexus . CQRS ES,
.
, CQRS,
.

(Jon Wagner), - ,
EMoney.

312

eMoney Nexus


Nexus ,
.
.

:
,
.

, .


Nexus
.

, Nexus .

,
.

- ,
- ; .

,
; .

,
( );
.

313

314


- ,
.

Web
Web

.
, , ,
. ,
, . Nexus
, .

eMoney Nexus

Web
Web

Nexus
Nexus

Nexus

Nexus


Nexus .
, ,
, ,
. ,
, .
: SQL Server Service Broker,
.
:
. ,
. Nexus
, .
Windows WCF,
.

315

316

Web
Web

WLBS
WLBS

Nexus

Nexus

Nexus

Nexus

Nexus

Nexus
, .
.
, , .
.
, .
, . ( )
, .
, ,
.
. SQL Server Service Broker .
.
,
.
Service Broker,
.
(API) , .

eMoney Nexus

WLBS
WLBS

Nexus

Nexus

Nexus

Nexus

Nexus/SQL Service Broker



1

2
3

Nexus/SQL
Service
Broker
1


Nexus


Nexus



Nexus
Nexus
. ,
, . ,
, .
,
. Nexus
, .

317

318

Web
Web

WLBS
WLBS

Nexus

Nexus

Nexus

Nexus

Nexus

Nexus
,
,

. ( )

. - ,

.
, ,
. ( ),
GUID ( ), .
, .
.
, (GUID
). .
, .

eMoney Nexus

, Nexus. CreateSubscription
( ), UpdateSubscription ( ) RepublishData ( ).
.
. ActivityID.
Nexus, , ,
. ,
. ,
.

319

320

1.

1.

2.

Web

2.

Web

3.
3.

4.

4.

10.
10.
9.
9.

Nexus
Nexus


Nexus

Nexus

Nexus

7.


7.


8.


8.

5.
/

5. /

6.

6.

Nexus . CQRS ES
. ,
.
CQRS = + . CQRS
, ,
.

Nexus

. .
.

.
.
.

, CQRS , :
. , ,
. . CreateSubscription
SubscriptionID. .

eMoney Nexus

, .

. , .

. BatchUpdate ( )
SubscriptionUpdate ( ).
.

+ = .
.

CQRS, 8 : .


, , .
.
,
. DI/IOC, ,
.

AJAX .
, SignalR, .

. ,
.
. ,
. , .

CQRS/ES,
.
. (Jon Wagner) Zeros, Ones and a Few Twos.

321


http://go.microsoft.com/fwlink/p/?LinkID=258574.

Contoso.
CQRS ES
.


V3.
. Windows Azure .
,
, .
.
( ), .
, V1-pseudo-prod, V2-pseudo-prod V3-pseudo-prod
GitHub. , . , 5 V1, 6
7
.


, , .

Visual Studio:
1. -
.
2. - Windows Azure
Windows Azure.
3. Windows Azure,
.
4. Windows Azure,
Windows Azure Windows Azure.
323

324

5. Windows Azure, Windows Azure


Windows Azure.
. SQL Express
.
.
. 1, 2, 3 4 SQL Express .
5 SQL SQL Express.
. V3 Conference.NoAzureSDK,
SDK Windows
Azure. 1 2.


, :
Visual Studio 2010 .

SQL Server 2008 Express .

ASP.NET MVC 3 4 V1 V2.

ASP.NET MVC 4 (Visual Studio 2010) V3.

Windows Azure SDK .NET 2011 V1 V2.

Windows Azure SDK .NET 2012


V3.
. V1 V2 ASP.NETMVC 3 ASP. NET MVC 4. , V3, ASP.NET MVC 4.
. Windows Azure SDK ,
Conference.NoAzureSDK.

Visual Studio
Microsoft Web Platform Installer 4.0.
NuGet, install-packages.
ps1, .
Windows Azure ( 2, 4, 5),
Windows Azure. Windows Azure (
BLOB-), Windows Azure SQL.
Windows Azure. :
Windows Azure Windows Azure
Windows Azure, Windows Azure.
Windows Azure,
Windows Azure.
. 1
Windows Azure.

Microsoft zip-.

, github.


SQL EXPRESS
1, 2, 3 4 SQL Express, Conference,
Install-Database.ps1 scripts.
.
SQL .

WINDOWS AZURE SQL


5 SQL Conference, Install-Database.ps1
scripts.
SQL Conference ,
( ,
Conference SQL Database):

. .
.
ServiceConfiguration.Cloud.cscfg Conference.Azure,
.
SQL:

Windows Azure:

325

326

Conference.Azure\ServiceConfiguration.Cloud.cscfg:

. LogLevelFilter Warning ()
Information ().
WADLogsTable, Verbose ( ).

Settings.xml
, Settings.xml Infrastructure Projects\Azure.
Settings.Template.xml Settings.xml.
. Settings.xml ,
Debug () Release ().
Windows Azure
Windows Azure, Settings.xml Infrastructure Projects\Azure
Windows Azure Windows
Azure.
. Settings.Template.xml,
.
. Windows Azure
. Windows Azure.


Conference Visual Studio , .

327

328

NuGet , installpackages.ps1 .


. :

Release
Release, Windows Azure.
Windows Azure .
, Windows Azure
( 5).

Debug
Debug,
Windows Azure , Windows Azure.
Windows Azure
, Windows Azure ( 2 4).

DebugLocal
DebugLocal,
Windows Azure -
Windows Azure.
SQL
Server ( 1 3).


,
Conference.Web.Admin.

Conference.Web.
, .

1. -, SQL, SQL
DebugLocal.
WorkerRoleCommandProcessor .
Conference.Web.Public Conference.Web.Admin ( Conference-Management) .

2. -, WINDOWS AZURE,

Debug.
WorkerRoleCommandProcessor .
Conference.Web.Public Conference.Web.Admin ( Conference-Management) .

3. , SQL, SQL
DebugLocal.
Windows Azure Conference.Azure.
. Visual Studio ,
Windows Azure.

4. , WINDOWS AZURE,

Debug.
Windows Azure Conference.Azure.
. Visual Studio ,
Windows Azure.

5. WINDOWS AZURE, WINDOWS AZURE,



Conference.Azure Windows Azure.
. Conference SQL
Install-Database.ps1 scripts, . ,
, Conference
SQL Express Conference, .


, .


Conference xUnit.net.

329

330

. xUnit.net Codeplex.


Visual Studio Conference.AcceptanceTests.
NuGet , installpackages.ps1 .
SpecFlow. SpecFlow . SpecFlow.
SpecFlow xUnit.net.
Conference.AcceptanceTests , Conference,
: SQL
Windows Azure
Windows Azure.
xUnit
xUnit Visual Studio (, TDD.net). XUnit
.



http://msdn.microsoft.com/en-us/library/jj619274.

V1 V2
V1 , V2,
. , V2 Windows
Azure.
. Conference.
1. , V1 Windows Azure.
2. V2 Windows Azure. V2
MaintenanceMode, true ().
, .
3. V2 ( ) Windows Azure.
4. V1 ( )
. .
5. (. ).
6. false () MaintenanceMode.
7. V2 Windows Azure.
. MaintenanceMode
Windows Azure.


SQL.
MigrationToV2 Settings.xml, Conference
App.config Windows Azure
SQL.

331

332

Settings.xml Windows Azure, V2.


V1 V2, , EventSourcing ,
V1. , V1, Program.cs
MigrationToV2:

V2 Settings.xml:

. V2
Windows Azure,
V1. , MigrationToV2.
App.config DbContext.ConferenceManagement.
SQL,
SQL. , SQL Windows Azure,
. , SQL Database
. ServiceConfiguration.csfg.
. Debug,
DbContext. ConferenceManagement SQL
Express.
. , ,
Windows Azure.
Windows Azure MigrationToV2.Azure.
. Windows Azure . Using
Remote Desktop with Windows Azure Rotes (
Windows Azure).
. V1 V2
DebugLocal.


- , ,
:
1. SQL , .
2. Windows Azure, Settings.xml EventSourcing
MessageLog.

V2 V3
V2 , V3,
. , V2 Windows
Azure.
. Conference.
1. , V2 Windows Azure.
2. V3 Windows Azure. V3
MaintenanceMode, true.
3. MigrationToV3.InHouseProcessor, V3.
4. MaintenanceMode V2 (
) true. - ,
. , Windows Azure
Ready (). .
5. MaintenanceMode V3 (
) false. MigrationToV3.InHouseProcessor
V2. V2.
, MaintenanceMode V2.
- V2 ,
V3 . .
6. Windows Azure VIP, - V3
.
7. V2, .
8. V3 Windows Azure.
. MaintenanceMode
Windows Azure.



http://msdn.microsoft.com/en-us/library/jj619274.

333

A
AddSeats , 74
AssignRegistrantDetails, , 66-67
AzureEventSourcedRepository, , 189-190
AzureMessageLogWriter, , 146-147

B
BuildMessage, 144

, , 218-219
, 219
, 1
, , 215
, , 214
, 301
, , 213
-, , 214
DDD/CQRS , 303-305

C
CachingConferenceDao, , 194-195
CAP, , 261
CommandBus, , 48, 142
CommandDispatcher, , 187-189
ConferenceConfiguration.feature , 74-76
ConferenceController, , 27
ConferenceProcessor, , 141
ConferenceRegistrationDbContext, , 71, 72
ConferenceViewModelGenerator, , 128, 138-140
Contoso , 1
CRUD, 101

E
else if, 176-177
eMoney Nexus:
EventBus, , 48, 144
EventSourced, , 115, 119-120
EventStore, , 120-121
EventStoreBusPublisher, , 122, 191

D
DAO, 59-60
DDD
, 7
, , 215
, 248
, , 215
, , 217
, , 215217
, 212-215
, , 218
CQRS, 220-221
CQRS, 227-228
, 212
, ,
213
, , 214

, 220

I
IAggregateRoot, , 249
ICommand, , 253
IEvent, , 259
IQueryable, 57-58

G
GUID, 196

L
LoadFrom, , 119-120

M
MakeSeatReservation, , 175
memento, , 189
MessageProcessor, , 46-47
Migrator, , 148-150

O
OnCreateContainer, , 187
335

336

Order, , 31-33, 64, 81-83, 113-114


Order, , 63, 116, 185
Order, 254-255
OrderCommandHandler, , 28-29, 113-114, 118
OrderController, , 63
OrderItemsView, , 69
OrderPlaced, , 178
OrdersView, , 69
OrdersView, , 69
OrderTotalsCalculated, , 185
OrderViewModelGenerator, , 69-71

R
RegenerateViewModels, , 148-150
RegisterToConference, , 29-31
RegistrationController, , 28, 65-66, 68, 134-135,
181-182
, 296
RegistrationController, , 140
RegistrationProcessManager, , 41-42, 64-65, 134136, 157, 159-161
, 199
, 174-181
, 322-330
, 328
,
325
, 327-328
, 325-327
, 323-324, 330
, 324
, 329-330
Settings.XML, 327
SQL Express, 325
, 322
Windows Azure SQL, 325327
S
SeatAssignmentsHandler, , 136-137
SeatsAvailability, , 73-74, 193-194
SeatsAvailability, , 190
SeatsAvailabilityCommand, , 193-194
SeatType, , 140
SelfRegistrationEndToEndWithControllers.feature,
, 78-79
SelfRegistrationEndToEndWithControllersSteps,
, 79-81
SelfRegistrationEndToEndWithDomain.feature,
, 152-154
ServiceBusConfig, , 141-142
SessionSubscriptionReceiver, , 143-144
SessionSubscriptionReceiver, , 193-194

Settings.Template.xml, , 192
SpecFlow, 74-76, 152-154
SpecifyRegistrantAndPaymentDetails, , 182-185
SpecifyRegistrantDetails.cshtml, , 67
SqlEventSourcedRepository, , 117-119
SqlProcessDataContext, , 179-180
State Change, , 89
SubscriptionReceiver, , 45-46, 198-199
SynchronousCommandBusDecorator, , 187-188

T
TOPAZ Technologies, 310
TopicSender, , 145-146
Twilio, 297-299

V
V1 , 91-124
, 98-99
, 113-116
, 93-95
, 105-106
, 122-123

, 97, 104, 108
CRUD, 101

, 105
, 97-98, 113
EventSourced, , 115
EventStore, , 120-121
EventStoreBusPublisher, , 122
, 107-108
, 123-124
, 108-123
, 111-113
, 101-103
,
123
, 124
Order, , 113-114
Order, , 116
OrderCommandHandler, , 113-114, 118

, 108
, 97-108
, 109111
,
117-118
, 107
, 105

, 118-120

,
120
SqlEventSourcedRepository, , 117-118,
119
,
, 99-101
, 123
Windows Azure, 104

Windows Azure, 120-121
VersionedEvent, , 260

W
WaitUntilSeatsAreConfirmed , 182-184
Windows Azure, 272-279

, 245
, 105-106
, xxix

, 25
, 215
, 249
, 250-252
, 98-99
, 128
ORM, 249
, 34-39
, 21
, 113-116
, 19-20

, , 218-219

, 18, 26

, 55-56
, 61
, 158159
V1, 93-95
, 126-127
ASP.NET MVC, 198
, 186

SQL Express, 325


, 325-327
, 304
, 282
, 172
- , 92
-, 232

, 8, 16
, 61

, 107-108
CQRS, 263-266
CQRS ES, 248-249,
261-262
, 92, 158
, 54
, 201-210
, 208
, 210
, 203
CQRS, 204-205
, 208
, 209

, 205

, 206
, 207
, , 202203
, 210
, 201-202, 208-209
, 208

, 207
, 206-210
, 209
CQRS, 206
V3, 159
, 297-298

, . CQRS ()
, 5
CQRS, 231
CQRS ES, 247-279
, 250-252
ORM, 249
,
249

337

338

CAP, , 261

, 252-256
DTO, 247
, 256
, 267-268
, 248
DDD , 248
, 263
, 268
, 260
, 259-260
, 256
, 248
, 269-271
, 248-249,
261-262
CQRS, 263-266
, 270271
IAggregateRoot, , 249
ICommand, , 253
IEvent, , 259
, 256-257
, 258-259
, 269

CQRS, 268-271
Windows Azure, 278
, 279
, 273
, 270
, 265
Order, 254-255
, 269
, 274-275
, 276-278
, 247
, 266
, 270
, 264
, 275

, 273
,
, 271
, 269
VersionedEvent, 260
Windows Azure, 272-279
Windows Azure, 273-279
, 267

, 219
, 208

, 136, 140, 148-150


, 248
, 233
, 19-20
, 57
, . ()

, 14-15, 54, 285-289
, 208

, 22-23, 34-39
, 5
2: , 333
, 283
CQRS ES, 279
CQRS, 234
, 11
, 210

, 52

, 90
, 200
DDD/CQRS
, 305
, ,
309
, Lokad,
302
, TOPAZ Technologies, 310
,
, 295, 296
V1, 124
, 155
, 268
OrderPlaced, 178
, 309
, 134
, 134

, 15
, 15
, 60-61
, 17-18
, 55
, 17

, 304
, 72
, 199

, 125, 158
, 298
, 111-113
, 101-103
, 282-283
, 200

, 207
, 165-172

, 40, 42
, 302
, 76-81

, xxiii-xxviii
, xxiv

, 281

Contoso, 10-11
CQRS (), 10
, 8
, 218
, , 91
, 330

, 252-256
CQRS ES, 253
, 14, 54, 125, 157
, 228
DTO, 247
, 161
, 254
, 141-142
, 256
, 166
, 44-47
, 186-189
, 304
, 61-62
(Inversion of Control,
IoC), 304-305
, 4
, 167
, 1

, 328
Lokad, 300-302
, 212-215
, 89
, 215

, 56

, .
()
, 4
, 171-172
CQRS, 230

, 48

, 273
, . Contoso
, 4
, 16, 92
, 55
,
140

, 138
, 15
, 16
, 146
, 107
, 105
, 266

, 56
, 69-71
, 225-226
, 331
, 155
, 136, 140, 148-150
, 333
V1 V2, 150-151, 331-333
V2 V3, 333

, 194-195
, 151
, 247

, 158
,
166

339

340

, 264
, 256-257
, 258-259
SeatsReserved, 175
, 269
, 265
, 269
, 4
, 270

, 203
, . ,

, 295
-, , 214

.
,

;

, 11
-, 281-283
, 8
, 8, 215-217
, 210
, 220
, 9
, 92-93

, 92

, 53-90

74-81
AddSeats, , 74
, 55-56
ASP.NET MVC, 66-68
, 83-89
, 61-62
ConferenceRegistrationDbContext, , 71
, 64-66
DAO, 59-60
, 57
, 84-86
, 76-81
, 62-74
, 83-84

, 54
, 81-83

, 90
, 55
, 63
, 55
OrderItemsView 69
OrdersView, 69
OrderViewModelGenerator, , 69-71
, 60-61
,
69-71
, 72
, 56
, 56
, 61
SeatsAvailability, , 73-74
SpecFlow, 74-76

(Transient Fault Handling Application
Block), 62
,
13, 52
, 25
, 34-39
, 18, 26
, 92-93
, 44-47
CommandBus, , 48
, 25
, 8
EventBus, , 48
, 48
, 25-49
, 40-42
MessageProcessor, , 46-47
, 52
, 18-25
, 22-23, 34-39
, 25
, 48
, 49
, 21
SubscriptionReceiver, , 45-46
, 49-52
, 24
, 19-20

, 92-93
, 23-24
Windows Azure, 42
, 109-111
, 9

, 8-9


, 92
V1 , 97, 104, 108
, 21
, 16-17
, 196-199
, 168
, 267
, 292
, 155

, 25
, 267-268
,
199
, 199
, . - ()
, xxix-xxx
API, 294
, , 15
,
, 99-101, 232
CQRS ES, 271

, 134
, 162-163
, 181-185
, 209
, 17
, 163-164
, 164
, 165
, 17
, 83-89
, 151
GUID, 196
, 269
, xxiii-xxviii
, xxi-xxii
- , .
DDD
, 233

, 7-11
, 7
, 15
, , 213
, xxvi-xxvii
, xxvi-xxvii
, 84-86
, 57
Unity Application Block, 296


(Transient Fault Handling Application Block),
62
1, .
2, .
, 123
ASP.NET MVC, 66-68
, 23-24
ASP.NET MVC, 66-68
, 61-62
, 199
, 301

, 169-170
, 201-202, 208-209
, 162
, 246247
, 298-299
, 178-179
, xxiv-xxv


(Command Query Responsibility Segregation,
CQRS),
, 1
, 263
, 105
, 298
, xxv-xxvi, 297-321
, 304
DDD, 301
DDD/CQRS , 303-305
, 301
, 306-309
eMoney Nexus:
, 301-302
, 297-298
, 298
, 302
(Inversion
of Control, IoC), 304-305
, 304
Lokad, 300-302
, 299, 302, 305,
309, 310
, 298
, 298-299
, 301
, 304
, 297-299
, 301

341

342

, 309
TOPAZ Technologies, 310
Twilio, 297-299
, 120
, 15, 92
(ES)
, 245
, 282
, 242
CQRS/ES, 243-245
, 91-92
, 236-240
, 245
, 235-246
, 209
ORM, 236-240
, 1
,
, 246-247
, 245
, 301-302
, 205
, 245
V1 , 97-98, 113
?, 240-242
, 2-3
. CQRS ();

- ();
();

();

(); - ()

(), 2
- (), 3
- (), 3

(), 2

(Transient Fault Handling Application
Block), 62
CQRS (), 2
, 10
(), 2

, xxiii-xxviii
, xxiii-xxiv

, 301
, 285
CQRS, 286

, 285289
, 285-290
, , 285
, , 16-17
, 62-74, 133

, 25, 49
, 208
, 168
, 208
, 49
, 186-189
Contoso, 3-5, 7
. V1
, 10
, 282
ORM, 236-240

, 165
, 282
CQRS ES, 259-260
, 14, 54, 125, 157
, 128
, 270-271
, 229
, 256
, 248
, 151
, 270271
, 260
, 270
SeatsReserved,
175
, 146-150, 274-275
, 117-118
, 131-132
, 161
, 129-131
, 276-278
, 167
, 270

, 118-120
, 275
, 269-271
, .

, 301
,
199

, 186

CQRS, 268-271, 286


, 294
, 228-230
, 268
; ,
, 294
, 167, 192
, 81-83
, 142
, 128-129
, , 202203
, 146-147
, 128
, 146
, 133
, 269
, 151
; ,
, 294
, 264
, 294
, 295

, 207
, 269
, 128
Windows Azure, 278
,
128
, 48
, xxiii-xxiv
, 270-271
, , 215
, , 214

, 64-66
, 64-66

,
195-196
, 293
, 49-52, 200
, 76-81
, 151-155
, 83-84
, 329-330
, 200
, 200
, ,
291, 296
, 294

, 295, 296
, 292
, 293
Unity Application Block,
296
API, 294
Windows Azure, 291

, 24
, 265
, 4, 17
(Event Sourcing, ES)
, 245
, 4

, 231
, , 213
, 125-155

, 134
, 126-127
AzureMessageLogWriter, , 146-147
, 155
BuildMessage, 144
,
134
, 141142
ConferenceProcessor, , 141
ConferenceViewModelGenerator,
, 128, 138-140
, 136, 140, 148-150
, 128
, 146-150
, 151
EventBus, , 144
, 142
, 151-155
, 133

, 128
, 128-129
, 133
, 146-147
, 146
V1 V2, 150-151
Migrator, , 148-150
, 155
,
128
, 151
, 127-133

343

344

, 131-132
, 129-131
, 151
RegenerateViewModels, , 148-150
RegistrationController, , 140
RegistrationProcessManager, , 134
,
140

, 138
SeatAssignmentsHandler, , 136-137
SeatType, , 140
ServiceBusConfig, , 141-142
SessionSubscriptionReceiver, , 143-144
SpecFlow, 152-154
TopicSender, , 145-146
, 134
, xxvii
, xxvii
, , 214
, 304
, 233
, 157-200
, 158-159
ASP.NET MVC,
198
, 165
, 186
AzureEventSourcedRepository, , 189190
, 166
CommandDispatcher, , 187, 188-189
,
167
OrderPlaced, 178
else if, 176-177
, 161
, 161
, 167
EventStoreBusPublisher, , 191
, 174-200
, 165-172
, 200
MakeSeatReservation, , 175
Memento, , 189
, 167,
192
, 200
, 199

,
195-196
, 172
,

199
OrderTotalsCalculated, , 185
, 168
,
,
196-199
SeatsReserved,
175
,
169-170
, 162

Windows Azure, 198-199
, 178-179
, 194195
, 173-174
RegistrationController, , 181-182
RegistrationProcessManager, , 157,
159-161
RegistrationProcessManager,
, 174-181
, 159-161

, 199
,
, 171-172
SeatsAvailability, , 193-194
SeatsAvailability, , 190
SeatsAvailabilityCommand, , 193-194
GUID, 196
, 168
SessionSubscriptionReceiver, ,
193-194

, 166
SqlProcessDataContext, , 179-180
, 186-189
SynchronousCommandBusDecorator,
, 187-188
, 200
, 199

, 162-163
, 181-185
, 163-164
, 164
, 165
, 200
WaitUntilSeatsAreConfirmed, , 182184
, 15

Global.asax.cs, 296
Settings.XML, 327
Web.config, 68
, 281-282
, 217
API, 294

Windows Azure, 198-199

, 245
Windows Azure, 273-279

Windows Azure 120-121

Windows Azure, 120-121
, 245
Windows Azure, 273-279

, 306-309

, 60-61
, 297-299

CQRS
, , 232
, 5
-, 232

, 233
, , 228
, 231
, 211-221
DDD, 220-221, 227-228
, 204-205
(Event Sourcing, ES),
, 243-245
, , 229
, 231
, 222
, xxiv-xxv
, , 228-230
, 234
, 225-226

, xxv-xxvi
, 230
, 233
,
, 232
?, 233
?, 232-234
?, 230-232
, 25
, 127-133

, 18-25

Memento, , 189
, 25
Windows Azure, 42, 104
,
, 291

, 322
Windows Azure SQL, 325-327
, 273
, xxix-xxx
, xxix-xxx
, 208
, 206
V1 , 123-124

345

Patterns & Practices

,

.
, .
,
CQRS, , Windows Azure

, CQRS ES.
.
.

.
CQRS ES ,
.
. ,
CQRS.

CQRS ES

CQRS
7.

CQRS

7.


,2.

.,

CQRS, , Windows Azure

8.

6.

,
2.


4.
8.

CQRS

ES.


5.


6.
.

V1


4.

5.
V1 .

Patterns & Practices





.
,
Microsoft Patterns & Practices.


.


.

,
.

Microsoft
.
,

.
,

Microsoft.

SQRS

CQRS ES
,

SQRS
1.

3.
1:


:


. ,

CQRS.
3.
1:
1.

Patterns & Practices.


:

, .
,
Windows Azure, .
!
(Scott Guthrie), -,
Azure, Microsoft

Patterns & Practices

Patterns & Practices

CQRS ES

, Patterns & Practices


, .

Patterns & Practices


, ,

.



.


.

Microsoft,

.


, Patterns & Practices.

, .

.
msdn.microsoft.com/practices