Last active
May 16, 2016 18:27
-
-
Save einari/4a6e53eca299f203ca7a3044a5d25cd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using System.Threading; | |
using Microsoft.ServiceBus.Messaging; | |
using Newtonsoft.Json; | |
namespace EventHubDataGenerator | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var offices = new string[] { | |
"Olivier's Office", | |
"Johns Office", | |
"Scotts Office", | |
"The Gus Office", | |
"Random Dudes Office" | |
}; | |
Console.WriteLine("Enter the EventHub ConnectionString for sending:"); | |
var connectionString = Console.ReadLine(); | |
var client = EventHubClient.CreateFromConnectionString(connectionString); | |
var rnd = new Random(); | |
for (;;) | |
{ | |
try | |
{ | |
var message = new | |
{ | |
hmdt = (rnd.NextDouble() * 20) + 80, | |
temp = (rnd.NextDouble() * 10) + 15, | |
lght = rnd.NextDouble(), | |
dspl = offices[rnd.Next(0,offices.Length-1)], | |
time = DateTime.UtcNow | |
}; | |
var messageAsString = JsonConvert.SerializeObject(message); | |
Console.WriteLine($"{DateTime.Now} > Sending Message : {messageAsString}"); | |
client.Send(new EventData(Encoding.UTF8.GetBytes(messageAsString))); | |
} | |
catch (Exception exception) | |
{ | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}"); | |
Console.ResetColor(); | |
} | |
Thread.Sleep(1000); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment