コード例 #1
0
ファイル: AzServiceBusConsumer.cs プロジェクト: suposk/CSRO
        public async Task Stop()
        {
            await _approvedAdoProjcetMessageReceiverClient?.CloseAsync();

            await _rejectedAdoProjcetMessageReceiverClient?.CloseAsync();

            //await _queueReceiverClient?.CloseAsync();
        }
コード例 #2
0
        private static async Task <T> GetMessageBodyAsync <T>(IReceiverClient client)
        {
            string body = null;

            client.RegisterMessageHandler(async(msg, token) =>
            {
                Message message = msg;

                if (message != null)
                {
                    body = Encoding.UTF8.GetString(message.Body);

                    if (body.Contains("spoiled", StringComparison.OrdinalIgnoreCase))
                    {
                        await client.DeadLetterAsync(msg.SystemProperties.LockToken);
                    }
                    else
                    {
                        await client.CompleteAsync(msg.SystemProperties.LockToken);
                    }
                }
            }, new MessageHandlerOptions(ExceptionReceivedHandler)
            {
                MaxConcurrentCalls = 1,
                AutoComplete       = false
            });

            await client.UnregisterMessageHandlerAsync(TimeSpan.FromMilliseconds(2000));

            await client.CloseAsync();

            if (body != null)
            {
                return(JsonSerializer.Deserialize <T>(body));
            }

            return(default);
コード例 #3
0
 public void Dispose()
 {
     _receiverClient.CloseAsync();
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: nickstaggs/ServiceBusCLI
        static string Read(IReceiverClient client, bool peek, int numMessages, int time)
        {
            System.Timers.Timer timer    = new System.Timers.Timer();
            System.Timers.Timer logTimer = new System.Timers.Timer()
            {
                Interval = 2000, AutoReset = true
            };

            client.PrefetchCount = numMessages;

            var  messages = new StringBuilder();
            int  n        = 0;
            bool isTimeUp = false;

            timer.Elapsed    += (object source, System.Timers.ElapsedEventArgs e) => { isTimeUp = true; };
            logTimer.Elapsed += (object source, System.Timers.ElapsedEventArgs e) => {
                if (Verbose)
                {
                    Console.WriteLine("Waiting for messages...");
                }
            };

            if (time >= 0)
            {
                timer.Interval = time * 1000;
                timer.Start();
            }

            logTimer.Start();

            var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
            {
                MaxConcurrentCalls = 1,
                AutoComplete       = false
            };

            try
            {
                client.RegisterMessageHandler(async(Message message, CancellationToken token) =>
                {
                    if (Verbose)
                    {
                        Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber}");
                    }

                    Console.WriteLine(Encoding.UTF8.GetString(message.Body));

                    messages.Append(Encoding.UTF8.GetString(message.Body));

                    if (!peek)
                    {
                        await client.CompleteAsync(message.SystemProperties.LockToken);
                    }

                    n++;
                }, messageHandlerOptions);

                while (n < numMessages && !isTimeUp)
                {
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Ooops, trying to read messages failed: {e}");
            }
            finally
            {
                client.CloseAsync();
                timer.Stop();
                logTimer.Stop();
            }

            return(messages.ToString());
        }
コード例 #5
0
 public async Task Stop()
 {
     await _wmOperationRequestMessageReceiverClient?.CloseAsync();
 }
コード例 #6
0
        public async Task CloseAsync()
        {
            await _onClose?.Invoke(_client);

            await _client.CloseAsync();
        }
コード例 #7
0
 public async ValueTask DisposeAsync()
 {
     await Task.WhenAll(_sender.CloseAsync(), _receiver.CloseAsync());
 }