-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
49 lines (42 loc) · 1.78 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
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using NATS.Client;
using System.Text;
using Newtonsoft.Json;
using nats_subscribe_logging.Models;
namespace nats_subscribe_logging
{
class Program
{
static void Main(string[] args)
{
// Create a new connection factory to create
// a connection.
ConnectionFactory cf = new ConnectionFactory();
// Creates a live connection to the default
// NATS Server running locally
IConnection c = cf.CreateConnection();
// Setup an event handler to process incoming messages.
// An anonymous delegate function is used for brevity.
EventHandler<MsgHandlerEventArgs> h = (sender, natsargs) =>
{
// print the message
Console.WriteLine(Encoding.UTF8.GetString(natsargs.Message.Data));
// User u = JsonConvert.DeserializeObject<User>(Encoding.UTF8.GetString(natsargs.Message.Data));
// Here are some of the accessible properties from
// the message:
// args.Message.Data;
// args.Message.Reply;
// args.Message.Subject;
// args.Message.ArrivalSubcription.Subject;
// args.Message.ArrivalSubcription.QueuedMessageCount;
// args.Message.ArrivalSubcription.Queue;
// Unsubscribing from within the delegate function is supported.
//natsargs.Message.ArrivalSubcription.Unsubscribe();
};
// The simple way to create an asynchronous subscriber
// is to simply pass the event in. Messages will start
// arriving immediately.
IAsyncSubscription s = c.SubscribeAsync("bingham.>", h);
}
}
}