Exemple #1
0
        public async Task <IActionResult> Post([FromBody] string value)
        {
            using (var transaction = await _sampleDbContext.Database.BeginTransactionAsync())
            {
                await _eventPublisher.PrepareAsync("test", value, new { signature = "" });

                transaction.Commit();
            }
            await _eventPublisher.ConfirmAsync();

            return(Ok());
        }
        public async Task <IActionResult> Post([FromBody] string value)
        {
            var transaction = await _sampleDbContext.Database.BeginTransactionAsync();

            //await _eventPublisher.PrepareAsync("charge.ok.shuttle", "Hello-World1", new { signature = "" });
            //await _eventPublisher.PrepareAsync("charge.ok.commute", "Hello-World2", new { signature = "" });

            for (var i = 0; i < 5; ++i)
            {
                await _eventPublisher.PrepareAsync("charge.ok.shuttle", "Hello-World1", new { signature = "" });
            }

            transaction.Commit();

            await _eventPublisher.ConfirmAsync();

            return(Ok());
        }
Exemple #3
0
        public static async Task PrepareAsync(this IEventPublisher eventPublisher, string routeKey, object content, object metaData, IDbConnection dbConnection, IDbTransaction dbTransaction, string exchange = "default.exchange@feiniubus", object args = null)
        {
            var message = new DefaultMessage(content);

            var anonyObj     = new AnonymousObject(metaData);
            var anonyMembers = anonyObj.GetProperties().Where(member => member.MemberType == System.Reflection.MemberTypes.Property)
                               .Select(member => new { MemberName = member.MemberName, Value = anonyObj.GetValue(member.DeclaringType, member.MemberName) });

            if (anonyMembers.Any())
            {
                var md = new MetaData();
                foreach (var member in anonyMembers)
                {
                    md.Set(member.MemberName, member.Value.ToString());
                }
                message.MetaData.Contact(md);
            }

            await eventPublisher.PrepareAsync(new EventDescriptor(routeKey, message, exchange, args), dbConnection, dbTransaction);
        }