Beispiel #1
0
        private static void Main(string[] args)
        {
            HorseMq mq = HorseMqBuilder.Create()
                         .AddClientHandler <ClientHandler>()
                         .AddQueueEventHandler <QueueEventHandler>()
                         .UseJustAllowDeliveryHandler()
                         .Build();

            var sampleMessageRouter        = mq.AddRouter("SAMPLE-MESSAGE-ROUTER", RouteMethod.Distribute);
            var sampleMessageQueueBinding  = new QueueBinding("sample-message-queue-binding", "SAMPLE-MESSAGE-QUEUE", 1, BindingInteraction.Response);
            var sampleMessageDirectBinding = new DirectBinding("sample-message-direct-binding", "@type:SAMPLE-MESSAGE-CONSUMER", 2, BindingInteraction.Response, RouteMethod.RoundRobin);

            sampleMessageRouter.AddBinding(sampleMessageQueueBinding);
            sampleMessageRouter.AddBinding(sampleMessageDirectBinding);

            var giveMeGuidRequestRouter  = mq.AddRouter("GIVE-ME-REQUEST-ROUTER", RouteMethod.Distribute);
            var giveMeGuidRequestHandler = new DirectBinding("sample-message-direct-binding", "@name:GIVE-ME-GUID-REQUEST-HANDLER-CONSUMER", 2, BindingInteraction.Response);

            giveMeGuidRequestRouter.AddBinding(giveMeGuidRequestHandler);

            HorseServer server = new HorseServer();

            server.UseHorseMq(mq);
            server.Run(15500);
        }
Beispiel #2
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));
        }