Configure the Azure Hub process data messages sent to the product
- Last UpdatedJul 24, 2022
- 1 minute read
An example of the message format for sending data from an Event Hub or IoT Hub can be found in the support article "Send events to and receive events from Azure Event Hubs - .NET (Azure.Messaging.EventHubs)" in Microsoft's documentation at Microsoft Documentation.
Messages sent from the Event Hub or IoT Hub to AVEVA Insight must have a specific format so AVEVA Insight can extract the relevant data.
Modify the message format described in the link above by following the snippet below.
Important: You must update private const string connectionString with your key and private const string eventHubName with your Event Hub or IoT Hub name.
Message format
{
"TagName": “<<tagname>>",
"EventTime": “<<time in UTC>>",
"Quality": “<<Good/Questionable/Bad>>",
"Value": “<<pv>>"
}
Example: C# code to generate messages
using System;
using System.Threading.Tasks;
using Azure.Messaging.EventHubs;
using Azure.Messaging.EventHubs.Producer;
using System.Text;
namespace EventHubToInsight
{
class Program
{
private const string connectionString = "<YOUR KEY>";
private const string eventHubName = "<YOUR HUB NAME>";
static async Task Main()
{
while (true)
{
await using (var producerClient = new EventHubProducerClient(connectionString, eventHubName))
{
var rand = new System.Random();
var insightMessage = new
{
TagName = "Random21",
EventTime = DateTime.UtcNow, // Time should always be in UTC
Quality = "Good", // Supported qualities are: Good, Questionable or Bad
Value = rand.NextDouble().ToString()
}
// Create a batch of events
using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
var msg = Newtonsoft.Json.JsonConvert.SerializeObject(insightMessage);
// Add events to the batch. An event is a represented by a collection of bytes and metadata.
eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes(msg)));
await producerClient.SendAsync(eventBatch);
}
System.Threading.Thread.Sleep(2000);
}
}
}
}