Hi Guys,
How would I solve the following simplified problem given the fact that I cannot change the Produce functions signature because of the abstract EventPublisher implementation? The issue is highlighted below. I cannot yield from the run function. Perhaps I could use a BlockingCollection of 1, but hat seams like a bad solution to me. Not sure how I could make the batch fail if this producer was not readed til the end of the batch (or subscription stops producing).
public class SellerEventPublisher : EventPublisher<SellerProjection>
{
private readonly IDocumentStore _documentStore;
public SellerEventPublisher(IDocumentStore documentStore)
{
_documentStore = documentStore;
}
public override IEnumerable<SellerProjection> Produce(CancellationToken cancellationToken)
{
var subscription = _documentStore.Subscriptions.GetSubscriptionWorker<SellerProjection>(new SubscriptionWorkerOptions(Subscription.Seller)
{
Strategy = SubscriptionOpeningStrategy.TakeOver,
MaxDocsPerBatch = 100,
CloseWhenNoDocsLeft = true
});
subscription.Run(batch =>
{
foreach (var item in batch.Items)
{
yield return item.Result;
}
}).GetAwaiter().GetResult();
}
}
Looking forward to your insights.
Thanks, Ron Brouwer