Esempio n. 1
0
        private static void SetUpConsumers(SubscriberParams argOptions, MassTransit.RabbitMqTransport.IRabbitMqBusFactoryConfigurator sbc, MassTransit.RabbitMqTransport.IRabbitMqHost host)
        {
            //sbc.UseInMemoryScheduler();
            sbc.UseMessageScheduler(new Uri($"rabbitmq://{argOptions.Host}/quartz"));

            sbc.ReceiveEndpoint(argOptions.QueueName, ep =>
            {
                if (!argOptions.DisableQueue2LevelRetry)
                {
                    ep.UseScheduledRedelivery(r => r.Intervals(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(5)));
                }
                if (!argOptions.DisableQueueRetry)
                {
                    ep.UseMessageRetry(r => r.Immediate(2));
                }
                if (argOptions.QueueIsExclusive)
                {
                    ep.ExclusiveConsumer = argOptions.QueueIsExclusive;
                }
                if (!argOptions.DisableQueueOutbox)
                {
                    ep.UseInMemoryOutbox();
                }

                ep.Consumer <Consumers.NewDataAvailableConsumer>();
                ep.Consumer <Consumers.InitialProcessingCompletedConsumer>();
                ep.Consumer <Consumers.FinalProcessingCompletedConsumer>();
            });

            if (!argOptions.DisableNoteworthyQueue)
            {
                sbc.ReceiveEndpoint("noteworthy_queue", ep =>
                {
                    ep.Consumer <Consumers.SomethingNoteworthyHappenedConsumer>();
                });
            }

            if (!argOptions.DisableFaultQueue)
            {
                sbc.ReceiveEndpoint("fault_queue", ep =>
                {
                    // can also declare handlers and consumer with a lambda
                    ep.Handler <Fault <NewDataAvailable> >(context =>
                    {
                        var msg = context.Message;

                        return(Console.Out.WriteLineAsync($"{context.MessageId} - {context.ConversationId} - Fault<NewDataAvailable>: {msg.Message.Text}"));
                    });
                });
            }
        }
Esempio n. 2
0
 private static void DisplayParams(SubscriberParams parms)
 {
     Console.WriteLine($"  --host                    {parms.Host}");
     Console.WriteLine($"  --vhost                   {parms.VHost}");
     Console.WriteLine($"  --name                    {parms.Name}");
     Console.WriteLine($"  --username                {parms.Username}");
     Console.WriteLine($"  --password                {parms.Password}");
     Console.WriteLine($"  --queueName               {parms.QueueName}");
     Console.WriteLine($"  --disableQueueOutbox      {parms.DisableQueueOutbox}");
     Console.WriteLine($"  --queueIsExclusive        {parms.QueueIsExclusive}");
     Console.WriteLine($"  --disableQueueRetry       {parms.DisableQueueRetry}");
     Console.WriteLine($"  --disableQueue2LevelRetry {parms.DisableQueue2LevelRetry}");
     Console.WriteLine($"  --disableFaultQueue       {parms.DisableFaultQueue}");
     Console.WriteLine($"  --disableNoteworthyQueue  {parms.DisableNoteworthyQueue}");
     Console.WriteLine("---------------------------");
 }
Esempio n. 3
0
        public static (SubscriberParams Options, string Errors) ParseParams(string[] args)
        {
            try
            {
                var spar = new SubscriberParams();

                var ph = new ParamHelpers(args);

                var i = 0;
                while (i < args.Length)
                {
                    var arg      = args[i];
                    var lowerArg = args[i].ToLowerInvariant();

                    i += 1;

                    if (lowerArg == "--host")
                    {
                        ph.CheckArgs(arg, i, 1);
                        (i, spar.Host) = ph.ReadString(arg, i);
                    }
                    else if (lowerArg == "--vhost")
                    {
                        ph.CheckArgs(arg, i, 1);
                        (i, spar.VHost) = ph.ReadString(arg, i);
                    }
                    else if (lowerArg == "--name")
                    {
                        ph.CheckArgs(arg, i, 1);
                        (i, spar.Name) = ph.ReadString(arg, i);
                    }
                    else if (lowerArg == "--username")
                    {
                        ph.CheckArgs(arg, i, 1);
                        (i, spar.Username) = ph.ReadString(arg, i);
                    }
                    else if (lowerArg == "--password")
                    {
                        ph.CheckArgs(arg, i, 1);
                        (i, spar.Password) = ph.ReadString(arg, i);
                    }
                    else if (lowerArg == "--queuename")
                    {
                        ph.CheckArgs(arg, i, 1);
                        (i, spar.QueueName) = ph.ReadString(arg, i);
                    }
                    else if (lowerArg == "--disablequeueoutbox")
                    {
                        (i, spar.DisableQueueOutbox) = ph.SetSwitch(i);
                    }
                    else if (lowerArg == "--queueisexclusive")
                    {
                        (i, spar.QueueIsExclusive) = ph.SetSwitch(i);
                    }
                    else if (lowerArg == "--disablequeueretry")
                    {
                        (i, spar.DisableQueueRetry) = ph.SetSwitch(i);
                    }
                    else if (lowerArg == "--disablequeue2levelretry")
                    {
                        (i, spar.DisableQueue2LevelRetry) = ph.SetSwitch(i);
                    }
                    else if (lowerArg == "--disablefaultqueue")
                    {
                        (i, spar.DisableFaultQueue) = ph.SetSwitch(i);
                    }
                    else if (lowerArg == "--disablenoteworthyqueue")
                    {
                        (i, spar.DisableNoteworthyQueue) = ph.SetSwitch(i);
                    }
                    else
                    {
                        throw new ArgumentException($"Unknown argument '{arg}'");
                    }
                }

                return(spar, string.Empty);
            }
            catch (ArgumentException ex)
            {
                return(null, ex.Message);
            }
        }