Example #1
0
 public void Execute()
 {
     TaskUtil.Await(ExecuteAsync);
 }
Example #2
0
 public void Dispose() => TaskUtil.Await(_harness.Stop);
Example #3
0
 public bool Stop(HostControl hostControl)
 {
     _logger.Info("Stopping bus...");
     TaskUtil.Await(() => _busControl.StopAsync(TimeSpan.FromSeconds(30)));
     return(true);
 }
Example #4
0
 /// <summary>
 /// Await a task in a test method that is not asynchronous, such as a test fixture setup
 /// </summary>
 /// <param name="taskFactory"></param>
 /// <param name="cancellationToken"></param>
 protected T Await <T>(Func <Task <T> > taskFactory, CancellationToken cancellationToken)
 {
     return(TaskUtil.Await(taskFactory, cancellationToken));
 }
Example #5
0
 /// <summary>
 /// Stop a bus, throwing an exception if the bus does not stop
 /// </summary>
 /// <param name="handle">The bus handle</param>
 public static void Stop(this BusHandle handle)
 {
     TaskUtil.Await(() => handle.StopAsync());
 }
Example #6
0
 /// <summary>
 /// Await a task in a test method that is not asynchronous, such as a test fixture setup
 /// </summary>
 /// <param name="taskFactory"></param>
 protected void Await(Func <Task> taskFactory)
 {
     TaskUtil.Await(taskFactory, CancellationToken.None);
 }
Example #7
0
 /// <summary>
 /// Await a task in a test method that is not asynchronous, such as a test fixture setup
 /// </summary>
 /// <param name="taskFactory"></param>
 /// <param name="cancellationToken"></param>
 protected void Await(Func <Task> taskFactory, CancellationToken cancellationToken)
 {
     TaskUtil.Await(taskFactory, cancellationToken);
 }
 public BusHandle Start()
 {
     return(TaskUtil.Await(() => _bus.StartAsync()));
 }
Example #9
0
        static void Main()
        {
            ConfigureLogger();

            // MassTransit to use Log4Net
            Log4NetLogger.Use();


            IBusControl busControl = CreateBus();

            TaskUtil.Await(() => busControl.StartAsync());

            string validateQueueName = ConfigurationManager.AppSettings["ValidateActivityQueue"];

            Uri validateAddress = _host.GetSendAddress(validateQueueName);

            string retrieveQueueName = ConfigurationManager.AppSettings["RetrieveActivityQueue"];

            Uri retrieveAddress = _host.GetSendAddress(retrieveQueueName);


            try
            {
                for (;;)
                {
                    Console.Write("Enter an address (quit exits): ");
                    string requestAddress = Console.ReadLine();
                    if (requestAddress == "quit")
                    {
                        break;
                    }

                    if (string.IsNullOrEmpty(requestAddress))
                    {
                        requestAddress = "http://www.microsoft.com/index.html";
                    }

                    int limit = 1;

                    if (requestAddress.All(x => char.IsDigit(x) || char.IsPunctuation(x)))
                    {
                        string[] values = requestAddress.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        requestAddress = values[0];
                        if (values.Length > 1)
                        {
                            limit = int.Parse(values[1]);
                            Console.WriteLine("Sending {0}", limit);
                        }
                    }

                    switch (requestAddress)
                    {
                    case "0":
                        requestAddress = "http://www.microsoft.com/index.html";
                        break;

                    case "1":
                        requestAddress = "http://i.imgur.com/Iroma7d.png";
                        break;

                    case "2":
                        requestAddress = "http://i.imgur.com/NK8eZUe.jpg";
                        break;
                    }

                    Uri requestUri;
                    try
                    {
                        requestUri = new Uri(requestAddress);
                    }
                    catch (UriFormatException)
                    {
                        Console.WriteLine("The URL entered is invalid: " + requestAddress);
                        continue;
                    }

                    IEnumerable <Task> tasks = Enumerable.Range(0, limit).Select(x => Task.Run(async() =>
                    {
                        var builder = new RoutingSlipBuilder(NewId.NextGuid());

                        builder.AddActivity("Validate", validateAddress);
                        builder.AddActivity("Retrieve", retrieveAddress);

                        builder.SetVariables(new
                        {
                            RequestId = NewId.NextGuid(),
                            Address   = requestUri,
                        });

                        RoutingSlip routingSlip = builder.Build();

                        await busControl.Publish <RoutingSlipCreated>(new
                        {
                            TrackingNumber = routingSlip.TrackingNumber,
                            Timestamp      = routingSlip.CreateTimestamp,
                        });

                        await busControl.Execute(routingSlip);
                    }));

                    Task.WaitAll(tasks.ToArray());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception!!! OMG!!! {0}", ex);
                Console.ReadLine();
            }
            finally
            {
                busControl.Stop();
            }
        }
 public void Kill()
 {
     TaskUtil.Await(() => SagaRepository.DeleteSaga(_correlationId));
 }
Example #11
0
 /// <summary>
 /// Starts a bus, throwing an exception if the bus does not start
 /// It is a wrapper of the async method `StartAsync`
 /// </summary>
 /// <param name="busControl">The bus handle</param>
 public static void Start(this IBusControl busControl)
 {
     TaskUtil.Await(() => busControl.StartAsync());
 }
Example #12
0
 /// <summary>
 /// Await a task in a test method that is not asynchronous, such as a test fixture setup
 /// </summary>
 /// <param name="taskFactory"></param>
 public T Await <T>(Func <Task <T> > taskFactory)
 {
     return(TaskUtil.Await(taskFactory, TestCancellationToken));
 }
Example #13
0
 BusHandle IBusControl.Start()
 {
     return(TaskUtil.Await(() => StartAsync(CancellationToken.None)));
 }
Example #14
0
        BusHandle IBusControl.Start()
        {
            if (_busHandle != null)
            {
                _log.Warn($"The bus was already started, additional Start attempts are ignored: {Address}");
                return(_busHandle);
            }

            TaskUtil.Await(() => _busObservable.PreStart(this));

            Exception exception = null;

            var endpoints = new List <ReceiveEndpointHandle>();
            var hosts     = new List <HostHandle>();
            var observers = new List <ConnectHandle>();
            var busReady  = new BusReady(_receiveEndpoints);

            try
            {
                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Starting bus hosts...");
                }

                foreach (IBusHostControl host in _hosts)
                {
                    try
                    {
                        HostHandle hostHandle = host.Start();

                        hosts.Add(hostHandle);
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                }

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Starting receive endpoints...");
                }

                foreach (IReceiveEndpoint endpoint in _receiveEndpoints)
                {
                    try
                    {
                        ConnectHandle observerHandle = endpoint.ConnectReceiveObserver(_receiveObservers);
                        observers.Add(observerHandle);

                        ReceiveEndpointHandle handle = endpoint.Start();

                        endpoints.Add(handle);
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (exception != null)
            {
                try
                {
                    var handle = new Handle(hosts, endpoints, observers, this, _busObservable, busReady);

                    handle.Stop(TimeSpan.FromSeconds(60));
                }
                catch (Exception ex)
                {
                    _log.Error("Failed to stop partially created bus", ex);
                }

                TaskUtil.Await(() => _busObservable.StartFaulted(this, exception));

                throw new MassTransitException("The service bus could not be started.", exception);
            }

            _busHandle = new Handle(hosts, endpoints, observers, this, _busObservable, busReady);

            TaskUtil.Await(() => _busObservable.PostStart(this, busReady.Ready));

            return(_busHandle);
        }