public override async Task <List <TransmissionPayload> > MessagesPull(int?count, int?wait, string mappingChannel = null) { var list = new List <TransmissionPayload>(); int countDown = count ?? 1; TransmissionPayload payload; Guid?batchId = null; if (BoundaryLoggingActive) { batchId = Collector?.BoundaryBatchPoll(count ?? -1, mPending.Count, mappingChannel ?? ChannelId, Priority); } while (countDown > 0 && mPending.TryDequeue(out payload)) { if (mappingChannel != null) { payload.Message.ChannelId = mappingChannel; } //Get the boundary logger to log the metadata. if (BoundaryLoggingActive) { Collector?.BoundaryLog(ChannelDirection.Incoming, payload, ChannelId, Priority, batchId: batchId); } list.Add(payload); countDown--; } return(list); }
/// <summary> /// This method pulls a set of messages from the fabric and unpacks them in to TransmissionPayload messages. /// </summary> /// <param name="count">The number of messages to pull.</param> /// <param name="wait">The maximum wait time.</param> /// <param name="mappingChannel">This is channel map name.</param> /// <returns>Returns a list of messages or null if the request times out.</returns> public override async Task <List <TransmissionPayload> > MessagesPull(int?count, int?wait, string mappingChannel = null) { List <TransmissionPayload> batch = null; Guid?batchId = null; try { var intBatch = (await MessageReceive(count, wait))?.ToList() ?? new List <M>(); if (BoundaryLoggingActive) { batchId = Collector?.BoundaryBatchPoll(count ?? -1, intBatch.Count, mappingChannel ?? ChannelId, Priority); } batch = intBatch.Select(m => TransmissionPayloadUnpack(m, Priority, mappingChannel, batchId)).ToList(); } catch (MessagingException dex) { //OK, something has gone wrong with the Azure fabric. LogException("Messaging Exception (Pull)", dex); //Let's reinitialise the client if (ClientReset == null) { throw; } ClientReset(dex); batch = batch ?? new List <TransmissionPayload>(); } catch (TimeoutException tex) { LogException("MessagesPull (Timeout)", tex); batch = batch ?? new List <TransmissionPayload>(); } LastTickCount = Environment.TickCount; return(batch); }