-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (30 loc) · 1.17 KB
/
Program.cs
File metadata and controls
41 lines (30 loc) · 1.17 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
35
36
37
38
39
40
41
using Cloudtoid.Interprocess;
namespace Publisher;
internal static partial class Program
{
internal static async Task Main()
{
// Set up an optional logger factory to redirect the traces to he console
using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
var logger = loggerFactory.CreateLogger("Publisher");
// Create the queue factory. If you are not interested in tracing the internals of
// the queue then don't pass in a loggerFactory
var factory = new QueueFactory(loggerFactory);
// Create a message queue publisher
var options = new QueueOptions(
queueName: "sample-queue",
capacity: 1024 * 1024);
using var publisher = factory.CreatePublisher(options);
// Enqueue messages
int i = 0;
while (true)
{
if (publisher.TryEnqueue([(byte)(i % 256)]))
LogEnqueue(logger, i++);
else
await Task.Delay(100);
}
}
[LoggerMessage(Level = LogLevel.Information, Message = "Enqueue #{i}")]
private static partial void LogEnqueue(ILogger logger, int i);
}