Beispiel #1
0
        private async Task FlushMessages()
        {
            List <ElasticReturn> bulkMessages = new List <ElasticReturn>();

            lock (logList)
            {
                foreach (LogCacheMessage logCache in logList)
                {
                    ElasticReturn elasticReturn = _elasticConfig.transformer(logCache);

                    if (includeLogs || logCache.type == LogType.Error || logCache.type == LogType.Exception)
                    {
                        bulkMessages.Add(elasticReturn);
                    }
                }

                if (bulkMessages.Count <= 0)
                {
                    return;
                }

                logList.Clear();
            }

            ElasticBulkMessage elasticBulkMessage = new ElasticBulkMessage()
            {
                messages = bulkMessages,
                index    = _elasticConfig.index
            };

            await ElasticsearchSendMessages(elasticBulkMessage);
        }
Beispiel #2
0
 private async Task ElasticsearchSendMessages(ElasticBulkMessage message)
 {
     try
     {
         await ESCallerService.BulkAsync(message);
     }
     catch (Exception ex)
     {
         Debug.LogException(ex);
         Debug.LogError($"Exception while emitting periodic batch from {this}: {ex}");
     }
 }
        public static async UniTask <bool> BulkAsync(ElasticBulkMessage msg)
        {
            string indexJson = "{\"index\": {\"_index\": \"" + msg.index + "\"}}\n";
            string json      = NDJsonHelper.ToNDJson(indexJson, msg.messages);

            await UniTask.SwitchToMainThread();

            var response = await instance.caller.PostNDJson($"{msg.index}/_bulk", json);

            if (!response.IsSuccess)
            {
                Debug.LogError(response.Error);
            }
            return(response.IsSuccess);
        }