-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
34 lines (25 loc) · 1.11 KB
/
Program.cs
File metadata and controls
34 lines (25 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using CQRSSample;
using Messages;
using MQContract;
using MQContract.CQRS;
using MQContract.CQRS.Extensions;
using MQContract.InMemory;
var serviceConnection = new Connection();
var contractConnection = ContractConnection.Instance(serviceConnection);
var cqrsConnection = contractConnection.CreateCQRSConnection("CQRSChannel");
await cqrsConnection.RegisterCommandProcessorAsync(new CreateUserProcessor(), "CommandGroup");
await cqrsConnection.RegisterQueryProcessorAsync(new GetUserProcessor(), "QueryGroup");
var context = new MQContract.CQRS.Context();
Console.WriteLine("Executing CreateUserCommand...");
await cqrsConnection.ExecuteCommandAsync(new CreateUserCommand("user123", "John Doe", "john@example.com"), context);
Console.WriteLine("Executing GetUserQuery...");
try
{
var user = await cqrsConnection.ExecuteQueryAsync<GetUserQuery, User>(new GetUserQuery("user123"), context, TimeSpan.FromSeconds(10));
Console.WriteLine($"Retrieved user: {user?.UserName}, {user?.Email}");
}
catch (QueryCallException e)
{
Console.WriteLine($"Query error: {e.Error.Message}");
}
Console.WriteLine("CQRS sample completed.");