Example #1
0
        public async Task <IActionResult> GetUploadedQueueAsync()
        {
            const string ENV_SERVICEBUS = "SKISB";
            const string QueueName      = "video-uploaded";

            Microsoft.Azure.ServiceBus.Core.MessageReceiver mr = new Microsoft.Azure.ServiceBus.Core.MessageReceiver(_config[ENV_SERVICEBUS], QueueName);
            var messages = await mr.PeekAsync(int.MaxValue);

            StringBuilder sb = new StringBuilder();

            if (messages.Count > 0)
            {
                foreach (var message in messages)
                {
                    sb.Append(Encoding.UTF8.GetString(message.Body));
                }
            }

            return(Content(sb.ToString()));
        }
        public async Task RunTest()
        {
            var senderCxn = new ServiceBusConnectionStringBuilder(targetNamespaceConnectionString)
            {
                EntityPath = targetQueue
            };
            var sendSideClient = new Microsoft.Azure.ServiceBus.Core.MessageSender(senderCxn);

            var receiverCxn = new ServiceBusConnectionStringBuilder(sourceNamespaceConnectionString)
            {
                EntityPath = sourceQueue
            };
            var receiveSideClient = new Microsoft.Azure.ServiceBus.Core.MessageReceiver(receiverCxn);

            var start = DateTime.UtcNow;

            var sw = new Stopwatch();

            sw.Start();
            var tracker = new ConcurrentDictionary <string, long>();

            Console.WriteLine("sending");
            List <Task> sendTasks = new List <Task>();

            for (int j = 0; j < 1000; j++)
            {
                string msgid = Guid.NewGuid().ToString();
                tracker[msgid] = sw.ElapsedTicks;
                var message = new Message(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
                message.MessageId = msgid;
                sendTasks.Add(sendSideClient.SendAsync(message));
            }

            await Task.WhenAll(sendTasks);

            ConcurrentBag <long> durations = new ConcurrentBag <long>();

            Console.Write("receiving: ");
            var receiveTask = Task.Run(async() =>
            {
                while (!tracker.IsEmpty)
                {
                    var message = await receiveSideClient.ReceiveAsync(100, TimeSpan.FromSeconds(30));
                    if (message != null)
                    {
                        foreach (var msg in message)
                        {
                            string msgid = msg.MessageId;
                            if (tracker.TryRemove(msgid, out var swval))
                            {
                                durations.Add(sw.ElapsedTicks - swval);
                            }
                            await receiveSideClient.CompleteAsync(msg.SystemProperties.LockToken);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            });

            await receiveTask;

            Console.WriteLine();
            Assert.True(tracker.IsEmpty, $"tracker is not empty: {tracker.Count}");

            Console.WriteLine(((double)durations.Sum() / (double)durations.Count) / TimeSpan.TicksPerMillisecond);
        }
Example #3
0
 public MessageProcessor(Microsoft.Azure.ServiceBus.Core.MessageReceiver messageReceiver, Microsoft.Azure.ServiceBus.MessageHandlerOptions messageOptions)
 {
 }