Ejemplo n.º 1
0
        public Task Register(ProducerRegistrationDto producer)
        {
            if (!_stateOfTheWorld.ContainsKey(producer.Endpoint))
            {
                var producerDescriptor = new ProducerDescriptor()
                {
                    Endpoint          = producer.Endpoint,
                    LastActivated     = DateTime.MinValue,
                    State             = ProducerState.Alive,
                    Topic             = producer.Topic,
                    HeartbeatEndpoint = producer.HeartbeatEndpoint
                };

                _stateOfTheWorld.AddOrUpdate(producer.Endpoint, producerDescriptor, (key, oldValue) =>
                {
                    return(oldValue);
                });
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        private bool TryGetNextConsumer()
        {
            try
            {
                if (_cancel.IsCancellationRequested)
                {
                    return(false);
                }

                _currentProducer = _directory.Next(typeof(TEvent).ToString()).Result;
            }
            catch (Exception ex)
            {
                //no producer found
                if (ex.InnerException.GetType() == typeof(ApiException))
                {
                    return(false);
                }

                ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
            }

            return(true);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Register([FromBody] ProducerRegistrationDto producer)
        {
            await _directory.Register(producer);

            return(StatusCode(201));
        }