-
Notifications
You must be signed in to change notification settings - Fork 46
/
ErrorMessagesDataStore.cs
683 lines (576 loc) · 27.1 KB
/
ErrorMessagesDataStore.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
namespace ServiceControl.Persistence.RavenDB
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Editing;
using NServiceBus.Logging;
using Raven.Client;
using Raven.Client.Documents;
using Raven.Client.Documents.Commands;
using Raven.Client.Documents.Linq;
using Raven.Client.Documents.Operations;
using Raven.Client.Documents.Queries;
using Raven.Client.Documents.Queries.Facets;
using Raven.Client.Documents.Session;
using ServiceControl.CompositeViews.Messages;
using ServiceControl.EventLog;
using ServiceControl.MessageFailures;
using ServiceControl.MessageFailures.Api;
using ServiceControl.Operations;
using ServiceControl.Operations.BodyStorage;
using ServiceControl.Persistence.Infrastructure;
using ServiceControl.Recoverability;
class ErrorMessagesDataStore(
IDocumentStore documentStore,
IBodyStorage bodyStorage,
ExpirationManager expirationManager)
: IErrorMessageDataStore
{
public async Task<QueryResult<IList<MessagesView>>> GetAllMessages(
PagingInfo pagingInfo,
SortInfo sortInfo,
bool includeSystemMessages
)
{
using var session = documentStore.OpenAsyncSession();
var query = session.Query<MessagesViewIndex.SortAndFilterOptions, MessagesViewIndex>()
.IncludeSystemMessagesWhere(includeSystemMessages)
.Statistics(out var stats)
.Sort(sortInfo)
.Paging(pagingInfo)
.OfType<FailedMessage>()
.TransformToMessageView();
var results = await query.ToListAsync();
return new QueryResult<IList<MessagesView>>(results, stats.ToQueryStatsInfo());
}
public async Task<QueryResult<IList<MessagesView>>> GetAllMessagesForEndpoint(
string endpointName,
PagingInfo pagingInfo,
SortInfo sortInfo,
bool includeSystemMessages
)
{
using var session = documentStore.OpenAsyncSession();
var query = session.Query<MessagesViewIndex.SortAndFilterOptions, MessagesViewIndex>()
.IncludeSystemMessagesWhere(includeSystemMessages)
.Where(m => m.ReceivingEndpointName == endpointName)
.Statistics(out var stats)
.Sort(sortInfo)
.Paging(pagingInfo)
.OfType<FailedMessage>()
.TransformToMessageView();
var results = await query.ToListAsync();
return new QueryResult<IList<MessagesView>>(results, stats.ToQueryStatsInfo());
}
public async Task<QueryResult<IList<MessagesView>>> SearchEndpointMessages(
string endpointName,
string searchKeyword,
PagingInfo pagingInfo,
SortInfo sortInfo
)
{
using var session = documentStore.OpenAsyncSession();
var query = session.Query<MessagesViewIndex.SortAndFilterOptions, MessagesViewIndex>()
.Statistics(out var stats)
.Search(x => x.Query, searchKeyword)
.Where(m => m.ReceivingEndpointName == endpointName)
.Sort(sortInfo)
.Paging(pagingInfo)
.OfType<FailedMessage>()
.TransformToMessageView();
var results = await query.ToListAsync();
return new QueryResult<IList<MessagesView>>(results, stats.ToQueryStatsInfo());
}
public async Task<QueryResult<IList<MessagesView>>> GetAllMessagesByConversation(
string conversationId,
PagingInfo pagingInfo,
SortInfo sortInfo,
bool includeSystemMessages
)
{
using var session = documentStore.OpenAsyncSession();
var query = session.Query<MessagesViewIndex.SortAndFilterOptions, MessagesViewIndex>()
.Statistics(out var stats)
.Where(m => m.ConversationId == conversationId)
.Sort(sortInfo)
.Paging(pagingInfo)
.OfType<FailedMessage>()
.TransformToMessageView();
var results = await query.ToListAsync();
return new QueryResult<IList<MessagesView>>(results, stats.ToQueryStatsInfo());
}
public async Task<QueryResult<IList<MessagesView>>> GetAllMessagesForSearch(
string searchTerms,
PagingInfo pagingInfo,
SortInfo sortInfo
)
{
using var session = documentStore.OpenAsyncSession();
var query = session.Query<MessagesViewIndex.SortAndFilterOptions, MessagesViewIndex>()
.Statistics(out var stats)
.Search(x => x.Query, searchTerms)
.Sort(sortInfo)
.Paging(pagingInfo)
.OfType<FailedMessage>()
.TransformToMessageView();
var results = await query.ToListAsync();
return new QueryResult<IList<MessagesView>>(results, stats.ToQueryStatsInfo());
}
public async Task FailedMessageMarkAsArchived(string failedMessageId)
{
using var session = documentStore.OpenAsyncSession();
var failedMessage = await session.LoadAsync<FailedMessage>(FailedMessageIdGenerator.MakeDocumentId(failedMessageId));
if (failedMessage.Status != FailedMessageStatus.Archived)
{
failedMessage.Status = FailedMessageStatus.Archived;
expirationManager.EnableExpiration(session, failedMessage);
}
await session.SaveChangesAsync();
}
public async Task<FailedMessage[]> FailedMessagesFetch(Guid[] ids)
{
using var session = documentStore.OpenAsyncSession();
var docIds = ids.Select(g => FailedMessageIdGenerator.MakeDocumentId(g.ToString()));
var results = await session.LoadAsync<FailedMessage>(docIds);
return results.Values.Where(x => x != null).ToArray();
}
public async Task StoreFailedErrorImport(FailedErrorImport failure)
{
using var session = documentStore.OpenAsyncSession();
await session.StoreAsync(failure);
await session.SaveChangesAsync();
}
public Task<IEditFailedMessagesManager> CreateEditFailedMessageManager()
{
var session = documentStore.OpenAsyncSession();
var manager = new EditFailedMessageManager(session, expirationManager);
return Task.FromResult((IEditFailedMessagesManager)manager);
}
public async Task<QueryResult<FailureGroupView>> GetFailureGroupView(string groupId, string status, string modified)
{
using var session = documentStore.OpenAsyncSession();
var document = await session.Advanced
.AsyncDocumentQuery<FailureGroupView, ArchivedGroupsViewIndex>()
.Statistics(out var stats)
.WhereEquals(group => group.Id, groupId)
.FilterByStatusWhere(status)
.FilterByLastModifiedRange(modified)
.FirstOrDefaultAsync();
return new QueryResult<FailureGroupView>(document, stats.ToQueryStatsInfo());
}
public async Task<IList<FailureGroupView>> GetFailureGroupsByClassifier(string classifier)
{
using var session = documentStore.OpenAsyncSession();
var groups = session
.Query<FailureGroupView, ArchivedGroupsViewIndex>()
.Where(v => v.Type == classifier);
var results = await groups
.OrderByDescending(x => x.Last)
.Take(200) // only show 200 groups
.ToListAsync();
return results;
}
public async Task<QueryResult<IList<FailedMessageView>>> ErrorGet(
string status,
string modified,
string queueAddress,
PagingInfo pagingInfo,
SortInfo sortInfo
)
{
using var session = documentStore.OpenAsyncSession();
var query = session.Advanced
.AsyncDocumentQuery<FailedMessageViewIndex.SortAndFilterOptions, FailedMessageViewIndex>()
.Statistics(out var stats)
.FilterByStatusWhere(status)
.FilterByLastModifiedRange(modified)
.FilterByQueueAddress(queueAddress)
.Sort(sortInfo)
.Paging(pagingInfo)
.SelectFields<FailedMessage>()
.ToQueryable()
.TransformToFailedMessageView();
var results = await query
.ToListAsync();
return new QueryResult<IList<FailedMessageView>>(results, stats.ToQueryStatsInfo());
}
public async Task<QueryStatsInfo> ErrorsHead(
string status,
string modified,
string queueAddress
)
{
using var session = documentStore.OpenAsyncSession();
var stats = await session.Advanced
.AsyncDocumentQuery<FailedMessageViewIndex.SortAndFilterOptions, FailedMessageViewIndex>()
.FilterByStatusWhere(status)
.FilterByLastModifiedRange(modified)
.FilterByQueueAddress(queueAddress)
.GetQueryResultAsync();
return stats.ToQueryStatsInfo();
}
public async Task<QueryResult<IList<FailedMessageView>>> ErrorsByEndpointName(
string status,
string endpointName,
string modified,
PagingInfo pagingInfo,
SortInfo sortInfo
)
{
using var session = documentStore.OpenAsyncSession();
var query = session.Advanced
.AsyncDocumentQuery<FailedMessageViewIndex.SortAndFilterOptions, FailedMessageViewIndex>()
.Statistics(out var stats)
.FilterByStatusWhere(status)
.AndAlso()
.WhereEquals("ReceivingEndpointName", endpointName)
.FilterByLastModifiedRange(modified)
.Sort(sortInfo)
.Paging(pagingInfo)
.SelectFields<FailedMessage>()
.ToQueryable()
.TransformToFailedMessageView();
var results = await query
.ToListAsync();
return new QueryResult<IList<FailedMessageView>>(results, stats.ToQueryStatsInfo());
}
public async Task<IDictionary<string, object>> ErrorsSummary()
{
using var session = documentStore.OpenAsyncSession();
var facetResults = await session.Query<FailedMessage, FailedMessageFacetsIndex>()
.AggregateBy(new List<Facet>
{
new Facet
{
FieldName = "Name",
DisplayFieldName = "Endpoints"
},
new Facet
{
FieldName = "Host",
DisplayFieldName = "Hosts"
},
new Facet
{
FieldName = "MessageType",
DisplayFieldName = "Message types"
}
}).ExecuteAsync();
var results = facetResults
.ToDictionary(
x => x.Key,
x => (object)x.Value
);
return results;
}
public Task<FailedMessage> ErrorBy(string failedMessageId) => ErrorByDocumentId(FailedMessageIdGenerator.MakeDocumentId(failedMessageId));
async Task<FailedMessage> ErrorByDocumentId(string documentId)
{
using var session = documentStore.OpenAsyncSession();
var message = await session.LoadAsync<FailedMessage>(documentId);
return message;
}
public Task<INotificationsManager> CreateNotificationsManager()
{
// the session manager manages the lifetime of the session
var manager = new NotificationsManager(documentStore.OpenAsyncSession());
return Task.FromResult<INotificationsManager>(manager);
}
public async Task<FailedMessageView> ErrorLastBy(string failedMessageId)
{
using var session = documentStore.OpenAsyncSession();
var message = await session.LoadAsync<FailedMessage>(FailedMessageIdGenerator.MakeDocumentId(failedMessageId));
if (message == null)
{
return null;
}
var result = Map(message, session);
return result;
}
static FailedMessageView Map(FailedMessage message, IAsyncDocumentSession session)
{
var processingAttempt = message.ProcessingAttempts.Last();
var metadata = processingAttempt.MessageMetadata;
var failureDetails = processingAttempt.FailureDetails;
var wasEdited = message.ProcessingAttempts.Last().Headers.ContainsKey("ServiceControl.EditOf");
var failedMsgView = new FailedMessageView
{
Id = message.UniqueMessageId,
MessageType = metadata.GetAsStringOrNull("MessageType"),
IsSystemMessage = metadata.GetOrDefault<bool>("IsSystemMessage"),
TimeSent = metadata.GetAsNullableDateTime("TimeSent"),
MessageId = metadata.GetAsStringOrNull("MessageId"),
Exception = failureDetails.Exception,
QueueAddress = failureDetails.AddressOfFailingEndpoint,
NumberOfProcessingAttempts = message.ProcessingAttempts.Count,
Status = message.Status,
TimeOfFailure = failureDetails.TimeOfFailure,
LastModified = session.Advanced.GetLastModifiedFor(message).Value,
Edited = wasEdited,
EditOf = wasEdited ? message.ProcessingAttempts.Last().Headers["ServiceControl.EditOf"] : ""
};
try
{
failedMsgView.SendingEndpoint = metadata.GetOrDefault<EndpointDetails>("SendingEndpoint");
}
catch (Exception ex)
{
Logger.Warn($"Unable to parse SendingEndpoint from metadata for messageId {message.UniqueMessageId}", ex);
failedMsgView.SendingEndpoint = EndpointDetailsParser.SendingEndpoint(processingAttempt.Headers);
}
try
{
failedMsgView.ReceivingEndpoint = metadata.GetOrDefault<EndpointDetails>("ReceivingEndpoint");
}
catch (Exception ex)
{
Logger.Warn($"Unable to parse ReceivingEndpoint from metadata for messageId {message.UniqueMessageId}", ex);
failedMsgView.ReceivingEndpoint = EndpointDetailsParser.ReceivingEndpoint(processingAttempt.Headers);
}
return failedMsgView;
}
public async Task EditComment(string groupId, string comment)
{
using var session = documentStore.OpenAsyncSession();
var groupComment =
await session.LoadAsync<GroupComment>(GroupComment.MakeId(groupId))
?? new GroupComment { Id = GroupComment.MakeId(groupId) };
groupComment.Comment = comment;
await session.StoreAsync(groupComment);
await session.SaveChangesAsync();
}
public async Task DeleteComment(string groupId)
{
using var session = documentStore.OpenAsyncSession();
session.Delete(GroupComment.MakeId(groupId));
await session.SaveChangesAsync();
}
public async Task<QueryResult<IList<FailedMessageView>>> GetGroupErrors(
string groupId,
string status,
string modified,
SortInfo sortInfo,
PagingInfo pagingInfo
)
{
using var session = documentStore.OpenAsyncSession();
var query = session.Advanced
.AsyncDocumentQuery<FailureGroupMessageView, FailedMessages_ByGroup>()
.Statistics(out var stats)
.WhereEquals(view => view.FailureGroupId, groupId)
.FilterByStatusWhere(status)
.FilterByLastModifiedRange(modified)
.Sort(sortInfo)
.Paging(pagingInfo)
.SelectFields<FailedMessage>()
.ToQueryable()
.TransformToFailedMessageView();
var results = await query
.ToListAsync();
return results.ToQueryResult(stats);
}
public async Task<QueryStatsInfo> GetGroupErrorsCount(string groupId, string status, string modified)
{
using var session = documentStore.OpenAsyncSession();
var queryResult = await session.Advanced
.AsyncDocumentQuery<FailureGroupMessageView, FailedMessages_ByGroup>()
.WhereEquals(view => view.FailureGroupId, groupId)
.FilterByStatusWhere(status)
.FilterByLastModifiedRange(modified)
.GetQueryResultAsync();
return queryResult.ToQueryStatsInfo();
}
public async Task<QueryResult<IList<FailureGroupView>>> GetGroup(string groupId, string status, string modified)
{
using var session = documentStore.OpenAsyncSession();
var queryResult = await session.Advanced
.AsyncDocumentQuery<FailureGroupView, FailureGroupsViewIndex>()
.Statistics(out var stats)
.WhereEquals(group => group.Id, groupId)
.FilterByStatusWhere(status)
.FilterByLastModifiedRange(modified)
.ToListAsync();
return queryResult.ToQueryResult(stats);
}
public async Task<bool> MarkMessageAsResolved(string failedMessageId)
{
var documentId = FailedMessageIdGenerator.MakeDocumentId(failedMessageId);
using var session = documentStore.OpenAsyncSession();
session.Advanced.UseOptimisticConcurrency = true;
var failedMessage = await session.LoadAsync<FailedMessage>(documentId);
if (failedMessage == null)
{
return false;
}
failedMessage.Status = FailedMessageStatus.Resolved;
expirationManager.EnableExpiration(session, failedMessage);
await session.SaveChangesAsync();
return true;
}
public async Task ProcessPendingRetries(DateTime periodFrom, DateTime periodTo, string queueAddress, Func<string, Task> processCallback)
{
using var session = documentStore.OpenAsyncSession();
var prequery = session.Advanced
.AsyncDocumentQuery<FailedMessageViewIndex.SortAndFilterOptions, FailedMessageViewIndex>()
.WhereEquals("Status", (int)FailedMessageStatus.RetryIssued)
.AndAlso()
.WhereBetween("LastModified", periodFrom.Ticks, periodTo.Ticks);
if (!string.IsNullOrWhiteSpace(queueAddress))
{
prequery = prequery.AndAlso()
.WhereEquals(options => options.QueueAddress, queueAddress);
}
var query = prequery
.SelectFields<FailedMessage>()
.ToQueryable()
.TransformToFailedMessageView();
await using var ie = await session.Advanced.StreamAsync(query);
while (await ie.MoveNextAsync())
{
await processCallback(ie.Current.Document.Id);
}
}
class DocumentPatchResult
{
public string Document { get; set; }
}
public async Task<string[]> UnArchiveMessagesByRange(DateTime from, DateTime to)
{
const int Unresolved = (int)FailedMessageStatus.Unresolved;
const int Archived = (int)FailedMessageStatus.Archived;
var indexName = new FailedMessageViewIndex().IndexName;
var query = new IndexQuery
{
// Set based args are treated differently ($name) than other places (args.name)!
// https://ravendb.net/docs/article-page/5.4/csharp/client-api/operations/patching/set-based
// Removing a property in a patch
// https://ravendb.net/docs/article-page/5.4/Csharp/client-api/operations/patching/single-document#remove-property
Query = $@"from index '{indexName}' as msg
where msg.Status == {Archived} and msg.LastModified >= $from and msg.LastModified <= $to
update
{{
msg.Status = {Unresolved};
{ExpirationManager.DeleteExpirationFieldExpression};
}}",
QueryParameters = new Parameters
{
{ "from", from.Ticks },
{ "to", to.Ticks }
}
};
var patch = new PatchByQueryOperation(query, new QueryOperationOptions
{
AllowStale = true,
RetrieveDetails = true
});
var operation = await documentStore.Operations.SendAsync(patch);
var result = await operation.WaitForCompletionAsync<BulkOperationResult>();
var ids = result.Details.OfType<BulkOperationResult.PatchDetails>()
.Select(d => d.Id)
.ToArray();
return ids;
}
public async Task<string[]> UnArchiveMessages(IEnumerable<string> failedMessageIds)
{
Dictionary<string, FailedMessage> failedMessages;
using var session = documentStore.OpenAsyncSession();
session.Advanced.UseOptimisticConcurrency = true;
var documentIds = failedMessageIds.Select(FailedMessageIdGenerator.MakeDocumentId);
failedMessages = await session.LoadAsync<FailedMessage>(documentIds);
foreach (var failedMessage in failedMessages.Values)
{
if (failedMessage.Status == FailedMessageStatus.Archived)
{
failedMessage.Status = FailedMessageStatus.Unresolved;
session.Advanced.GetMetadataFor(failedMessage).Remove(Constants.Documents.Metadata.Expires);
}
}
await session.SaveChangesAsync();
// Return the unique IDs - the dictionary keys are document ids with a prefix
return failedMessages.Values.Select(x => x.UniqueMessageId).ToArray();
}
public async Task RevertRetry(string messageUniqueId)
{
using var session = documentStore.OpenAsyncSession();
var failedMessage = await session
.LoadAsync<FailedMessage>(FailedMessageIdGenerator.MakeDocumentId(messageUniqueId));
if (failedMessage != null)
{
failedMessage.Status = FailedMessageStatus.Unresolved;
}
var failedMessageRetry = await session
.LoadAsync<FailedMessageRetry>(FailedMessageRetry.MakeDocumentId(messageUniqueId));
if (failedMessageRetry != null)
{
session.Delete(failedMessageRetry);
}
await session.SaveChangesAsync();
}
public async Task RemoveFailedMessageRetryDocument(string uniqueMessageId)
{
using var session = documentStore.OpenAsyncSession();
await session.Advanced.RequestExecutor.ExecuteAsync(new DeleteDocumentCommand(FailedMessageRetry.MakeDocumentId(uniqueMessageId), null), session.Advanced.Context);
}
public async Task<string[]> GetRetryPendingMessages(DateTime from, DateTime to, string queueAddress)
{
using var session = documentStore.OpenAsyncSession();
var query = session
.Query<FailedMessageViewIndex.SortAndFilterOptions, FailedMessageViewIndex>()
.Where(o => o.Status == FailedMessageStatus.RetryIssued && o.LastModified >= from.Ticks && o.LastModified <= to.Ticks && o.QueueAddress == queueAddress)
.OfType<FailedMessageProjection>();
int index = 0;
await using var streamResults = await session.Advanced.StreamAsync(query, out var streamQueryStatistics);
string[] ids = new string[streamQueryStatistics.TotalResults];
while (await streamResults.MoveNextAsync())
{
ids[index++] = streamResults.Current.Document.UniqueMessageId;
}
return ids;
}
record struct FailedMessageProjection(string UniqueMessageId);
public async Task<byte[]> FetchFromFailedMessage(string uniqueMessageId)
{
byte[] body = null;
var result = await bodyStorage.TryFetch(uniqueMessageId);
if (result == null)
{
throw new InvalidOperationException("IBodyStorage.TryFetch result cannot be null");
}
if (result.HasResult)
{
await using (result.Stream) // Not strictly required for MemoryStream but might be different behavior in future .NET versions
{
// Unfortunately we can't use the buffer manager here yet because core doesn't allow to set the length property so usage of GetBuffer is not possible
// furthermore call ToArray would neglect many of the benefits of the recyclable stream
// RavenDB always returns a memory stream in ver. 3.5 so there is no need to pretend we need to do buffered reads since the memory is anyway fully allocated already
// this assumption might change when we stop supporting RavenDB 3.5 but right now this is the most memory efficient way to do things
// https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream#getbuffer-and-toarray
using var memoryStream = new MemoryStream();
await result.Stream.CopyToAsync(memoryStream);
body = memoryStream.ToArray();
}
}
return body;
}
public async Task StoreEventLogItem(EventLogItem logItem)
{
using var session = documentStore.OpenAsyncSession();
await session.StoreAsync(logItem);
expirationManager.EnableExpiration(session, logItem);
await session.SaveChangesAsync();
}
public async Task StoreFailedMessagesForTestsOnly(params FailedMessage[] failedMessages)
{
using var session = documentStore.OpenAsyncSession();
foreach (var message in failedMessages)
{
await session.StoreAsync(message);
}
await session.SaveChangesAsync();
}
static readonly ILog Logger = LogManager.GetLogger<ErrorMessagesDataStore>();
}
}