private static void Receive(IMessageSubscriber <SampleEvent> receiver)
        {
            var message = receiver.ReceiveAsAsync().Result;

            if (message == null)
            {
                WriteColoredLine("No messages waiting for processing", DetailsColor);
            }
            else
            {
                message.CompleteAsync();
                WriteColoredLine($"Received message with id {message.Content.Id} published at {message.Content.Timestamp}", DetailsColor);
            }
        }
示例#2
0
        private async Task <IMessage <T> > GetMessage(IMessageSubscriber <T> subscriber)
        {
            IMessage <T> message;

            try
            {
                // This could throw an exception because the connection failed to open or a message could not be retrieved from the connection. We can't tell which
                // so we'll assume it is because the connection failed to open and abandon.
                message = await subscriber.ReceiveAsAsync();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, $"Failed to retrieve message {typeof(T).FullName}");
                await OnFatalAsync(ex);

                throw;
            }

            return(message);
        }