Exemple #1
0
            public async Task HandleAsync()
            {
                if (_token.IsCancellationRequested)
                {
                    Dispose();
                    _configuration.Logger.Log(new InfoLogMsg("SubscriberHandler was cancelled by cancellationRequest"));
                    return;
                }

                try
                {
                    NetMQMessage received = _socket.ReceiveMultipartMessage();
                    _configuration.Logger.Log(new DebugLogMsg($"handling message for [Subscriber:{typeof(TMessage)}]"));
                    var actualMessage = received.ParsePubSubMessage <TMessage>(_configuration);

                    var msg = actualMessage.IsSuccess ? actualMessage.GetResult() : new TMessage();
                    if (this._asyncCallback is null)
                    {
                        _syncCallback(msg);
                    }
                    else
                    {
                        await _asyncCallback(msg);
                    }
                }
                catch (NetMQ.TerminatingException trmnt)
                {
                    _configuration.Logger.Log(new ErrorLogMsg($"Subscriber handle for [Message:{typeof(TMessage)}] did fail: " + trmnt.Message));
                }
                catch (System.Exception ex)
                {
                    _configuration.Logger.Log(new ErrorLogMsg($"Subscriber handle for [Message:{typeof(TMessage)}] did fail: " + ex.Message));
                }
            }