コード例 #1
0
ファイル: RqRep.cs プロジェクト: TimoHeiten/zer0mqXt
        public async Task <XtResult <TResult> > RequestAsync <T, TResult>(T request)
            where T : class, new()
            where TResult : class, new()
        {
            try
            {
                return(await DoRequestAsync <T, TResult>(request));
            }
            catch (NetMQ.EndpointNotFoundException ntfnd)
            {
                _configuration.Logger.Log(new ErrorLogMsg($"NetMQ.Endpoint could not be found at {_configuration.Address()}: " + ntfnd.Message));
                await Task.Delay((int)_configuration.TimeOut.TotalMilliseconds);

                try
                {
                    return(await DoRequestAsync <T, TResult>(request));
                }
                catch (System.Exception inner)
                {
                    _configuration.Logger.Log(new ErrorLogMsg("Request failed after Retry: " + inner.Message));
                    return(XtResult <TResult> .Failed(inner));
                }
            }
            catch (System.Exception ex)
            {
                _configuration.Logger.Log(new ErrorLogMsg("Request failed: " + ex.Message));
                return(XtResult <TResult> .Failed(ex));
            }
        }
コード例 #2
0
        public async Task <XtResult <TMessage> > PublishAsync <TMessage>(TMessage message)
            where TMessage : class, new()
        {
            PublisherSocket publisherSocket = null;

            try
            {
                publisherSocket = new PublisherSocket();
                publisherSocket.Connect(_configuration.Address());
                return(await Task.Run(() =>
                {
                    try
                    {
                        var msg = new PubSubMessage <TMessage>(_configuration, message);
                        publisherSocket.SendMultipartMessage(msg);
                    }
                    catch (System.Exception ex)
                    {
                        return XtResult <TMessage> .Failed(ex, "publish");
                    }

                    return XtResult <TMessage> .Success(message, "publish");
                }));
            }
            catch (System.Exception ex)
            {
                return(XtResult <TMessage> .Failed(ex, "publish"));
            }
            finally
            {
                publisherSocket?.Dispose();
            }
        }
コード例 #3
0
            public (bool success, Exception ex) Setup()
            {
                Exception exception = null;

                try
                {
                    _socketDelegate = async(s, arg) => await HandleAsync();

                    _socket.ReceiveReady += _socketDelegate;

                    // todo use actual topics instead of catchall
                    string catchAllTopic = "";
                    _socket.Bind(_configuration.Address());
                    _socket.Subscribe(catchAllTopic);
                    _configuration.Logger.Log(new DebugLogMsg($"subscribed to [{typeof(TMessage)}]"));
                    _poller.Add(_socket);
                    _poller.RunAsync();

                    return(true, null);
                }
                catch (NetMQ.EndpointNotFoundException ntfnd)
                {
                    _configuration.Logger.Log(new ErrorLogMsg(ntfnd.Message));
                    exception = ntfnd;
                    return(false, exception);
                }
            }
コード例 #4
0
 // socket came late, for now no refactoring of all tests desired
 private static ISocket ToSocket(SocketConfiguration configuration)
 {
     if (configuration is SocketConfiguration.Tcp tcp)
     {
         string port = tcp.Address().Split(":").Last();
         return(Zer0Mq.Go().BuildWithTcp("localhost", port));
     }
     else
     {
         return(Zer0Mq.Go().BuildWithInProc(configuration.Address().Split("//").Last()));
     }
 }
コード例 #5
0
 private static async Task ExecuteScenario(string key, SocketConfiguration configuration)
 {
     System.Console.WriteLine($"Running scenario [{key}] with config [{configuration.GetType().Name}] at address [{configuration.Address()}]");
     await _terminalActions[key](configuration);
 }