在我以前的API版本中,我已经使用 Mono 作为返回类型。一切正常后,我登录了 doOnSuccess 方法。
将API方法的返回类型更改为 Flux 后,我无法使用 doOnSuccess 进行日志记录。
请问Flux的 doOnSuccess 方法等效于什么?
答案 0 :(得分:2)
flux的doOnSuccess方法等效什么
public class DefaultResponseModel<T>
{
public string ResponseID { get; private set; }
public DateTimeOffset ResponseDateTime { get; private set; }
public string RequestMethod { get; private set; }
public string IPAddress { get; private set; }
public T Data { get; set; }
public DefaultResponseModel(ApiController controller)
{
ResponseDateTime = DateTimeOffset.Now;
RequestMethod = controller.Request.Method.ToString();
if (controller.Request.Properties.ContainsKey("MS_HttpContext"))
{
var ctx = controller.Request.Properties["MS_HttpContext"] as HttpContextBase;
if (ctx != null)
{
IPAddress = ctx.Request.UserHostAddress;
}
else
{
IPAddress = "--";
}
}
ResponseID = controller.Request.Properties.FirstOrDefault(x => x.Key == "RequestID").Value.ToString();
}
public DefaultResponseModel(HttpRequestMessage Request)
{
ResponseDateTime = DateTimeOffset.Now;
RequestMethod = Request.Method.ToString();
if (Request.Properties.ContainsKey("MS_HttpContext"))
{
var ctx = Request.Properties["MS_HttpContext"] as HttpContextBase;
if (ctx != null)
{
IPAddress = ctx.Request.UserHostAddress;
}
else
{
IPAddress = "--";
}
}
ResponseID = Request.Properties.FirstOrDefault(x => x.Key == "RequestID").Value.ToString();
}
可能是最接近的匹配项,当doOnComplete()
成功完成(没有错误)时,这会带来副作用。
作为附录,Flux
是等效的运算符,它将在doOnTerminate()
正常终止或引发异常时终止时增加副作用。