Beispiel #1
0
 /// <summary>
 /// Create a ProducerRouter with the given cluster and configuration.
 /// Will start the internal actor.
 /// </summary>
 /// <param name="cluster"></param>
 /// <param name="configuration"></param>
 /// <param name="pool">The pool of message buffers (for when SerializeOnProduce is true)</param>
 public ProduceRouter(ICluster cluster, Configuration configuration, Pool <ReusableMemoryStream> pool)
 {
     _cluster       = cluster;
     _configuration = configuration;
     _pool          = pool;
     _messages      = new ActionBlock <RouterMessageType>(m => ProcessMessage(m),
                                                          new ExecutionDataflowBlockOptions
     {
         MaxMessagesPerTask = configuration.ProduceBatchSize,
         TaskScheduler      = configuration.TaskScheduler
     });
     if (configuration.BatchStrategy == BatchStrategy.Global)
     {
         _batchStrategy = new GlobalBatchingStrategy(
             configuration,
             (n, b) =>
         {
             if (n.Post(b))
             {
                 return;
             }
             foreach (var pm in b.SelectMany(g => g).SelectMany(g => g))
             {
                 Route(pm);
             }
         });
     }
     else
     {
         _batchStrategy = new ByNodeBatchingStrategy();
     }
 }
 public ConsumeRouter(ICluster cluster, Configuration configuration, int resolution = 1000)
 {
     _resolution    = resolution;
     _cluster       = cluster;
     _configuration = configuration;
     _innerActor    = new ActionBlock <ConsumerMessage>(m => ProcessMessage(m),
                                                        new ExecutionDataflowBlockOptions {
         TaskScheduler = configuration.TaskScheduler
     });
     if (configuration.BatchStrategy == BatchStrategy.ByNode)
     {
         _fetchBatchStrategy  = new ByNodeFetchBatchingStrategy();
         _offsetBatchStrategy = new ByNodeOffsetBatchingStrategy();
     }
     else
     {
         _fetchBatchStrategy  = new GlobalFetchBatchingStrategy(configuration, (n, b) => n.Post(b));
         _offsetBatchStrategy = new GlobalOffsetBatchingStrategy(configuration, (n, b) => n.Post(b));
     }
 }
Beispiel #3
0
 public ConsumeRouter(ICluster cluster, Configuration configuration, int resolution = 1000)
 {
     _resolution    = resolution;
     _cluster       = cluster;
     _configuration = configuration;
     _innerActor    = new ActionBlock <ConsumerMessage>(m => ProcessMessage(m),
                                                        new ExecutionDataflowBlockOptions {
         TaskScheduler = configuration.TaskScheduler
     });
     if (configuration.BatchStrategy == BatchStrategy.ByNode)
     {
         _fetchBatchStrategy  = new ByNodeFetchBatchingStrategy();
         _offsetBatchStrategy = new ByNodeOffsetBatchingStrategy();
     }
     else
     {
         _fetchBatchStrategy = new GlobalFetchBatchingStrategy(configuration, (n, b) =>
         {
             if (n.Post(b))
             {
                 return;
             }
             foreach (var fm in b.SelectMany(g => g))
             {
                 Postpone(fm.Topic, fm.Partition);
             }
         });
         _offsetBatchStrategy = new GlobalOffsetBatchingStrategy(configuration, (n, b) =>
         {
             if (n.Post(b))
             {
                 return;
             }
             foreach (var om in b.SelectMany(g => g))
             {
                 Postpone(om.Topic, om.Partition);
             }
         });
     }
 }