Skip to content

Commit 97a4695

Browse files
authored
Merge pull request #36 from markjbrown/mjb-updates
Mjb updates
2 parents 8311674 + 82d1a0b commit 97a4695

File tree

11 files changed

+53
-49
lines changed

11 files changed

+53
-49
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/devcontainers/dotnet:6.0-bullseye
1+
FROM mcr.microsoft.com/dotnet/sdk:8.0
22

33
# Install Azure Functions Core Tools
44
RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg

.devcontainer/devcontainer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"extensions": [
1818
"ms-dotnettools.vscode-dotnet-runtime",
1919
"ms-dotnettools.csharp",
20+
"ms-azuretools.vscode-docker",
2021
"ms-azuretools.vscode-bicep"
2122
]
2223
}

distributed-counter/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Typically, you can avoid concurrency issues by implementing optimistic concurren
2929

3030
## Solution
3131

32-
In a distributed counter solution, a group of distributed counter items are used to keep track of the number. By having the solution distribute the counter across multiple items, update operations can be performed on a random item without causing contention. Even more, the solution can calculate the total of all counters at any time using an aggregation of the values from each individual counter.
32+
In a distributed counter solution, a group of distributed counters, implemented as documents, are used to keep track of the number. By having the solution distribute the counter across multiple documents, update operations can be performed on a random document without causing contention. Calculating the current counter value can be done at any time by performing an aggregation of the values across all the documents in a query.
3333

3434
## Sample implementation
3535

@@ -89,7 +89,7 @@ You need to configure **two** application configuration files to run this app.
8989

9090
While on the Keys blade, make note of the `URI` and `PRIMARY KEY`. You will need these for the sections below.
9191

92-
1. Open the Visualizer project and add a new **appsettings.development.json** file with the following contents:
92+
1. Open the **Visualizer** project and add a new **appsettings.development.json** file with the following contents:
9393

