scala - Akka如何根据参数值有条件地转发请求
问题描述
我有一个类似的现有路线:
pathPrefix("foo") {
pathPrefix(IntNumber) { id =>
post {
entity(as[FooReqeust]) { request =>
val f = doSomething(id, request)
onComplete(f) {
case Success(res) => complete(res)
case Failure(e) => complete(HttpResponse(InternalServerError, entity = "someError"))
}
}
}
}
}
我们有一个新服务(在这个服务之外),我们希望在运行一些测试后开始路由到它。新的服务标头/参数/帖子正文等与现有的相同
id
如果回答某些条件,我想将来自现有端点的请求转发到新端点。
我不清楚如何实现这一点。(并希望避免序列化/反序列化检查主体等)
例如:
pathPrefix("foo") {
pathPrefix(IntNumber) { id =>
post {
if (id == 1234) complete(usingNewService(...)) <<<< blindly complete with the new service
else // use the current implementation
entity(as[FooReqeust]) { request =>
.... same code as before ...
}
}
}
}
解决方案
推荐阅读
- google-cloud-platform - GCP:如何更改 VPC 子网区域?
- powershell - 如何在 ps 脚本路径有空格且路径派生自 %~dp0% 时从批处理文件运行 powershell 脚本
- python - 为什么 PIL.Image.open() 函数对象的维度在转换为 numpy 数组时会发生变化
- python - 需要在python中以不同格式从现有字典创建新字典
- python - 通过 ZipFile.setpassword 命令使用变量
- facebook - 是否可以确定液体中的图像宽度和高度?
- c# - 在 C# 中按字段排序并通过另一个字段检查是否相等
- android - 如何更改通知徽章 Android
- virtualbox - 尝试启动 WebOS TV 模拟器时如何解决此错误?
- r - 基于来自观察事件的数据帧可输出