Ejemplo n.º 1
0
        private async Task <byte[]> HandleSubscriptionRequestsAsync(
            IServiceRemotingRequestContext requestContext,
            ServiceRemotingMessageHeaders messageHeaders,
            byte[] requestMsgBodyBytes)
        {
            ActorMessageHeaders actorMessageHeaders;

            if (!ActorMessageHeaders.TryFromServiceMessageHeaders(messageHeaders, out actorMessageHeaders))
            {
                //This can only happen if there is issue in our product code like Message Corruption or changing headers format.
                ReleaseAssert.Failfast("ActorMessageHeaders Deserialization failed");
            }

            if (actorMessageHeaders.MethodId == ActorEventSubscription.SubscribeMethodId)
            {
                var requestMsgBody       = (ActorMessageBody)SerializationUtility.Deserialize(ActorEventSubscription.Serializer, requestMsgBodyBytes);
                var castedRequestMsgBody = (EventSubscriptionRequestBody)requestMsgBody.Value;

                await this.actorService.ActorManager.SubscribeAsync(
                    actorMessageHeaders.ActorId,
                    castedRequestMsgBody.eventInterfaceId,
                    new ActorEventSubscriberProxy(
                        castedRequestMsgBody.subscriptionId,
                        requestContext.GetCallbackClient()));

                return(null);
            }

            if (actorMessageHeaders.MethodId == ActorEventSubscription.UnSubscribeMethodId)
            {
                var requestMsgBody       = (ActorMessageBody)SerializationUtility.Deserialize(ActorEventSubscription.Serializer, requestMsgBodyBytes);
                var castedRequestMsgBody = (EventSubscriptionRequestBody)requestMsgBody.Value;

                await this.actorService.ActorManager.UnsubscribeAsync(
                    actorMessageHeaders.ActorId,
                    castedRequestMsgBody.eventInterfaceId,
                    castedRequestMsgBody.subscriptionId);

                return(null);
            }

            throw new MissingMethodException(string.Format(CultureInfo.CurrentCulture, Actors.SR.ErrorInvalidMethodId, actorMessageHeaders.MethodId));
        }
Ejemplo n.º 2
0
        private async Task <byte[]> HandleSubscriptionRequests(
            IServiceRemotingRequestContext requestContext,
            ServiceRemotingMessageHeaders messageHeaders,
            byte[] requestMsgBodyBytes)
        {
            ActorMessageHeaders actorMessageHeaders;

            if (!ActorMessageHeaders.TryFromServiceMessageHeaders(messageHeaders, out actorMessageHeaders))
            {
                throw new SerializationException(Actors.SR.ErrorActorMessageHeadersDeserializationFailed);
            }

            if (actorMessageHeaders.MethodId == ActorEventSubscription.SubscribeMethodId)
            {
                var requestMsgBody       = (ActorMessageBody)SerializationUtility.Deserialize(ActorEventSubscription.Serializer, requestMsgBodyBytes);
                var castedRequestMsgBody = (EventSubscriptionRequestBody)requestMsgBody.Value;

                await this.actorService.ActorManager.SubscribeAsync(
                    actorMessageHeaders.ActorId,
                    castedRequestMsgBody.eventInterfaceId,
                    new ActorEventSubscriberProxy(
                        castedRequestMsgBody.subscriptionId,
                        requestContext.GetCallbackClient()));

                return(null);
            }

            if (actorMessageHeaders.MethodId == ActorEventSubscription.UnSubscribeMethodId)
            {
                var requestMsgBody       = (ActorMessageBody)SerializationUtility.Deserialize(ActorEventSubscription.Serializer, requestMsgBodyBytes);
                var castedRequestMsgBody = (EventSubscriptionRequestBody)requestMsgBody.Value;

                await this.actorService.ActorManager.UnsubscribeAsync(
                    actorMessageHeaders.ActorId,
                    castedRequestMsgBody.eventInterfaceId,
                    castedRequestMsgBody.subscriptionId);

                return(null);
            }

            throw new MissingMethodException(string.Format(CultureInfo.CurrentCulture, Actors.SR.ErrorInvalidMethodId, actorMessageHeaders.MethodId));
        }