Exemple #1
0
        /// <summary>
        /// Creates new router
        /// </summary>
        private async Task CreateRouter(MqClient client, HorseMessage message)
        {
            IRouter found = _server.FindRouter(message.Target);

            if (found != null)
            {
                await client.SendAsync(message.CreateResponse(HorseResultCode.Ok));

                return;
            }

            string      methodHeader = message.FindHeader(HorseHeaders.ROUTE_METHOD);
            RouteMethod method       = RouteMethod.Distribute;

            if (!string.IsNullOrEmpty(methodHeader))
            {
                method = (RouteMethod)Convert.ToInt32(methodHeader);
            }

            //check create queue access
            foreach (IClientAuthorization authorization in _server.Authorizations)
            {
                bool grant = await authorization.CanCreateRouter(client, message.Target, method);

                if (!grant)
                {
                    await client.SendAsync(message.CreateResponse(HorseResultCode.Unauthorized));

                    return;
                }
            }

            _server.AddRouter(message.Target, method);
            await client.SendAsync(message.CreateResponse(HorseResultCode.Ok));
        }
Exemple #2
0
        public async Task Handle(MqClient client, HorseMessage message, bool fromNode)
        {
            IRouter router = _server.FindRouter(message.Target);

            if (router == null)
            {
                await SendResponse(RouterPublishResult.Disabled, client, message);

                return;
            }

            RouterPublishResult result = await router.Publish(client, message);

            await SendResponse(result, client, message);
        }