コード例 #1
0
        private static async Task SendRequest()
        {
            var         semaphoreSlim = new SemaphoreSlim(0, 1);
            IBusControl bus           = null;

            await Task.Factory.StartNew(async() =>
            {
                var queueGuid           = Guid.NewGuid().ToString();
                var models              = new List <CorrelationResponseModel>();
                var correlationConsumer = new CorrelationConsumer(model =>
                {
                    Console.WriteLine($"added model with index: {model.ResponseIndex}");
                    models.Add(model);

                    if (models.Count == model.TotalCount)
                    {
                        Console.WriteLine("Got all models in list");
                        semaphoreSlim.Release();
                    }
                });

                bus = Bus.Factory.CreateUsingAzureServiceBus(cfg =>
                {
                    AzureServiceBusFactory.ConfigureHost(cfg);

                    cfg.ReceiveEndpoint(queueGuid, configurator =>
                    {
                        configurator.Consumer(() => correlationConsumer);
                    });
                });

                await bus.StartAsync();

                await QueuePublisher.StartCorrelation(queueGuid);

                // Do not stop bus here, otherwise the consumer does not receive notifications
                // await bus.StopAsync();
            }).ConfigureAwait(false);


            await semaphoreSlim.WaitAsync();

            await bus?.StopAsync();

            /*
             * var result = await RpcPublisher.SendToCoreRpcQueue(new StringIntRequestModel
             * {
             *  IntValue = _intValue++, StringValue = "FrameworkRpcCall"
             * });
             *
             * Console.WriteLine(
             *  $"{Environment.NewLine}string: {result.StringValue}, int: {result.IntValue}, date: {result.DateTime}{Environment.NewLine}");
             */
        }
