async Task ProcessEventHubEvent(EventData ev) { if ((DateTime.UtcNow - ev.EnqueuedTimeUtc).TotalDays > 1) { _logger.ReceivedExpiredMessage(ev.EnqueuedTimeUtc); return; } Message msg; if (_serializer.TryDeserialize(new ArraySegment <byte>(ev.GetBytes()), out msg)) { var actorHeader = msg.GetHeader <ActorTargetHeader>(); if (actorHeader != null) { _logger.ReceivedMessageForActor(actorHeader.ActorKey, msg); var actor = _actors.GetOrAdd(actorHeader.ActorKey.Id, SpawnActor); var opHeader = msg.GetHeader <OperationHeader>(); var actorReplyHeader = msg.GetHeader <ActorDirectReplyHeader>(); if (opHeader != null && opHeader.Type == OperationType.Request && actorReplyHeader != null) { var operationContext = new OperationContext(null, msg, opHeader.ActivityId); Message reply = null; try { reply = await actor.Process(operationContext); } catch (ProcessingException ex) { reply = new ErrorMessage(ex.ErrorCode, ex.Message); } if (reply != null) { if (actorReplyHeader.ActorRef.Location.Equals(_serverNode.Address)) { OnDirectReplyMessage(new OperationContext(null, reply, opHeader.ActivityId)); } else { try { INetChannel replyChannel = await _serverNode.Connect(actorReplyHeader.ActorRef.Location); replyChannel.Reply(operationContext, reply); } catch (Exception ex) { _logger.FailedToSendReply(actorHeader.ActorKey, msg, ex); } } } } else { var activityId = opHeader?.ActivityId ?? Guid.NewGuid(); try { await actor.Process(new OperationContext(null, msg, activityId)); } catch (ProcessingException ex) { //log and skip } } } else { _logger.ReceivedMessageWithoutActorHeader(_id, msg); } } else { _logger.FailedToDeserializeEvent(_id, ev.PartitionKey, ev.SequenceNumber, ev.Offset); } }