protected async Task <Task> ExecuteMessagesByDownStreamOperators(StreamMessage msg, IAsyncStream <StreamMessage> stream, IOperator op) { if (downStreamOperators.Count > 0) { int batchID = msg.BatchID; var targetKey = op.GetPrimaryKey(); try { msg.From = this.GetPrimaryKey(); //if is barrier message, set the message count if (msg.Value == Constants.Barrier_Value) { if (downStreamMessageCountMaps.ContainsKey(batchID)) { if (downStreamMessageCountMaps[batchID].ContainsKey(op.GetPrimaryKey())) { msg.Count = downStreamMessageCountMaps[batchID][op.GetPrimaryKey()]; } else { msg.Count = 0; } } else { msg.Count = 0; } } //if it is a normal message, increment the count map else if (msg.Value != Constants.System_Key) { if (!downStreamMessageCountMaps.ContainsKey(batchID)) { downStreamMessageCountMaps.Add(batchID, new Dictionary <Guid, int>()); } var key = op.GetPrimaryKey(); if (downStreamMessageCountMaps[batchID].ContainsKey(key)) { downStreamMessageCountMaps[batchID][key] = downStreamMessageCountMaps[batchID][key] + 1; } else { downStreamMessageCountMaps[batchID].Add(key, 1); } } op.ExecuteMessage(msg, stream); } catch (Exception e) { PrettyConsole.Line("Get Exception : " + e + "; Start Receovry"); topologyManager.ReplaceTheOldOperator(targetKey); } } return(Task.CompletedTask); }