Ejemplo n.º 1
0
        public static async Task <bool> TimeoutCommand(this IMessageSession ctx, ICommand command, TimeSpan timeout)
        {
            if (string.IsNullOrEmpty(Configuration.Settings.CommandDestination))
            {
                throw new ArgumentException($"Must use Configuration.SetCommandDestination to use destination-less extension methods");
            }

            var options = new SendOptions();

            options.SetDestination(Configuration.Settings.CommandDestination);
            options.SetHeader(Defaults.RequestResponse, "1");

            var cancelation = new CancellationTokenSource(timeout);

            try
            {
                var response = await ctx.Request <IMessage>(command, options, cancelation.Token).ConfigureAwait(false);

                CheckResponse(command, response);
                return(true);
            }
            catch (TaskCanceledException)
            {
                Logger.WarnEvent("TimeOut", "{CommandType}", command.GetType().FullName);
                return(false);
            }
        }
Ejemplo n.º 2
0
        public static async Task PassiveCommand(this IMessageSession ctx, ICommand command)
        {
            var options = new SendOptions();

            options.SetHeader(Defaults.RequestResponse, "0");

            await ctx.Send(command, options).ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        public static async Task Command(this IMessageSession ctx, ICommand command)
        {
            var options = new SendOptions();

            options.SetHeader(Defaults.RequestResponse, "1");

            var response = await ctx.Request <IMessage>(command, options).ConfigureAwait(false);

            response.CommandResponse();
        }
Ejemplo n.º 4
0
        public static async Task PassiveCommand(this IMessageHandlerContext ctx, ICommand command)
        {
            if (string.IsNullOrEmpty(Configuration.Settings.CommandDestination))
            {
                throw new ArgumentException($"Must use Configuration.SetCommandDestination to use destination-less extension methods");
            }

            var options = new SendOptions();

            options.SetDestination(Configuration.Settings.CommandDestination);
            options.SetHeader(Defaults.RequestResponse, "0");

            await ctx.Send(command, options).ConfigureAwait(false);
        }
Ejemplo n.º 5
0
 private static void CheckResponse(Aggregates.Messages.ICommand command, Aggregates.Messages.IMessage msg)
 {
     if (msg is Reject)
     {
         var reject = (Reject)msg;
         Log.Logger.WarnEvent("Rejection", $"Command was rejected - Message: {reject.Message}");
         throw new RejectedException(command.GetType(), reject.Message, reject.Exception);
     }
     if (msg is Error)
     {
         var error = (Error)msg;
         Log.Logger.WarnEvent("Fault", $"Command Fault!\n{error.Message}");
         throw new RejectedException(command.GetType(), $"Command Fault!\n{error.Message}");
     }
 }
Ejemplo n.º 6
0
        public static async Task <bool> TimeoutCommand(this IMessageSession ctx, ICommand command, TimeSpan timeout)
        {
            var options = new SendOptions();

            options.SetHeader(Defaults.RequestResponse, "1");

            var cancelation = new CancellationTokenSource(timeout);

            try
            {
                var response = await ctx.Request <IMessage>(command, options, cancelation.Token).ConfigureAwait(false);

                response.CommandResponse();
                return(true);
            }
            catch (TaskCanceledException)
            {
                Logger.Warn($"Command {command.GetType().FullName} timed out");
                return(false);
            }
        }
Ejemplo n.º 7
0
        public static async Task PassiveCommand(this IMessageHandlerContext ctx, string destination, ICommand command)
        {
            var options = new SendOptions();

            options.SetDestination(destination);
            options.SetHeader(Defaults.RequestResponse, "0");

            await ctx.Send(command, options).ConfigureAwait(false);
        }
Ejemplo n.º 8
0
        public static async Task <bool> TimeoutCommand(this IMessageSession ctx, string destination, ICommand command, TimeSpan timeout)
        {
            var options = new SendOptions();

            options.SetDestination(destination);
            options.SetHeader(Defaults.RequestResponse, "1");

            var cancelation = new CancellationTokenSource(timeout);

            try
            {
                var response = await ctx.Request <IMessage>(command, options, cancelation.Token).ConfigureAwait(false);

                CheckResponse(command, response);
                return(true);
            }
            catch (TaskCanceledException)
            {
                Logger.WarnEvent("TimeOut", "{CommandType}", command.GetType().FullName);
                return(false);
            }
        }