/// <summary>
        /// Initializes a new instance of the <see cref="QueueWrapper" /> class.
        /// </summary>
        /// <param name="queueEndpoint">The queue endpoint.</param>
        public QueueWrapper([NotNull] QueueEndpoint queueEndpoint)
        {
            var cloudStorageAccount = CloudStorageAccount.Parse(queueEndpoint.ConnectionString);
            var queueClient         = cloudStorageAccount.CreateCloudQueueClient();

            this.cloudQueue = queueClient.GetQueueReference(queueEndpoint.QueueName);
        }
Beispiel #2
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));
        }
Beispiel #3
0
        /// <summary>
        /// Run the program
        /// </summary>
        /// <param name="arg">Arg. totally ignored...</param>
        public static void Run(object arg)
        {
            Trace.MethodEnter();
            startupTimer.Dispose();

            Trace.Info("Starting intialization.");
            QueueManager.Intance.Initialize();

            Program.endpoint = new QueueEndpoint(new IPEndPoint(IPAddress.Any, 1024));

            Trace.Info("Initialization completed.");

            // Set the handle on completion
            startupHandle.Set();

            Trace.MethodLeave();
        }
Beispiel #4
0
        public async Task SubmitMessageAsync_WhenMessageSubmitted_ExpectOnTheQueue()
        {
            // Arrange
            var queueEndpoint = new QueueEndpoint
            {
                ConnectionString = StorageHelpers.ConnectionString,
                QueueName        = this.testQueueName
            };

            var queueWrapper = new QueueWrapper(queueEndpoint);

            var data = new TestEntity {
                Data = "Test"
            }.SerializeToVersionedMessage(SerializerType.ProtocolBuffers).SerializeToString();
            var cloudMessage = new CloudQueueMessage(data);

            // Act
            var stopwatch = Stopwatch.StartNew();
            await queueWrapper.SubmitMessageAsync(cloudMessage, CancellationToken.None).ConfigureAwait(false);

            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            var cloudQueueMessage = await StorageHelpers.GetQueueReference(this.testQueueName).GetMessageAsync().ConfigureAwait(false);

            Assert.That(cloudQueueMessage, Is.Not.Null);

            var testEntity = cloudQueueMessage
                             .AsString
                             .DeserializeToVersionedMessage(SerializerType.ProtocolBuffers)
                             .Data
                             .Deserialize <TestEntity>();

            Assert.That(testEntity, Is.Not.Null);
            Assert.That(testEntity.Data, Is.EqualTo("Test"));
        }
Beispiel #5
0
        public async Task SubmitMessagesAsync_WhenMessagesSubmitted_ExpectOnTheQueue()
        {
            // Arrange
            var queueEndpoint = new QueueEndpoint
            {
                ConnectionString = StorageHelpers.ConnectionString,
                QueueName        = this.testQueueName
            };

            var queueWrapper = new QueueWrapper(queueEndpoint);

            var data = new List <CloudQueueMessage>();

            for (var i = 0; i < 10; i++)
            {
                var testEntity = new TestEntity {
                    Data = $"Test{i}"
                }.SerializeToString();
                var queueMessage = new CloudQueueMessage(testEntity);
                data.Add(queueMessage);
            }

            // Act
            var stopwatch = Stopwatch.StartNew();
            await queueWrapper.SubmitMessagesAsync(data, CancellationToken.None).ConfigureAwait(false);

            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            var cloudQueueMessage = await StorageHelpers.GetQueueReference(this.testQueueName).GetMessagesAsync(10).ConfigureAwait(false);

            var list = cloudQueueMessage.ToList();

            Assert.That(list, Is.Not.Null);
            Assert.That(list.Count, Is.EqualTo(10));
        }