Esempio n. 1
0
        public async Task <MessageFacade> PeekMessageAsync(string queueName)
        {
            MessageFacade toReturn = null;

            try
            {
                QueueClient queueClient = new QueueClient(this.ConnectionString, queueName);
                if (queueClient.Exists())
                {
                    PeekedMessage[] peekedMessage = await queueClient.PeekMessagesAsync(1);

                    if (peekedMessage != null && peekedMessage.ToList().Count == 1)
                    {
                        toReturn = new MessageFacade()
                        {
                            MessageId   = peekedMessage[0].MessageId,
                            MessageText = peekedMessage[0].MessageText
                        };
                    }
                }
            }
            catch (Exception ex)
            {
                this.ErrorMessage = ex.ToString();
            }
            return(toReturn);
        }
Esempio n. 2
0
        public async Task <MessageFacade> ReadMessageAsync(string queueName, int?dequeueTimeoutSeconds = 30)
        {
            MessageFacade toReturn = null;

            try
            {
                QueueClient queueClient = new QueueClient(this.ConnectionString, queueName);
                if (queueClient.Exists())
                {
                    QueueMessage[] retrievedMessage = await queueClient.ReceiveMessagesAsync(1, TimeSpan.FromSeconds((double)dequeueTimeoutSeconds));

                    if (retrievedMessage != null && retrievedMessage.ToList().Count == 1)
                    {
                        toReturn = new MessageFacade()
                        {
                            MessageId   = retrievedMessage[0].MessageId,
                            MessageText = retrievedMessage[0].MessageText,
                            PopReceipt  = retrievedMessage[0].PopReceipt
                        };
                    }
                }
            }
            catch (Exception ex)
            {
                this.ErrorMessage = ex.ToString();
            }
            return(toReturn);
        }
Esempio n. 3
0
        public MessageFacade CreateMessage(string queueName, string message)
        {
            MessageFacade toReturn = null;

            try
            {
                QueueClient queueClient = new QueueClient(this.ConnectionString, queueName);
                queueClient.CreateIfNotExists();
                var receipt = queueClient.SendMessage(message);
                toReturn = new MessageFacade()
                {
                    MessageId   = receipt.Value.MessageId,
                    MessageText = message,
                    PopReceipt  = receipt.Value.PopReceipt
                };
            }
            catch (Exception ex)
            {
                this.ErrorMessage = ex.ToString();
            }
            return(toReturn);
        }