Example #1
0
        private static async Task LauchEventWithCommitedTransaction()
        {
            var pinged = new Pinged("Second event", 1500);

            Console.WriteLine("---------- ");
            Console.WriteLine($"Strategy: {PublishStrategy.SyncStopOnException} launched inside a transaction");
            Console.WriteLine("--------------------------");

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    await _publisher.Publish(pinged, PublishStrategy.SyncStopOnException);

                    Console.WriteLine("In main.... event already published");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("In main.... exception caught");
                    Console.WriteLine($"{ex.GetType()}: {ex.Message}");
                }
                finally
                {
                    transaction.Complete();
                }
            }

            Console.WriteLine("---------- ");
            Console.WriteLine($"Strategy: {PublishStrategy.ParallelWait} launched inside a transaction");
            Console.WriteLine("--------------------------");

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    await _publisher.Publish(pinged, PublishStrategy.ParallelWait);

                    Console.WriteLine("In main.... event already published");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("In main.... exception caught");
                    Console.WriteLine($"{ex.GetType()}: {ex.Message}");
                }
                finally
                {
                    transaction.Complete();
                }
            }
        }
Example #2
0
        private static async Task LauchEvent()
        {
            var pinged = new Pinged("First event", 1500);

            foreach (PublishStrategy strategy in Enum.GetValues(typeof(PublishStrategy)))
            {
                Console.WriteLine("----------");
                Console.WriteLine($"Strategy: {strategy}");
                Console.WriteLine("--------------------------");

                try
                {
                    await _publisher.Publish(pinged, strategy);

                    Console.WriteLine("In main.... event already published");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("In main.... exception caught");
                    Console.WriteLine($"{ex.GetType()}: {ex.Message}");
                }
            }
        }