9

Java http 请求中如何处理外部回调?

 3 years ago
source link: https://www.v2ex.com/t/785294
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Java

Java http 请求中如何处理外部回调?

  wangsongyan · 7 小时 40 分钟前 · 526 次点击

我的服务(A)部分功能依赖于外部服务(B),A 向 B 发送 http 请求时,B 会立即返回“提交成功”,等 B 处理完成后才会回调 A 返回我想要的数据。
B 服务不具备修改为同步返回的条件。

当用户访问 A 时,我想返回 B 回调的结果,请问怎么实现? 目前想到两种方式:

  • 1.在 A 请求 B 过程中,A 阻塞等待 B 返回结果,然后返回用户。
  • 2.A 请求 B 后直接返回用户结果,然后用户再使用轮询方式从 A 获取结果。

或者还有没有其他更好的方式?写惯了同步代码,现在换种方式不知道咋搞了


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK