Beispiel #1
0
        protected override async Task <SessionWorkItem> OnFetchWorkItem(TimeSpan receiveTimeout)
        {
            IEnumerable <BrokeredMessage> newMessages = null;

            MessageSession session = await trackingQueueClient.AcceptMessageSessionAsync(receiveTimeout);

            if (session == null)
            {
                return(null);
            }

            newMessages = await Utils.ExecuteWithRetries(() => session.ReceiveBatchAsync(PrefetchCount),
                                                         session.SessionId, "Receive Tracking Message Batch",
                                                         MaxRetriesServiceBus,
                                                         IntervalBetweenRetriesSecs);

            TraceHelper.TraceSession(TraceEventType.Information, session.SessionId,
                                     GetFormattedLog(
                                         string.Format("{0} new messages to process: {1}",
                                                       newMessages.Count(),
                                                       string.Join(",", newMessages.Select(m => m.MessageId + " [" + m.SequenceNumber + "]")))));

            return(new SessionWorkItem {
                Session = session, Messages = newMessages
            });
        }
Beispiel #2
0
        public async Task Send()
        {
            await CreateResponseQueue();

            QueueClient sendClient     = QueueClient.CreateFromConnectionString(ConfigurationManager.AppSettings[Helpers.ConnectionStringKey], Helpers.BasicQueueName);
            QueueClient responseClient = QueueClient.CreateFromConnectionString(ConfigurationManager.AppSettings[Helpers.ConnectionStringKey], Helpers.ResponseQueue);

            byte[] messageData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Helpers.GetModels()));
            string sessionId   = Guid.NewGuid().ToString("N");

            BrokeredMessage message = new BrokeredMessage(new MemoryStream(messageData), true)
            {
                ContentType      = "application/json",
                Label            = "dynamic data",
                TimeToLive       = TimeSpan.FromMinutes(20),
                ReplyToSessionId = sessionId,
                ReplyTo          = Helpers.ResponseQueue
            };

            await sendClient.SendAsync(message);

            MessageSession messageSession = await responseClient.AcceptMessageSessionAsync(sessionId);

            BrokeredMessage responseMessage = await messageSession.ReceiveAsync();

            string responseMessageBody = responseMessage.GetBody <string>();

            Console.WriteLine($"Message response received: \n{responseMessageBody}");
        }
        async Task AcceptAndCompleteSessionsAsync(QueueClient queueClient, string sessionId, string messageId)
        {
            var sessionReceiver = await queueClient.AcceptMessageSessionAsync(sessionId);

            if (sessionId != null)
            {
                Assert.True(sessionReceiver.SessionId == sessionId);
            }

            var message = await sessionReceiver.ReceiveAsync();

            Assert.True(message.MessageId == messageId);
            TestUtility.Log($"Received Message: {message.MessageId} from Session: {sessionReceiver.SessionId}");

            await message.CompleteAsync();

            TestUtility.Log($"Completed Message: {message.MessageId} for Session: {sessionReceiver.SessionId}");

            await sessionReceiver.CloseAsync();
        }
Beispiel #4
0
        public async Task Receive()
        {
            QueueClient receiveClient = QueueClient.CreateFromConnectionString(ConfigurationManager.AppSettings[Helpers.ConnectionStringKey], Helpers.SessionQueueName);
            var         tcs           = new TaskCompletionSource <bool>();

            MessageSession messageSession = await receiveClient.AcceptMessageSessionAsync();

            OnMessageOptions options = new OnMessageOptions
            {
                AutoComplete       = false,
                MaxConcurrentCalls = 4
            };

            messageSession.OnMessageAsync(async message =>
            {
                await Helpers.PrintMessageInfo(message);
                await message.CompleteAsync();
            }, options);

            await Task.Delay(TimeSpan.FromMinutes(1));

            tcs.SetResult(true);
            await tcs.Task;
        }
 internal async Task <MessageSession> AcceptMessageSession(QueueClient client)
 {
     return(await client.AcceptMessageSessionAsync(_sessionWaitTime));
 }