本文整理汇总了C#中PartitionContext.CheckpointAsync方法的典型用法代码示例。如果您正苦于以下问题:C# PartitionContext.CheckpointAsync方法的具体用法?C# PartitionContext.CheckpointAsync怎么用?C# PartitionContext.CheckpointAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PartitionContext
的用法示例。
在下文中一共展示了PartitionContext.CheckpointAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessEventsAsync
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
var batch = new TableBatchOperation();
foreach(var msg in messages)
{
var snap = JsonConvert.DeserializeObject<BusSnapshotInfo>(Encoding.UTF8.GetString(msg.GetBytes()));
var entity = new DynamicTableEntity(snap.RouteShortName, snap.VehicleId.ToString());
entity.Properties.Add("RouteShortName", EntityProperty.GeneratePropertyForString(snap.RouteShortName));
entity.Properties.Add("VehicleId", EntityProperty.GeneratePropertyForInt(snap.VehicleId));
entity.Properties.Add("TripId", EntityProperty.GeneratePropertyForInt(snap.TripId));
entity.Properties.Add("Latitude", EntityProperty.GeneratePropertyForDouble(snap.Latitude));
entity.Properties.Add("Longitude", EntityProperty.GeneratePropertyForDouble(snap.Longitude));
entity.Properties.Add("DirectionOfTravel", EntityProperty.GeneratePropertyForString(snap.DirectionOfTravel.ToString()));
entity.Properties.Add("NextStopId", EntityProperty.GeneratePropertyForInt(snap.NextStopId));
entity.Properties.Add("Timeliness", EntityProperty.GeneratePropertyForString(snap.Timeliness.ToString()));
entity.Properties.Add("TimelinessOffset", EntityProperty.GeneratePropertyForInt(snap.TimelinessOffset));
entity.Properties.Add("Timestamp", EntityProperty.GeneratePropertyForDateTimeOffset(snap.Timestamp));
batch.Add(TableOperation.InsertOrReplace(entity));
}
var tableClient = _account.CreateCloudTableClient();
var table = tableClient.GetTableReference("snapshots");
await table.CreateIfNotExistsAsync();
await table.ExecuteBatchAsync(batch);
await context.CheckpointAsync();
}
示例2: foreach
async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
var partitionedMessages = messages.GroupBy(data => data.PartitionKey).ToDictionary(datas => datas.Key, datas => datas.ToList());
//For each partition spawn a Task which will sequentially iterate over its own block
//Wait for all Tasks to complete, before proceeding.
await Task.WhenAll(partitionedMessages.Select(partition => Task.Run(async () =>
{
var block = partition.Value;
foreach (var eventData in block)
{
try
{
var data = Encoding.UTF8.GetString(eventData.GetBytes());
System.Console.WriteLine(DateTime.Now + ":Message received. Partition: '{0}', Data: '{1}', Partition Key: '{2}'", context.Lease.PartitionId, data, eventData.PartitionKey);
}
catch (Exception e)
{
//do something with your logs..
}
}
})));
//Call checkpoint every 5 minutes, so that worker can resume processing from the 5 minutes back if it restarts.
if (checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
{
await context.CheckpointAsync();
checkpointStopWatch.Restart();
}
}
示例3: ProcessEventsAsync
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> events)
{
// Workaround for event hub sending null on timeout
events = events ?? Enumerable.Empty<EventData>();
foreach (var eventData in events)
{
var updateTemperatureEvent = JsonConvert.DeserializeObject<UpdateTemperatureEvent>(Encoding.UTF8.GetString(eventData.GetBytes()));
eventData.Properties["BuildingId"] = _buildingLookupService.GetBuildingId(updateTemperatureEvent.DeviceId);
}
if(!await _elasticSearchWriter.WriteAsync(events.ToList(), _token).ConfigureAwait(false))
{
return;
}
try
{
EventData checkpointEventData = events.LastOrDefault();
await context.CheckpointAsync(checkpointEventData);
WarmStorageEventSource.Log.CheckpointCompleted(ProcessorName, _eventHubName, context.Lease.PartitionId, checkpointEventData.Offset);
}
catch (Exception ex)
{
if (!(ex is StorageException || ex is LeaseLostException))
{
throw;
}
WarmStorageEventSource.Log.UnableToCheckpoint(ex, ProcessorName, _eventHubName, context.Lease.PartitionId);
}
}
示例4:
async Task IEventProcessor.CloseAsync(PartitionContext context, CloseReason reason)
{
if (reason == CloseReason.Shutdown)
{
await context.CheckpointAsync();
}
}
示例5: ProcessEventsAsync
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
Trace.TraceInformation("\n");
Trace.TraceInformation("........ProcessEventsAsync........");
foreach (EventData eventData in messages)
{
try
{
string jsonString = Encoding.UTF8.GetString(eventData.GetBytes());
Trace.TraceInformation(string.Format("Message received at '{0}'. Partition: '{1}'",
eventData.EnqueuedTimeUtc.ToLocalTime(), this.partitionContext.Lease.PartitionId));
Trace.TraceInformation(string.Format("-->Raw Data: '{0}'", jsonString));
SensorEvent newSensorEvent = this.DeserializeEventData(jsonString);
Trace.TraceInformation(string.Format("-->Serialized Data: '{0}', '{1}', '{2}', '{3}', '{4}'",
newSensorEvent.timestart, newSensorEvent.dsplalert, newSensorEvent.alerttype, newSensorEvent.message, newSensorEvent.targetalarmdevice));
// Issuing alarm to device.
string commandParameterNew = "{\"Name\":\"AlarmThreshold\",\"Parameters\":{\"SensorId\":\"" + newSensorEvent.dsplalert + "\"}}";
Trace.TraceInformation("Issuing alarm to device: '{0}', from sensor: '{1}'", newSensorEvent.targetalarmdevice, newSensorEvent.dsplalert);
Trace.TraceInformation("New Command Parameter: '{0}'", commandParameterNew);
await WorkerRole.iotHubServiceClient.SendAsync(newSensorEvent.targetalarmdevice, new Microsoft.Azure.Devices.Message(Encoding.UTF8.GetBytes(commandParameterNew)));
}
catch (Exception ex)
{
Trace.TraceInformation("Error in ProssEventsAsync -- {0}\n", ex.Message);
}
}
await context.CheckpointAsync();
}
示例6: ProcessEventsAsync
public Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
try
{
foreach (EventData message in messages)
{
string contents = Encoding.UTF8.GetString(message.GetBytes());
Console.WriteLine(string.Format("SimpleEventProcessor: {0}", contents));
OnMessageReceived(this, new MessageReceivedEventArgs() { ReceivedOn = DateTimeOffset.UtcNow, Message = message });
}
if (this.checkpointStopWatch.Elapsed > TimeSpan.FromSeconds(2))
{
lock (this)
{
this.checkpointStopWatch.Reset();
return context.CheckpointAsync();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return Task.FromResult<object>(null);
}
示例7: ProcessEventsAsync
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> events)
{
// Workaround for event hub sending null on timeout
events = events ?? Enumerable.Empty<EventData>();
if(!await _elasticSearchWriter.WriteAsync(events.ToList(), _token).ConfigureAwait(false))
{
return;
}
try
{
EventData checkpointEventData = events.LastOrDefault();
await context.CheckpointAsync(checkpointEventData);
WarmStorageEventSource.Log.CheckpointCompleted(ProcessorName, _eventHubName, context.Lease.PartitionId, checkpointEventData.Offset);
}
catch (Exception ex)
{
if (!(ex is StorageException || ex is LeaseLostException))
{
throw;
}
WarmStorageEventSource.Log.UnableToCheckpoint(ex, ProcessorName, _eventHubName, context.Lease.PartitionId);
}
}
示例8: ProcessEventsAsync
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
foreach (EventData eventData in messages)
{
if (eventData.Properties.ContainsKey("time"))
{
if (eventData.Properties.ContainsKey("temp"))
Console.WriteLine(string.Format("time = {0}, temp = {1}", eventData.Properties["time"], eventData.Properties["temp"]));
if (eventData.Properties.ContainsKey("hmdt"))
Console.WriteLine(string.Format("time = {0}, hmdt = {1}", eventData.Properties["time"], eventData.Properties["hmdt"]));
if (eventData.Properties.ContainsKey("accx") &&
eventData.Properties.ContainsKey("accy") &&
eventData.Properties.ContainsKey("accz"))
Console.WriteLine(string.Format("time = {0}, accx = {1}, accy = {2}, accz = {3}", eventData.Properties["time"], eventData.Properties["accx"], eventData.Properties["accy"], eventData.Properties["accz"]));
if (eventData.Properties.ContainsKey("bpm"))
Console.WriteLine(string.Format("time = {0}, bpm = {1}", eventData.Properties["time"], eventData.Properties["bpm"]));
}
}
//Call checkpoint every 5 minutes, so that worker can resume processing from the 5 minutes back if it restarts.
//if (this.checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
if (this.checkpointStopWatch.Elapsed > TimeSpan.FromSeconds(30))
{
await context.CheckpointAsync();
this.checkpointStopWatch.Restart();
}
}
示例9: CloseAsync
public async Task CloseAsync(PartitionContext context, CloseReason reason)
{
if (reason == CloseReason.Shutdown)
{
await context.CheckpointAsync();
}
}
示例10: foreach
async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
foreach (EventData eventData in messages)
{
_Logger.LogInfo(string.Format("Event received from partition: {0} - {1}", context.Lease.PartitionId,eventData.PartitionKey));
try
{
var httpMessage = HttpMessage.Parse(eventData.GetBodyStream());
await _MessageContentProcessor.ProcessHttpMessage(httpMessage);
}
catch (Exception ex)
{
_Logger.LogError(ex.Message);
}
}
//Call checkpoint every 5 minutes, so that worker can resume processing from the 5 minutes back if it restarts.
if (this.checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
{
_Logger.LogInfo("Checkpointing");
await context.CheckpointAsync();
this.checkpointStopWatch.Restart();
}
}
示例11: ProcessEventsAsync
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> events)
{
try
{
Notifications notifications = new Notifications();
foreach (EventData eventData in events)
{
var dataString = Encoding.UTF8.GetString(eventData.GetBytes());
var newData = JsonConvert.DeserializeObject<MetricEvent>(dataString);
EventMessage message = GetMessage(newData.Type, dataString);
if (message == null)
message = newData.GetMessage();
notifications.Notify(message);
Console.WriteLine(string.Format("Message received.Partition:'{0}',{1},Device:'{2}'", this.partitionContext.Lease.PartitionId, newData.Type, newData.DeviceId));
}
//Call checkpoint every 5 minutes, so that worker can resume processing from the 5 minutes back if it restarts.
if (this.checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
{
await context.CheckpointAsync();
this.checkpointStopWatch.Restart();
}
}
catch (Exception exp)
{
Console.WriteLine("Error in processing: " + exp.Message);
}
}
示例12: DbService
async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
var iDbService = new DbService();
_client = iDbService.GetFirebaseClient();
foreach (EventData eventData in messages)
{
string data = Encoding.UTF8.GetString(eventData.GetBytes());
FirebaseResponse response = await _client.PushAsync("event", new EHdata
{
offset = eventData.Offset,
body = data,
partitionId = context.Lease.PartitionId
});
Console.WriteLine(String.Format("Message received. Partition: '{0}', Data: '{1}', Offset: '{2}'",
context.Lease.PartitionId, data, eventData.Offset));
}
//Call checkpoint every 5 minutes, so that worker can resume processing from the 5 minutes back if it restarts.
if (this.checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
{
Console.WriteLine(this.checkpointStopWatch.Elapsed);
await context.CheckpointAsync();
this.checkpointStopWatch.Restart();
}
}
示例13: CloseAsync
public async Task CloseAsync(PartitionContext context, CloseReason reason)
{
if (reason == CloseReason.Shutdown)
{
Clients.All.showMessageOnClient("XClose");
await context.CheckpointAsync();
}
}
示例14: CloseAsync
public async Task CloseAsync(PartitionContext context, CloseReason reason)
{
Console.WriteLine("Shutting Down Event Processor");
if (reason == CloseReason.Shutdown)
{
await context.CheckpointAsync();
}
}
示例15: CloseAsync
public async Task CloseAsync(PartitionContext context, CloseReason reason)
{
Console.WriteLine($"Processor Shutting Down. Partition '{context.Lease.PartitionId}', Reason: '{reason}'.");
if (reason == CloseReason.Shutdown)
{
await context.CheckpointAsync();
}
}