Consuming subscription while yielding results

閲覧: 28 回
最初の未読メッセージにスキップ

Ron Brouwer

未読、
2021/12/24 10:53:522021/12/24
To: RavenDB - an awesome database
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

Egor Shamanaev

未読、
2021/12/26 6:54:562021/12/26
To: rav...@googlegroups.com
Hi 

You cannot yield return items from the Worker.Run() method directly so populating a collection seems like  the way togo.

In case if the batch / fail or subscription stops producing the task will fail. You can see here an example of exception handling in subscription:
https://ravendb.net/docs/article-page/5.3/csharp/client-api/data-subscriptions/consumption/examples#client-with-full-exception-handling-and-processing-retries

--
You received this message because you are subscribed to the Google Groups "RavenDB - an awesome database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/58569198-9ea1-46ee-8afb-36008f1f54d5n%40googlegroups.com.


--
Egor
Developer   /   Hibernating Rhinos LTD
Support:  sup...@ravendb.net
  
全員に返信
投稿者に返信
転送
新着メール 0 件