Exemplo n.º 1
0
        /// <summary>
        /// Peek Event Handler
        /// </summary>
        private async Task MyPeekCompleted(object source,
                                           PeekCompletedEventArgs asyncResult, string ChannelToReturnTo, string channelPeeked)
        {
            ResultModel resultModel = new ResultModel();

            try
            {
                // Connect to the queue.
                System.Messaging.MessageQueue mq = (System.Messaging.MessageQueue)source;

                // End the asynchronous peek operation.
                System.Messaging.Message myMessage = mq.EndPeek(asyncResult.AsyncResult);
                resultModel.message = MessageConvert.ConvertFromSystemMessage(myMessage);
                resultModel.Result  = (int)ResultsEnum.Done;
                // Restart the asynchronous peek operation.
                Response response = await initiator.SendRequestAsync(new KubeMQ.SDK.csharp.CommandQuery.LowLevel.Request()
                {
                    Metadata    = "PeekOK",
                    Body        = Converter.ToByteArray(resultModel),
                    CacheKey    = "",
                    CacheTTL    = 0,
                    Channel     = ChannelToReturnTo,
                    ClientID    = clientID,
                    RequestType = RequestType.Query
                });
            }
            catch (Exception ex)
            {
                _logger.LogCritical(string.Format("Failed to peek path {0} on ex {1}", channelPeeked, ex.Message));
            }
        }
        /// <inheritdoc />
        public Message EndPeek(System.Messaging.MessageQueue messageQueue, IAsyncResult asyncResult)
        {
            try
            {
                return(messageQueue.EndPeek(asyncResult));
            }
            catch (Exception exception)
            {
                _logger.Debug(exception, "Error ending Peek on Message Queues");

                if (exception is MessageQueueException messageQueueException && messageQueueException.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
                {
                    return(null);
                }

                throw new MessageQueuePeekException("End", messageQueue, asyncResult, exception);
            }
        }