示例#1
0
        /// <summary>
        /// Creates this instance.
        /// </summary>
        /// <param name="queueConfiguration">The queue configuration.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <returns>
        /// The <see cref="IQueue" />
        /// </returns>
        public static IQueue Create(
            QueueConfiguration queueConfiguration,
            ILoggerFactory loggerFactory = null)
        {
            var logger = loggerFactory ?? new LoggerFactory();

            var queueEndpoint = new QueueEndpoint
            {
                ConnectionString = queueConfiguration.QueueConnectionString,
                QueueName        = queueConfiguration.QueueName
            };

            var serializerSettings = new SerializerSettings
            {
                SerializerType = queueConfiguration.SerializerType
            };

            var batchSettings = new BatchSettings
            {
                MaxQueueMessagesPerSchedule = queueConfiguration.MaxQueueMessagesPerSchedule,
                MaxMessagesPerQueueMessage  = queueConfiguration.MaxMessagesPerQueueMessage
            };

            var scheduleSettings = new ScheduleSettings
            {
                ThrottleTime = queueConfiguration.ThrottleTime
            };

            var queueWrapper           = new QueueWrapper(queueEndpoint);
            var messageSerializer      = new MessageSerializer(serializerSettings);
            var queueMessageSerializer = new QueueMessageSerializer(batchSettings, messageSerializer);

            var buffer = new Buffer(logger, queueWrapper, queueMessageSerializer);

            var stopwatchFactory = new StopwatchFactory();
            var delayCalculator  = new DelayCalculator();
            var pumpProcessor    = new PumpProcessor(
                logger,
                buffer,
                stopwatchFactory,
                delayCalculator,
                scheduleSettings);

            var queuePump = new QueuePump(buffer, pumpProcessor);

            return(new Queue(queuePump));
        }
 static async Task MainAsync(string[] args)
 {
     try
     {
         config.Connectionstring(
             Environment.GetEnvironmentVariable("MessageHandler.AzureServiceBus.Connectionstring"));
         config.ChannelId("Console");
         config.DisruptorRingSize(1024);
         var pump = new QueuePump(settings);
         var messageReceiverSettings = new MessageReceiverSettings()
         {
             NumberOfReceivers = 5,
             BatchSize         = 100,
             ServerWaitTime    = TimeSpan.FromSeconds(1)
         };
         config.MessageReceiverSettings(messageReceiverSettings);
         config.RegisterMessagePump(pump);
         config.UseEventProcessingRuntime();
         Func <IProcessingContext, Task> pipeline = ctx => Task.CompletedTask;
         config.Pipeline(pipeline);
         Console.WriteLine("Press a key to start.");
         Console.ReadKey();
         bool YN = false;
         do
         {
             await SendMessage();
         } while (YN == false);
         Console.WriteLine("Messages sent.");
         Console.ReadKey();
         Console.WriteLine("Program finished.");
         Console.ReadKey();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         Console.ReadKey();
     }
 }
示例#3
0
        static async Task MainAsync(string[] args)
        {
            try
            {
                config.Connectionstring(
                    Environment.GetEnvironmentVariable("MessageHandler.AzureServiceBus.Connectionstring"));
                config.ChannelId("Console");
                config.DisruptorRingSize(1024);
                var pump = new QueuePump(settings);
                var messageReceiverSettings = new MessageReceiverSettings()
                {
                    NumberOfReceivers = 20,
                    BatchSize         = 1000,
                    ServerWaitTime    = TimeSpan.FromMilliseconds(100)
                };
                config.MessageReceiverSettings(messageReceiverSettings);
                config.RegisterMessagePump(pump);
                config.UseEventProcessingRuntime();
                int invocationCount = 0;
                Func <IProcessingContext, Task> pipeline = async ctx =>
                {
                    await Console.Out.WriteLineAsync(invocationCount ++ + " " + DateTime.Now.ToLongTimeString());
                };
                config.Pipeline(pipeline);
                var runtime = await HandlerRuntime.Create(config);

                await runtime.Start();

                Console.WriteLine("Press a key to stop.");
                Console.ReadKey();
                await runtime.Stop();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
            }
        }