コード例 #2
0
 public bool Stop(HostControl hostControl)
 {
     bus?.StopAsync(new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
     return(true);
 }
コード例 #3
0
ファイル: Shutdown_Specs.cs プロジェクト: zz110/MassTransit
        public async Task Should_complete_running_consumers_nicely()
        {
            TaskCompletionSource <PingMessage> consumerStarted = GetTask <PingMessage>();

            IBusControl bus = Bus.Factory.CreateUsingRabbitMq(x =>
            {
                IRabbitMqHost host = x.Host("localhost", "test", h =>
                {
                });

                x.ReceiveEndpoint(host, "input_queue", e =>
                {
                    e.PurgeOnStartup = true;

                    e.Handler <PingMessage>(async context =>
                    {
                        await Console.Out.WriteLineAsync("Starting handler");

                        consumerStarted.TrySetResult(context.Message);

                        for (var i = 0; i < 5; i++)
                        {
                            await Task.Delay(1000);

                            await Console.Out.WriteLineAsync("Handler processing");
                        }

                        await context.RespondAsync(new PongMessage(context.Message.CorrelationId));

                        await Console.Out.WriteLineAsync("Handler complete");
                    });
                });
            });

            await Console.Out.WriteLineAsync("Starting bus");

            await bus.StartAsync(TestCancellationToken);

            await Console.Out.WriteLineAsync("Bus started");

            try
            {
                await bus.Publish(new PingMessage(), x =>
                {
                    x.RequestId       = NewId.NextGuid();
                    x.ResponseAddress = bus.Address;
                });

                await consumerStarted.Task;

                await Console.Out.WriteLineAsync("Consumer Start Acknowledged");
            }
            finally
            {
                await Console.Out.WriteLineAsync("Stopping bus");

                await bus.StopAsync(TestCancellationToken);

                await Console.Out.WriteLineAsync("Bus stopped");
            }
        }
 public Task StopAsync(CancellationToken cancellationToken)
 {
     _logger.LogInformation("Stopping bus Order Services");
     return(_bus.StopAsync(cancellationToken));
 }
コード例 #5
0
 public async Task StopAsync(CancellationToken cancellationToken)
 {
     _logger.LogDebug("Stopping host");
     await _bus.StopAsync(cancellationToken).ConfigureAwait(false);
 }
コード例 #6
0
 public Task StopAsync(CancellationToken cancellationToken)
 {
     _timer?.Dispose();
     return(_busControl.StopAsync(cancellationToken));
 }
コード例 #7
0
 /// <summary>
 /// Stop a bus, throwing an exception if the bus does not stop.
 /// It is a wrapper of the async method `StopAsync`
 /// </summary>
 /// <param name="busControl">The bus handle</param>
 public static void Stop(this IBusControl busControl)
 {
     TaskUtil.Await(() => busControl.StopAsync());
 }
 public Task StopAsync(CancellationToken cancellationToken)
 {
     _logger.LogInformation("Bus is stopping...");
     return(_bus.StopAsync(cancellationToken));
 }
コード例 #9
0
 public override Task StopAsync(CancellationToken cancellationToken)
 {
     return(Task.WhenAll(base.StopAsync(cancellationToken), _bus.StopAsync()));
 }
コード例 #10
0
        /// <summary>
        /// Stop a bus, throwing an exception if the bus does not stop in the specified timeout
        /// </summary>
        /// <param name="bus">The bus handle</param>
        /// <param name="stopTimeout">The wait time before throwing an exception</param>
        public static async Task StopAsync(this IBusControl bus, TimeSpan stopTimeout)
        {
            using var cancellationTokenSource = new CancellationTokenSource(stopTimeout);

            await bus.StopAsync(cancellationTokenSource.Token).ConfigureAwait(false);
        }
コード例 #11
0
ファイル: MessageBus.cs プロジェクト: myarichuk/Samples.MSA
 public Task StopAsync(CancellationToken token = default) => _busControl.StopAsync(token);
コード例 #12
0
 public Task StopAsync(CancellationToken cancellationToken)
 {
     _log.LogInformation("Stopping bus...");
     return(_busControl.StopAsync(cancellationToken));
 }
コード例 #13
0
 public async Task StopAsync(CancellationToken cancellationToken)
 {
     await _bus.StopAsync(cancellationToken).ConfigureAwait(false);
 }
コード例 #14
0
        public async Task StopAsync(CancellationToken cancellationToken)
        {
            await _busControl.StopAsync(cancellationToken);

            _logger.LogInformation("Indexing service stopped");
        }
コード例 #15
0
 public Task StopAsync(TimeSpan stopTimeout)
 {
     return(busControl.StopAsync(stopTimeout));
 }
コード例 #16
0
        public async Task StopAsync(CancellationToken cancellationToken)
        {
            await _bus.StopAsync(cancellationToken).ConfigureAwait(false);

            _simplifiedBusCheck?.ReportBusStopped();
        }
コード例 #17
0
 public override Task StopAsync(CancellationToken cancellationToken)
 {
     Console.WriteLine("BusService stopped");
     return(_busControl.StopAsync(cancellationToken));
 }
コード例 #18
0
 public Task StopAsync(CancellationToken cancellationToken)
 {
     return(bus.StopAsync(cancellationToken));
 }
 public virtual Task StopAsync(CancellationToken token = default(CancellationToken))
 {
     return(_busControl.StopAsync(token));
 }
コード例 #20
0
 /// <inheritdoc />
 public override async Task StopAsync(CancellationToken cancellationToken)
 {
     await _busControl.StopAsync(cancellationToken);
 }
コード例 #21
0
ファイル: BusService.cs プロジェクト: lulzzz/masstransit-2
 public Task StopAsync(CancellationToken cancellationToken)
 {
     logger.LogInformation($"Bus parado às {DateTimeOffset.Now}");
     return(busControl.StopAsync(cancellationToken));
 }
コード例 #22
0
 public async Task StopAsync(CancellationToken cancellationToken)
 {
     //stop the bus
     await busControl.StopAsync(TimeSpan.FromSeconds(10));
 }
コード例 #23
0
 public async Task StopAsync(CancellationToken cancellationToken)
 {
     await _bus.StopAsync(cancellationToken);
 }
コード例 #24
0
ファイル: Worker.cs プロジェクト: DevWouter/MassTransitDemo
        public override async Task StopAsync(CancellationToken cancellationToken)
        {
            await _bus.StopAsync(cancellationToken);

            await base.StopAsync(cancellationToken);
        }
コード例 #25
0
 public async Task CloseAsync() => await _bus?.StopAsync();
コード例 #26
0
 public Task StopAsync(CancellationToken cancellationToken)
 {
     return(_busControl.StopAsync(cancellationToken));
 }
コード例 #27
0
        public async Task StopAsync(CancellationToken cancellationToken)
        {
            await _busControl.StopAsync(cancellationToken);

            _logger.LogInformation("发货 微服务已停止");
        }
コード例 #28
0
 public async Task StopAsync(CancellationToken cancellationToken)
 {
     await busControl.StopAsync(cancellationToken);
 }
コード例 #29
0
 public Task StopAsync(CancellationToken cancellationToken) => _busControl.StopAsync(cancellationToken);
コード例 #30
0
        public async Task SetupAzureServiceBusTestFixture()
        {
            _bus = CreateBus();

            _bus.ConnectReceiveEndpointObserver(new ReceiveEndpointObserver());

            _busHandle = await _bus.StartAsync();
            try
            {
                _busSendEndpoint = await _bus.GetSendEndpoint(_bus.Address);
                _busSendEndpoint.ConnectSendObserver(_sendObserver);

                _inputQueueSendEndpoint = await _bus.GetSendEndpoint(_inputQueueAddress);
                _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver);
            }
            catch (Exception)
            {
                try
                {
                    using (var tokenSource = new CancellationTokenSource(TestTimeout))
                    {
                        await _bus.StopAsync(tokenSource.Token);
                    }
                }
                finally
                {
                    _busHandle = null;
                    _bus = null;
                }

                throw;
            }
        }
コード例 #31
0
        public async Task StopAsync(CancellationToken cancellationToken)
        {
            await _busControl.StopAsync();

            _logger.LogInformation("Payment microservice stopped.");
        }