public override void Flush()
        {
            if (_writeBufferOffset <= 0)
            {
                return;
            }
            var count = Lz4.Compress(_writeBuffer, 0, _writeBufferOffset, ref _compressedBuffer, _compressionMode);

            _targetStream.Write(_compressedBuffer, 0, count);
            CompressedLength  += count;
            _writeBufferOffset = 0;
        }
Пример #2
0
        private void WorkToDo()
        {
            var compressor = new Lz4();

            while (!_isCanceled)
            {
                byte[] jsonBytes       = new byte[0];
                byte[] compressedBytes = new byte[0];
                long   alertListCount  = 0;
                long   eventListCount  = 0;
                try
                {
                    var alerts = ConsumeInSmallBatch();

                    // return to the while if there is nothing to save
                    if (alerts.Item1.Count == 0)
                    {
                        continue;
                    }

                    //debug messaging incase anything goes wrong here.
                    alertListCount = alerts.Item1.Count;
                    eventListCount = alerts.Item1.Sum(x => x.Events.Length);

                    string json = JsonConvert.SerializeObject(alerts.Item1);
                    jsonBytes       = Encoding.Unicode.GetBytes(json);
                    compressedBytes = compressor.Compress(jsonBytes);

                    _proxy.Produce(compressedBytes);
                }
                catch (Exception ex)
                {
                    _exLog.Error($"alertListCount: {alertListCount} ");
                    _exLog.Error($"eventListCount: {eventListCount} ");
                    _exLog.Error($"jsonBytes: {jsonBytes.Length} ");
                    _exLog.Error($"compressedBytes: {compressedBytes.Length} ");
                    _exLog.Error(ex);
                }
            }
        }