You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ReadMe.md
+87-42Lines changed: 87 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
# EventDriven.CQRS
1
+
# EventDriven.ReferenceArchitecture
2
2
3
-
An event-driven approach to Command Query Responsibility Segregation.
3
+
Reference architecture for using **EventDriven** abstractions and libraries for Domain Driven Design (**DDD**), Command-Query Responsibility Segregation (**CQRS**) and Event Driven Architecture (**EDA**).
4
4
5
5
## Prerequisites
6
6
-[.NET Core SDK](https://dotnet.microsoft.com/download) (5.0 or greater)
@@ -12,10 +12,11 @@ An event-driven approach to Command Query Responsibility Segregation.
This project builds on the principles of [Domain Driven Design](https://en.wikipedia.org/wiki/Domain-driven_design) to provide a set of abstractions and reference architecture for implementing the [Command Query Responsibility Segregation](https://docs.microsoft.com/en-us/azure/architecture/patterns/cqrs) pattern, also known as as CQRS. Because entities process commands by emitting domain events, adding [event sourcing](https://microservices.io/patterns/data/event-sourcing.html) at a later time will be relatively straightforward.
19
+
This project builds on the principles of [Domain Driven Design](https://en.wikipedia.org/wiki/Domain-driven_design)(DDD) to provide a set of abstractions and reference architecture for implementing the [Command Query Responsibility Segregation](https://docs.microsoft.com/en-us/azure/architecture/patterns/cqrs)(CQRS) pattern. By providing an event bus abstraction over [Dapr](https://dapr.io/) (Distributed Application Runtime), the reference architecture demonstrates how to apply principles of [Event Driven Architecture](https://en.wikipedia.org/wiki/Event-driven_architecture) (EDA). Because entities process commands by emitting domain events, adding [event sourcing](https://microservices.io/patterns/data/event-sourcing.html) at a later time will be relatively straightforward.
19
20
20
21
The **Reference Architecture** projects demonstrate how to apply these concepts to two microservices: `CustomerService` and `OrderService`. In addition, each service has *separate controllers for read and write operations*, thus segregating command and query responsibilities, with different sets of models, or Data Transfer Objects (DTO's).
21
22
-**Query Controller**: Uses repository to retrieve entities and converts them to DTO's with AutoMapper.
@@ -30,21 +31,22 @@ The **Reference Architecture** projects demonstrate how to apply these concepts
- Then open http://localhost:8080 to view containers after executing `dapr run` commands.
37
-
```
38
-
dapr dashboard
39
-
```
40
-
2. Use Tye or Dapr to run the customer service.
36
+
> **Note**: As an alternative to Tye, you can run services directly usng the Dapr CLI. This may be useful for troubleshooting Dapr issues after setting `Microsoft.AspNetCore` logging level to `Debug`.
1. Open a terminal at the **reference-architecture** directory and run Tye to launch all services simultaneously.
41
40
```
42
-
dapr run --app-id customer-service --app-port 5656 --components-path ../dapr/components -- dotnet run
41
+
tye run
43
42
```
44
-
3. Use Dapr to run the order service.
43
+
2. Alternatively, run Tye in debug mode.
45
44
```
46
-
dapr run --app-id order-service --app-port 5757 --components-path ../dapr/components -- dotnet run
45
+
tye run --debug *
47
46
```
47
+
- Set breakpoints in **OrderService**, **CustomerService**.
48
+
- Attach the IDE debugger to **OrderService.dll**, **CustomerService.dll**.
49
+
3. Open the Tye dashboard at http://localhost:8000 to inspect service endpoints and view logs.
48
50
4. Create some customers.
49
51
- Open http://localhost:5656/swagger
50
52
- Execute posts using contents of **customers.json**.
@@ -64,12 +66,6 @@ The **Reference Architecture** projects demonstrate how to apply these concepts
64
66
6. Update the address of a customer who has order.
65
67
- Note the address is also updated for the customer's orders.
66
68
- Observe log messages in terminal when integration events are published and handled.
67
-
7. To **debug** services, you can use [tye](https://github.com/dotnet/tye) with the *Dapr extension*.
68
-
- Open a terminal at the reference-architecture folder.
69
-
- Run `tye run --debug *`
70
-
- Set breakpoints in each project.
71
-
- Attach the debugger to each process.
72
-
- Open http://localhost:8000 to view the Tye Dashboard.
73
69
74
70
### Development Guide
75
71
@@ -87,16 +83,23 @@ The **Reference Architecture** projects demonstrate how to apply these concepts
87
83
```
88
84
- Where you need to execute business logic, implement `ICommandProcessor` and `IEventApplier` interfaces to process commands by emitting domain events and to apply those events to mutate entity state.
89
85
```csharp
90
-
public IEnumerable<IDomainEvent> Process(CreateCustomer command)
91
-
// To process command, return one or more domain events
6. Add configuration entries to **appsettings.json**.
178
+
```json
179
+
"CustomerDatabaseSettings": {
180
+
"ConnectionString": "mongodb://localhost:27017",
181
+
"DatabaseName": "CustomersDb",
182
+
"CollectionName": "Customers"
183
+
},
184
+
"DaprEventBusOptions": {
185
+
"PubSubName": "pubsub"
186
+
},
187
+
"DaprEventCacheOptions": {
188
+
"DaprStateStoreOptions": {
189
+
"StateStoreName": "statestore-mongodb"
190
+
}
191
+
},
192
+
"DaprStoreDatabaseSettings": {
193
+
"ConnectionString": "mongodb://localhost:27017",
194
+
"DatabaseName": "daprStore",
195
+
"CollectionName": "daprCollection"
196
+
},
197
+
"DaprEventBusSchemaOptions": {
198
+
"UseSchemaRegistry": true,
199
+
"SchemaValidatorType": "Json",
200
+
"SchemaRegistryType": "Mongo",
201
+
"AddSchemaOnPublish": true,
202
+
"MongoStateStoreOptions": {
203
+
"ConnectionString": "mongodb://localhost:27017",
204
+
"DatabaseName": "schema-registry",
205
+
"SchemasCollectionName": "schemas"
206
+
}
207
+
}
208
+
```
209
+
7. Repeat these steps for the **Order** service.
165
210
- Reference the Common project.
166
211
- Add **Integration/EventHandlers** folders with a `CustomerAddressUpdatedEventHandler` class that extends `IntegrationEventHandler<CustomerAddressUpdated>`.
167
212
- Override `HandleAsync` to update the order addresses for the customer.
168
213
```csharp
169
214
public override async Task HandleAsync(CustomerAddressUpdated @event)
0 commit comments