9494
```json
9595
{
@@ -115,7 +115,7 @@ While on the Keys blade, make note of the `URI` and `PRIMARY KEY`. You will need
115115

116116
Next move to the other project.
117117

118-
1. Open the ConsumerApp project and add a new **appsettings.development.json** file with the following contents:
118+
1. Open the **ConsumerApp** project and add a new **appsettings.development.json** file with the following contents:
119119

120120
```json
121121
{
@@ -199,10 +199,10 @@ Next move to the other project.
199199
200200
## Summary
201201
202-
In conclusion, the Distributed Counter design pattern offers a powerful solution for managing count-related data in NoSQL databases. By leveraging distributed systems' capabilities, this pattern enables the seamless tracking of numeric values across various nodes, ensuring accuracy and scalability. Through careful design and implementation, applications can efficiently handle scenarios involving likes, votes, or any form of quantifiable interactions.
202+
In conclusion, the Distributed Counter design pattern offers a powerful solution for managing count-related data in NoSQL databases. By leveraging multiple documents and randomizing access to reduce concurrency issues, this pattern enables the tracking of numeric values at any scale with accuracy. Through careful design and implementation, applications can efficiently handle scenarios involving likes, votes, product inventory or any form of quantifiable interactions where concurrency is an issue.
203203
204-
The beauty of the Distributed Counter lies in its ability to maintain consistency in a distributed environment, achieving high availability and fault tolerance. By leveraging atomic operations and optimized data structures, it minimizes contention while delivering rapid and accurate count updates.
204+
The beauty of the Distributed Counter lies in its ability to maintain consistency, achieving high availability and fault tolerance. By leveraging atomic operations and optimized data structures, it minimizes contention while delivering rapid and accurate count updates.
205205
206-
From social media interactions to monitoring system metrics, the Distributed Counter pattern empowers applications to handle dynamic, high-velocity scenarios. By incorporating this pattern, developers can harness the full potential of NoSQL databases, ensuring reliable count management that scales alongside user engagement and system growth.
206+
From social media interactions, ecommerce or monitoring high-volume system metrics, the Distributed Counter pattern empowers applications to handle dynamic, high-velocity scenarios. By incorporating this pattern, developers can harness the full potential of NoSQL databases, ensuring reliable count management that scales alongside user engagement and system growth.
207207
208208
As technology continues to evolve, and as user interactions become increasingly diverse and complex, the Distributed Counter design pattern remains an essential tool in a developer's toolkit, providing a solid foundation for effective count management in the dynamic world of modern distributed applications.

distributed-counter/source/ConsumerApp/DistributedCounterConsumerApp.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
1414
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
1515
</Content>
16-
<None Remove="appsettings - Copy.json" />
17-
<None Remove="appsettings.development.json" />
16+
1817
<Content Include="appsettings.json">
1918
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2019
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>

distributed-counter/source/Counter/CosmosDistributedCounter.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<Content Remove="C:\Users\sandnair\.nuget\packages\microsoft.azure.cosmos\3.31.2\contentFiles\any\netstandard2.0\ThirdPartyNotice.txt" />
18-
</ItemGroup>
19-
20-
<ItemGroup>
21-
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.41.0" />
17+
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.4*" />
2218
</ItemGroup>
2319

2420
</Project>

distributed-counter/source/Visualizer/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public void ConfigureServices(IServiceCollection services)
3131
{
3232
services.AddRazorPages();
3333
services.AddServerSideBlazor();
34-
services.AddSingleton<DistributedCounterManagementService>(InitializeDistributedCounterManagementServiceAsync(Configuration).GetAwaiter().GetResult());
34+
services.AddSingleton<DistributedCounterManagementService>(InitializeDistributedCounterManagementServiceAsync(Configuration));
3535
}
3636

3737

38-
private static async Task<DistributedCounterManagementService> InitializeDistributedCounterManagementServiceAsync(IConfiguration configuration)
38+
private static DistributedCounterManagementService InitializeDistributedCounterManagementServiceAsync(IConfiguration configuration)
3939
{
4040

4141
string endpoint = configuration["CosmosUri"];

event-sourcing/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ While event sourcing can be implemented with various types of databases, this pa
2323

2424
1. Flexible schema: NoSQL databases generally allow for schema flexibility. Easy support for unstructured event data formats that are often in JSON formats align perfectly with the needs of event sourcing architectures.
2525

26-
1. Scalability: NoSQL databases are typically designed for high scale. Data volumes in event sourcing patterns can range from the thousands to millions of messages per second. An underlying database needs to scale and do so seemlessly. Azure Cosmos DB's scale-out architecture is well-suited here with highly elastic throughput and storage.
26+
1. Scalability: NoSQL databases are typically designed for high scale. Data volumes in event sourcing patterns can range from the thousands to millions of messages per second. An underlying database needs to scale and do so seamlessly. Azure Cosmos DB's scale-out architecture is well-suited here with highly elastic throughput and storage.
2727

2828
This sample demonstrates:
2929

event-sourcing/source/CartEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CartEvent
1111
public int UserId { get; set; }
1212
public string EventType { get; set; } = "";
1313
public string? Product { get; set; }
14-
public int? QuantityChange { get; set; }
14+
public int? QuantityChange { get; set; } = 0;
1515
public List<CartItem>? ProductsInCart { get; set; }
1616
public string EventTimestamp { get; set; } = DateTime.UtcNow.ToString();
1717
}

event-sourcing/source/EventSourceFunction.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ namespace EventSourcing
1111
{
1212
public class EventSourceFunction
1313
{
14-
private readonly ILogger _logger;
14+
private readonly ILogger<EventSourceFunction> _logger;
1515

16-
public EventSourceFunction(ILoggerFactory loggerFactory)
16+
public EventSourceFunction(ILogger<EventSourceFunction> logger)
1717
{
18-
_logger = loggerFactory.CreateLogger<EventSourceFunction>();
18+
_logger = logger;
1919
}
2020

2121
[Function("EventSourcing")]
@@ -25,22 +25,22 @@ public EventSourceFunction(ILoggerFactory loggerFactory)
2525
Connection = "CosmosDBConnection",
2626
CreateIfNotExists = true,
2727
PartitionKey = "/CartId")]
28-
public static async Task<IActionResult> Run(
29-
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
30-
IAsyncCollector<CartEvent> cartEventOut,
31-
ILogger log)
28+
public async Task<IActionResult> Run(
29+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
30+
FunctionContext context)
3231
{
33-
log.LogInformation("C# HTTP trigger function processed a request.");
32+
_logger.LogInformation("C# HTTP trigger function processed a request.");
3433

3534
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
3635
string responseMessage;
3736

3837
if (requestBody != null)
3938
{
4039
CartEvent cartEvent = JsonConvert.DeserializeObject<CartEvent>(requestBody) ?? throw new ArgumentException("Request body is empty");
41-
await cartEventOut.AddAsync(cartEvent);
40+
_logger.LogInformation(JsonConvert.SerializeObject(cartEvent, Formatting.Indented));
4241

43-
responseMessage = $"HTTP function successful for event {cartEvent.EventType} for cart {cartEvent.CartId}.";
42+
//responseMessage = $"HTTP function successful for event {cartEvent.EventType} for cart {cartEvent.CartId}.";
43+
return new OkObjectResult(cartEvent);
4444
}
4545
else
4646
{

event-sourcing/source/EventSourcing.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
9+
<ItemGroup>
10+
<None Update="local.settings.json">
11+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
12+
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
13+
</None>
14+
</ItemGroup>
915
<ItemGroup>
1016
<FrameworkReference Include="Microsoft.AspNetCore.App" />
1117
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
1218
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.CosmosDB" Version="4.6.0" />
1319
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
14-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
15-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.0" />
20+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.1" />
21+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.4" />
1622
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
1723
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
1824
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="4.7.0" />

0 commit comments

Comments
 (0)