forked from cloudtoid/interprocess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
37 lines (27 loc) · 1.07 KB
/
Program.cs
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
using Cloudtoid.Interprocess;
using Microsoft.Extensions.Logging;
namespace Subscriber;
internal class Program
{
internal static void 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("Subscriber");
// 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 subscriber = factory.CreateSubscriber(options);
// Dequeue messages
var messageBuffer = new byte[1];
while (true)
{
if (subscriber.TryDequeue(messageBuffer, default, out var message))
logger.LogInformation("Dequeue #" + messageBuffer[0]);
}
}
}