private async Task handleMessage(IMessageSession session, Message message, CancellationToken token) { var lockToken = message.SystemProperties.LockToken; Envelope envelope; try { envelope = _protocol.ReadEnvelope(message); } catch (Exception e) { _logger.LogException(e, message: "Error trying to map an incoming Azure Service Bus message to an Envelope. See the Dead Letter Queue"); await session.DeadLetterAsync(lockToken, "Bad Envelope", e.ToString()); return; } try { await _callback.Received(Address, new[] { envelope }); await session.CompleteAsync(lockToken); } catch (Exception e) { _logger.LogException(e, envelope.Id, "Error trying to receive a message from " + Address); await session.AbandonAsync(lockToken); } }
private static async Task receive(Stream stream, IReceiverCallback callback, Envelope[] messages, Uri uri) { var status = callback.Received(uri, messages); switch (status) { case ReceivedStatus.ProcessFailure: await stream.SendBuffer(Constants.ProcessingFailureBuffer); break; case ReceivedStatus.QueueDoesNotExist: await stream.SendBuffer(Constants.QueueDoesNotExistBuffer); break; default: await stream.SendBuffer(Constants.ReceivedBuffer); var ack = await stream.ReadExpectedBuffer(Constants.AcknowledgedBuffer); if (ack) { callback.Acknowledged(messages); } else { callback.NotAcknowledged(messages); } break; } }
private static async Task receive(Stream stream, IReceiverCallback callback, Envelope[] messages, Uri uri) { // Just a ping if (messages.Any() && messages.First().IsPing()) { await stream.SendBuffer(ReceivedBuffer); // We aren't gonna use this in this case var ack = await stream.ReadExpectedBuffer(AcknowledgedBuffer); return; } var status = await callback.Received(uri, messages); switch (status) { case ReceivedStatus.ProcessFailure: await stream.SendBuffer(ProcessingFailureBuffer); break; case ReceivedStatus.QueueDoesNotExist: await stream.SendBuffer(QueueDoesNotExistBuffer); break; default: await stream.SendBuffer(ReceivedBuffer); var ack = await stream.ReadExpectedBuffer(AcknowledgedBuffer); if (ack) { await callback.Acknowledged(messages); } else { await callback.NotAcknowledged(messages); } break; } }