コード例 #1
0
        public void Publish(IMessageWrapper messageWrapper)
        {
            var raw = _messageConverter.Serialize(messageWrapper.Message);

            if (raw == null)
            {
                return;
            }
            _rabbitMQWrapper.Publish(messageWrapper.Descriptor, raw);
        }
コード例 #2
0
        private void OnTransactionChangedHandler(object sender, NotifyTransactionChangedEventArgs e)
        {
            if (e.Action == NotifyTransactionChangedAction.Commit)
            {
                var    allEvents       = changeCollector.GetAllChanges();
                var    transactionMock = new TransactionMock(e.Transaction.TransactionId, e.Transaction.CommitSequenceNumber);
                var    trAppliedEvent  = new NotifyTransactionAppliedEvent(transactionMock, allEvents);
                Byte[] byteStream      = messageConverter.Serialize(trAppliedEvent);
                long   currentLsn      = e.Transaction.CommitSequenceNumber;
                // handle the failure of Task here.
                EventCollector.TransactionApplied(this.partitionId, previousLsn, currentLsn, byteStream);
                previousLsn = currentLsn;

                // Flush previous items.
                this.changeCollector.CreateNew();
            }
        }
コード例 #3
0
        public async ValueTask <string> HashAsync(
            IMessageDescriptor descriptor,
            IMessage message,
            HashAlgorithmName algorism          = default,
            CancellationToken cancellationToken = default)
        {
            algorism = (algorism == default) ? HashAlgorithmName.SHA1 : algorism;

            byte[] raw = null;

            if (descriptor is IRichMessageDescriptor rich)
            {
                if (rich.Raw != null && rich.Raw.Length != 0)
                {
                    raw = rich.Raw;
                }
                else if (!string.IsNullOrWhiteSpace(rich.MessageId))
                {
                    raw = Encoding.UTF8.GetBytes(rich.MessageId);
                }
            }
            if (raw == null)
            {
                try
                {
                    raw = _messageConverter.Serialize(message);
                }
                catch (Exception)
                {
                }
            }
            if (raw == null)
            {
                return("SRC-ERROR");
            }
            return(await Task.Run(async() => await HashBodyAsync(descriptor, raw, algorism, cancellationToken)));
        }