/// <summary> /// Try to send request message and return the response as a message, or return null if not successful /// </summary> /// <param name="address">a string denoting the address to connect to</param> /// <param name="requestMessage">The request message</param> /// <param name="numTries">The number of times to try</param> /// <param name="requestTimeout">The timeout for each request</param> /// <param name="progressPublisher">Report topics: Failure, Retry, Send, Success</param> /// <returns>the response message, or null if not successful</returns> public static NetMQMessage RequestResponseMultipartMessageWithRetry([NotNull] string address, [NotNull] NetMQMessage requestMessage, int numTries, TimeSpan requestTimeout, PublisherSocket progressPublisher = null) { NetMQMessage responseMessage = new NetMQMessage(); while (numTries-- > 0) { using (RequestSocket requestSocket = new RequestSocket(address)) { progressPublisher?.SendFrame(ProgressTopic.Send.ToString()); requestSocket.SendMultipartMessage(requestMessage); if (requestSocket.TryReceiveMultipartMessage(requestTimeout, ref responseMessage)) { progressPublisher?.SendFrame(ProgressTopic.Success.ToString()); return(responseMessage); } progressPublisher?.SendFrame(ProgressTopic.Retry.ToString()); } } progressPublisher?.SendFrame(ProgressTopic.Failure.ToString()); return(null); }
/// <summary> /// Try to send request string and return the response string, or return null if not successful /// </summary> /// <param name="address">a string denoting the address to connect to</param> /// <param name="requestString">The request string</param> /// <param name="numTries">The number of times to try</param> /// <param name="requestTimeout">The timeout for each request</param> /// <param name="progressPublisher">Report topics: Failure, Retry, Send, Success</param> /// <returns>the response message, or null if not successful</returns> public static string RequestResponseStringWithRetry([NotNull] string address, [NotNull] string requestString, int numTries, TimeSpan requestTimeout, PublisherSocket progressPublisher = null) { while (numTries-- > 0) { using (RequestSocket requestSocket = new RequestSocket(address)) { progressPublisher?.SendFrame(ProgressTopic.Send.ToString()); requestSocket.SendFrame(requestString); string frameString; if (requestSocket.TryReceiveFrameString(requestTimeout, out frameString)) { progressPublisher?.SendFrame(ProgressTopic.Success.ToString()); return(frameString); } progressPublisher?.SendFrame(ProgressTopic.Retry.ToString()); } } progressPublisher?.SendFrame(ProgressTopic.Failure.ToString()); return(null); }