Sending data to Azure EventHubs
I've been doing some experimenting with Azure EventHubs recently.
Event Hubs are a new way of logging events to temporary(ish) storage so that they can be consumed by other Azure services, like Stream Analytics. The main positive for me is it has much better performance characteristics than table storage.
Here's a snippet to illustrate sending a piece of data to an event hub.
using NewtonSoft.Json;
using Microsoft.ServiceBus.Messaging;
...
// Connection data taken from the Azure portal
const string endpoint = "sb://my-environment.servicebus.windows.net/";
const string eventHubName = "my-event-hub";
const string SAKName = "MyEventHub";
const string SAKSecret = "ThisIsNotAKey=";
string connectionString = string.Format("Endpoint={0};SharedAccessKeyName={1};SharedAccessKey={2}",
SAKName,
SAKSecret,
endpoint);
var client = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);
var message = new ApplicationSpecificEvent
{
Value = thisIsMyValue,
Timestamp = DateTime.UtcNow
};
string json = JsonConvert.SerializeObject(message);
client.Send(new EventData(Encoding.Default.GetBytes(json)));