Skip to content

Commit f0b07d5

Browse files
committed
Move sample code to dedicated repo
1 parent b92066a commit f0b07d5

File tree

198 files changed

+12716
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+12716
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
<appSettings>
7+
<add key="Database" value="\test.db" />
8+
<add key="QueueName" value="testing" />
9+
<add key="EnableTrace" value="true" />
10+
<add key="EnableMetrics" value="false" />
11+
<add key="EnableCompression" value="true" />
12+
<add key="EnableEncryption" value="true" />
13+
<add key="EnableChaos" value="false" />
14+
</appSettings>
15+
<runtime>
16+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
17+
<dependentAssembly>
18+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
19+
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
20+
</dependentAssembly>
21+
<dependentAssembly>
22+
<assemblyIdentity name="Microsoft.Extensions.Options" publicKeyToken="adb9793829ddae60" culture="neutral" />
23+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
24+
</dependentAssembly>
25+
<dependentAssembly>
26+
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" />
27+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.1" newVersion="5.0.0.1" />
28+
</dependentAssembly>
29+
<dependentAssembly>
30+
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
31+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
32+
</dependentAssembly>
33+
<dependentAssembly>
34+
<assemblyIdentity name="Microsoft.Extensions.Configuration" publicKeyToken="adb9793829ddae60" culture="neutral" />
35+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
36+
</dependentAssembly>
37+
<dependentAssembly>
38+
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
39+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
40+
</dependentAssembly>
41+
<dependentAssembly>
42+
<assemblyIdentity name="App.Metrics.Concurrency" publicKeyToken="0d5193a913d1b812" culture="neutral" />
43+
<bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
44+
</dependentAssembly>
45+
<dependentAssembly>
46+
<assemblyIdentity name="Microsoft.Extensions.Configuration.EnvironmentVariables" publicKeyToken="adb9793829ddae60" culture="neutral" />
47+
<bindingRedirect oldVersion="0.0.0.0-3.1.6.0" newVersion="3.1.6.0" />
48+
</dependentAssembly>
49+
<dependentAssembly>
50+
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
51+
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
52+
</dependentAssembly>
53+
<dependentAssembly>
54+
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
55+
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
56+
</dependentAssembly>
57+
<dependentAssembly>
58+
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
59+
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
60+
</dependentAssembly>
61+
<dependentAssembly>
62+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
63+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
64+
</dependentAssembly>
65+
<dependentAssembly>
66+
<assemblyIdentity name="OpenTracing" publicKeyToken="61503406977abdaf" culture="neutral" />
67+
<bindingRedirect oldVersion="0.0.0.0-0.12.1.0" newVersion="0.12.1.0" />
68+
</dependentAssembly>
69+
<dependentAssembly>
70+
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
71+
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
72+
</dependentAssembly>
73+
<dependentAssembly>
74+
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
75+
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
76+
</dependentAssembly>
77+
<dependentAssembly>
78+
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
79+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.2" newVersion="5.0.0.2" />
80+
</dependentAssembly>
81+
<dependentAssembly>
82+
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
83+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
84+
</dependentAssembly>
85+
<dependentAssembly>
86+
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
87+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.1" newVersion="5.0.0.1" />
88+
</dependentAssembly>
89+
<dependentAssembly>
90+
<assemblyIdentity name="Microsoft.Extensions.Configuration.Binder" publicKeyToken="adb9793829ddae60" culture="neutral" />
91+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
92+
</dependentAssembly>
93+
<dependentAssembly>
94+
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
95+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
96+
</dependentAssembly>
97+
<dependentAssembly>
98+
<assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral" />
99+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
100+
</dependentAssembly>
101+
<dependentAssembly>
102+
<assemblyIdentity name="Microsoft.Extensions.Logging.Configuration" publicKeyToken="adb9793829ddae60" culture="neutral" />
103+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
104+
</dependentAssembly>
105+
</assemblyBinding>
106+
<dependentAssembly>
107+
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
108+
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
109+
</dependentAssembly>
110+
<dependentAssembly>
111+
<assemblyIdentity name="Microsoft.Extensions.Configuration" publicKeyToken="adb9793829ddae60" culture="neutral" />
112+
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
113+
</dependentAssembly>
114+
<dependentAssembly>
115+
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
116+
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
117+
</dependentAssembly>
118+
</runtime>
119+
</configuration>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFrameworks>net6.0;net48</TargetFrameworks>
5+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
6+
</PropertyGroup>
7+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
8+
<DebugType>full</DebugType>
9+
</PropertyGroup>
10+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
11+
<DebugType>pdbonly</DebugType>
12+
</PropertyGroup>
13+
<ItemGroup>
14+
<PackageReference Include="App.Metrics.Extensions.Configuration" Version="4.3.0" />
15+
<PackageReference Include="App.Metrics.Reporting.InfluxDB" Version="4.3.0" />
16+
<PackageReference Include="DotNetWorkQueue" Version="0.7.1" />
17+
<PackageReference Include="DotNetWorkQueue.AppMetrics" Version="0.7.1" />
18+
<PackageReference Include="DotNetWorkQueue.Transport.LiteDb" Version="0.7.1" />
19+
<PackageReference Include="LiteDB" Version="5.0.17" />
20+
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
21+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
22+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
23+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
24+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
25+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
26+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
27+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
28+
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="8.0.0" />
29+
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="8.0.0" />
30+
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
31+
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
32+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
33+
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
34+
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
35+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
36+
<PackageReference Include="Microsoft.Extensions.Primitives" Version="8.0.0" />
37+
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" />
38+
<PackageReference Include="MsgPack.Cli" Version="1.0.1" />
39+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
40+
<PackageReference Include="OpenTelemetry" Version="1.6.0" />
41+
<PackageReference Include="OpenTelemetry.Api" Version="1.6.0" />
42+
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.6.0" />
43+
<PackageReference Include="Polly.Caching.Memory" Version="3.0.2" />
44+
<PackageReference Include="Serilog" Version="3.1.1" />
45+
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
46+
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
47+
<PackageReference Include="SimpleInjector" Version="5.4.2" />
48+
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
49+
<PackageReference Include="System.Buffers" Version="4.5.1" />
50+
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
51+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
52+
<PackageReference Include="System.IO" Version="4.3.0" />
53+
<PackageReference Include="System.Memory" Version="4.5.5" />
54+
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
55+
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
56+
<PackageReference Include="System.Runtime" Version="4.3.1" />
57+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
58+
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
59+
<PackageReference Include="System.Security.Cryptography.Encoding" Version="4.3.0" />
60+
<PackageReference Include="System.Security.Cryptography.Primitives" Version="4.3.0" />
61+
<PackageReference Include="System.Text.Encodings.Web" Version="8.0.0" />
62+
<PackageReference Include="System.Text.Json" Version="8.0.0" />
63+
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
64+
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
65+
</ItemGroup>
66+
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
67+
<Reference Include="DotNetWorkQueue">
68+
<HintPath>..\..\..\DotNetWorkQueue\bin\Debug\net48\DotNetWorkQueue.dll</HintPath>
69+
</Reference>
70+
<Reference Include="DotNetWorkQueue.AppMetrics">
71+
<HintPath>..\..\..\DotNetWorkQueue.AppMetrics\bin\Debug\net48\DotNetWorkQueue.AppMetrics.dll</HintPath>
72+
</Reference>
73+
<Reference Include="DotNetWorkQueue.Transport.LiteDb">
74+
<HintPath>..\..\..\DotNetWorkQueue.Transport.LiteDB\bin\Debug\net48\DotNetWorkQueue.Transport.LiteDb.dll</HintPath>
75+
</Reference>
76+
<Reference Include="DotNetWorkQueue.Transport.Shared">
77+
<HintPath>..\..\..\DotNetWorkQueue.Transport.Shared\bin\Debug\net48\DotNetWorkQueue.Transport.Shared.dll</HintPath>
78+
</Reference>
79+
<Reference Include="SampleShared">
80+
<HintPath>..\..\SampleShared\bin\Debug\net48\SampleShared.dll</HintPath>
81+
</Reference>
82+
<Reference Include="System.ComponentModel.Composition" />
83+
<Reference Include="System.ComponentModel.DataAnnotations" />
84+
<Reference Include="System.Configuration" />
85+
<Reference Include="System.Runtime.Remoting" />
86+
<Reference Include="System.Data.DataSetExtensions" />
87+
</ItemGroup>
88+
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
89+
<Reference Include="DotNetWorkQueue">
90+
<HintPath>..\..\..\DotNetWorkQueue\bin\Debug\net6.0\DotNetWorkQueue.dll</HintPath>
91+
</Reference>
92+
<Reference Include="DotNetWorkQueue.AppMetrics">
93+
<HintPath>..\..\..\DotNetWorkQueue.AppMetrics\bin\Debug\net6.0\DotNetWorkQueue.AppMetrics.dll</HintPath>
94+
</Reference>
95+
<Reference Include="DotNetWorkQueue.Transport.LiteDb">
96+
<HintPath>..\..\..\DotNetWorkQueue.Transport.LiteDB\bin\Debug\net6.0\DotNetWorkQueue.Transport.LiteDb.dll</HintPath>
97+
</Reference>
98+
<Reference Include="DotNetWorkQueue.Transport.Shared">
99+
<HintPath>..\..\..\DotNetWorkQueue.Transport.Shared\bin\Debug\net6.0\DotNetWorkQueue.Transport.Shared.dll</HintPath>
100+
</Reference>
101+
<Reference Include="SampleShared">
102+
<HintPath>..\..\SampleShared\bin\Debug\net6.0\SampleShared.dll</HintPath>
103+
</Reference>
104+
</ItemGroup>
105+
<ItemGroup>
106+
<None Include="metricsettings.json">
107+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
108+
</None>
109+
<None Include="tracesettings.json">
110+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
111+
</None>
112+
</ItemGroup>
113+
</Project>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using DotNetWorkQueue;
2+
using DotNetWorkQueue.Configuration;
3+
using DotNetWorkQueue.Transport.LiteDb.Basic;
4+
using SampleShared;
5+
using Serilog;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Configuration;
9+
using System.IO;
10+
11+
namespace LiteDbConsumer
12+
{
13+
class Program
14+
{
15+
static void Main(string[] args)
16+
{
17+
//we are using serilog for sample purposes
18+
var log = new LoggerConfiguration()
19+
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}")
20+
.MinimumLevel.Debug()
21+
.CreateLogger();
22+
Log.Logger = log;
23+
log.Information("Startup");
24+
log.Information(SharedConfiguration.AllSettings);
25+
26+
//verify that the queue exists
27+
var fileLocation = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents");
28+
var queueName = ConfigurationManager.AppSettings.ReadSetting("QueueName");
29+
var connectionString = $"Filename={fileLocation}{ConfigurationManager.AppSettings.ReadSetting("Database")};Connection=shared;";
30+
var queueConnection = new QueueConnection(queueName, connectionString);
31+
using (var createQueueContainer = new QueueCreationContainer<LiteDbMessageQueueInit>(serviceRegister =>
32+
Injectors.AddInjectors(Helpers.CreateForSerilog(), SharedConfiguration.EnableTrace, SharedConfiguration.EnableMetrics, SharedConfiguration.EnableCompression, SharedConfiguration.EnableEncryption, "SQLiteConsumer", serviceRegister)
33+
, options => Injectors.SetOptions(options, SharedConfiguration.EnableChaos)))
34+
{
35+
using (var createQueue =
36+
createQueueContainer.GetQueueCreation<LiteDbMessageQueueCreation>(queueConnection))
37+
{
38+
if (!createQueue.QueueExists)
39+
{
40+
//the consumer can't do anything if the queue hasn't been created
41+
Log.Error($"Could not find {connectionString}. Verify that you have run the producer, which will create the queue");
42+
return;
43+
}
44+
}
45+
}
46+
47+
using (var queueContainer = new QueueContainer<LiteDbMessageQueueInit>(serviceRegister =>
48+
Injectors.AddInjectors(Helpers.CreateForSerilog(), SharedConfiguration.EnableTrace, SharedConfiguration.EnableMetrics, SharedConfiguration.EnableCompression, SharedConfiguration.EnableEncryption, "LiteDbConsumer", serviceRegister),
49+
options => Injectors.SetOptions(options, SharedConfiguration.EnableChaos)))
50+
{
51+
using (var queue = queueContainer.CreateConsumer(queueConnection))
52+
{
53+
//set some processing options and start looking for work
54+
queue.Configuration.Worker.WorkerCount = 4; //lets run 4 worker threads
55+
queue.Configuration.HeartBeat.UpdateTime = "sec(*%10)"; //set a heartbeat every 10 seconds
56+
queue.Configuration.HeartBeat.MonitorTime = TimeSpan.FromSeconds(15); //check for dead records every 15 seconds
57+
queue.Configuration.HeartBeat.Time = TimeSpan.FromSeconds(35); //records with no heartbeat after 35 seconds are considered dead
58+
59+
//an invalid data exception will be re-tried 3 times, with delays of 3, 6 and then finally 9 seconds
60+
queue.Configuration.TransportConfiguration.RetryDelayBehavior.Add(typeof(InvalidDataException), new List<TimeSpan> { TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(6), TimeSpan.FromSeconds(9) });
61+
62+
queue.Configuration.MessageExpiration.Enabled = true;
63+
queue.Configuration.MessageExpiration.MonitorTime = TimeSpan.FromSeconds(20); //check for expired messages every 20 seconds
64+
queue.Start<SimpleMessage>(MessageProcessing.HandleMessages);
65+
Console.WriteLine("Processing messages - press any key to stop");
66+
Console.ReadKey((true));
67+
}
68+
}
69+
70+
//if jaeger is using udp, sometimes the messages get lost; there doesn't seem to be a flush() call ?
71+
if (SharedConfiguration.EnableTrace)
72+
System.Threading.Thread.Sleep(2000);
73+
}
74+
}
75+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"MetricsOptions": {
3+
"DefaultContextLabel": "workqueuesamples",
4+
"Enabled": true,
5+
"ReportingEnabled": true
6+
},
7+
"MetricsReportingInfluxDbOptions": {
8+
"InfluxDb": {
9+
"BaseUri": "http://192.168.0.36:8086",
10+
"Database": "dotnetworkqueue-samples",
11+
"CreateDataBaseIfNotExists": true
12+
}
13+
}
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"Jaeger": {
3+
"JAEGER_SERVICE_NAME": "dotnetworkqueue-LiteDb-sample",
4+
"JAEGER_AGENT_HOST": "192.168.0.2",
5+
"JAEGER_AGENT_PORT": "6831"
6+
},
7+
}

0 commit comments

Comments
 (0)