-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
75 lines (61 loc) · 2.14 KB
/
Program.cs
File metadata and controls
75 lines (61 loc) · 2.14 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Microsoft.Extensions.DependencyInjection;
using msgqNET;
using msgqNET.implementations.msgq.queues;
using msgqNET.interfaces;
using TestApp;
// Set up the dependency injection container
internal class Program
{
public static void Main(string endpoint = "backupManagerSP")
{
var serviceProvider = new ServiceCollection()
.AddSingleton<IEventProcessor, EventProcessor>()
.AddMessaging()
.BuildServiceProvider();
// Get the event processor from the service provider
var messagingFactory = serviceProvider.GetRequiredService<IMessagingFactory>();
var context = messagingFactory.CreateContext();
var subsocket = messagingFactory.CreateSubSocket(context, endpoint, "127.0.0.1");
subsocket.SetTimeout(TimeSpan.FromSeconds(30));
//
long counter = 0;
// Event processing loop
while (true)
{
Console.WriteLine($"Processing event {counter++}");
// pubsocket.SendMessage(new FakeMessage());
// await Task.Delay(1000); // Sleep for 1 second
var x = subsocket.Receive();
HexDumper.PrintHexDump(x?.GetData() ?? []);
Console.WriteLine();
Thread.Sleep(1);
}
// var pubsocket = messagingFactory.CreatePubSocket(context, "example-endpoint");
// var subsocket = messagingFactory.CreateSubSocket(context, "example-endpoint");
//
// var publisherTask = Task.Run(async () =>
// {
// long counter = 0;
// // Event processing loop
// while (true)
// {
// pubsocket.SendMessage(new ZmqMessage($"hello world [{counter++}]"));
// await Task.Delay(3000);
// }
// });
//
//
// subsocket.SetTimeout(TimeSpan.FromSeconds(5));
// while (true)
// {
// HexDumper.PrintHexDump(subsocket.Receive()?.GetData() ?? []);
// }
var pubqueue = new MessageQueuePublisher("backupManagerSP", 10486144);
var queue = new MessageQueueSubscriber("backupManagerSP", 10486144);
var queue2 = new MessageQueueSubscriber("backupManagerSP", 10486144);
// Perform operations...
pubqueue.Close();
queue.Close();
queue2.Close();
}
}