Exemple #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);
            }
        }
Exemple #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);
        }
Exemple #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();
        }
Exemple #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);
        }
Exemple #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}");
     }
 }
Exemple #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);
            }
        }
Exemple #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);
        }
Exemple #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);
            }
        }