-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
36 lines (33 loc) · 1.17 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
using System;
using NATS.Client;
using System.Text;
using Newtonsoft.Json;
using nats_publish_user_info.Models;
namespace nats_publish_user_info
{
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();
// T:NATS.Client.NATSNoServersException:
// T:NATS.Client.NATSConnectionException:
int i = 0;
User u;
while (true) {// Publish requests to the given subject:
u = new User();
u.Id = i;
u.FirstName = "User" + i.ToString();
u.LastName = "Bingham";
u.Email = u.FirstName + "@gmail.com";
u.Created = DateTime.Now;
c.Publish("bingham.user.create", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(u)));
i++;
System.Threading.Thread.Sleep(new TimeSpan(0, 0, 5));
}
}
}
}