public void AddQueue(string queueName, int parallelization) { var options = new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = parallelization, CancellationToken = _cancellationToken }; if (!_receivers.ContainsKey(queueName)) { var receiver = new ActionBlock <Envelope>(async envelope => { try { envelope.ContentType = envelope.ContentType ?? "application/json"; await Pipeline.Invoke(envelope); } catch (Exception e) { _logger.LogException(e); } }, options); _receivers.Add(queueName, receiver); } }
public static async Task <int> put__messages_durable(HttpRequest request, ILocalWorkerSender workers, IMessageLogger logger, IMessagingRoot root) { if (root.ListeningStatus == ListeningStatus.TooBusy) { return(503); } try { // TODO -- optimize the reading here to reduce allocations var bytes = await request.Body.ReadBytesAsync(request.ContentLength); var envelopes = Envelope.ReadMany(bytes); await workers.EnqueueDurably(envelopes); return(200); } catch (Exception e) { var message = $"Error receiving envelopes from {request.Headers["x-jasper-envelope-sender"]}"; logger.LogException(e, message: message); return(500); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { await Task.Delay(_settings.MetricsCollectionSamplingInterval, stoppingToken); _metrics.LogLocalWorkerQueueDepth(_workers.QueuedCount); try { var counts = await _persistor.GetPersistedCounts(); _metrics.LogPersistedCounts(counts); } catch (Exception e) { _logger.LogException(e); } } }
public async Task StartAsync(CancellationToken cancellationToken) { try { var local = new ServiceNode(_settings) { HttpEndpoints = _runtime.HttpAddresses?.Select(x => x.ToUri().ToMachineUri()).Distinct() .ToArray() }; _runtime.Node = local; await _nodes.Register(local); } catch (Exception e) { _logger .LogException(e, message: "Failure when trying to register the node with " + _nodes); } }