var serviceProviderConfig = new Configuration(); EPServiceProvider epService = EPServiceProviderManager.GetProvider("MyEngine", serviceProviderConfig); // Define the query to detect patterns in the data stream var statement = "select * from TemperatureEvent.std:groupwin(deviceId).win:length_batch(10) where avg(temperature) > 100"; var epStatement = epService.EPAdministrator.CreateEPL(statement); // Add a listener to handle the results of the query epStatement.Events += (sender, args) => { Console.WriteLine($"Temperature anomaly detected for device {args.NewEvents[0]["deviceId"]}"); }; // Send data to the Esper engine for processing var eventData = new TemperatureEvent() { deviceId = "Device 1", temperature = 110 }; epService.EPRuntime.SendEvent(eventData);
var serviceProviderConfig = new Configuration(); EPServiceProvider epService = EPServiceProviderManager.GetProvider("MyEngine", serviceProviderConfig); // Define the query to join two data streams and detect complex relationships var statement = "select a.deviceId as device1, b.deviceId as device2 from TemperatureEvent.win:time(30 sec) a, TemperatureEvent.win:time(30 sec) b where a.temperature > b.temperature"; var epStatement = epService.EPAdministrator.CreateEPL(statement); // Add a listener to handle the results of the query epStatement.Events += (sender, args) => { Console.WriteLine($"High temperature detected for devices {args.NewEvents[0]["device1"]} and {args.NewEvents[0]["device2"]}"); }; // Send data to the Esper engine for processing var eventData1 = new TemperatureEvent() { deviceId = "Device 1", temperature = 110 }; var eventData2 = new TemperatureEvent() { deviceId = "Device 2", temperature = 100 }; epService.EPRuntime.SendEvent(eventData1); epService.EPRuntime.SendEvent(eventData2);In both examples, the Esper library is used to create an instance of the EPServiceProvider, define a query to process real-time data streams, add a listener to handle the query results, and send data to the Esper engine for processing. The Esper library is available as a NuGet package for C#.