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)); } }
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(); } }
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); } }
// 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())); } }
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); }