我正在尝试向领事寻求健康的服务。答复是:
HttpResponse(200 OK,List(X-Consul-Index: 3471242, X-Consul-Knownleader: true, X-Consul-Lastcontact: 0, Date: Fri, 02 Mar 2018 16:06:08 GMT),HttpEntity.Strict(application/json,[{"Node":{"Node":"ci-content-1","Address":"10.45.200.14","TaggedAddresses":{"wan":"10.45.200.14"},"CreateIndex":2708577,"ModifyIndex":3470978},"Service":{"ID":"de62bdcb8e37:varnish_2:6085","Service":"shop-varnish-6085","Tags":null,"Address":"10.45.200.14","Port":33889,"EnableTagOverride":false,"CreateIndex":3313055,"ModifyIndex":3313055},"Checks":[{"Node":"ci-content-1","CheckID":"serfHealth","Name":"Serf Health Status","Status":"passing","Notes":"","Output":"Agent alive and reachable","ServiceID":"","ServiceName":"","CreateIndex":2708577,"ModifyIndex":3451134}]},{"Node":{"Node":"ci-content-2","Address":"10.45.200.18","TaggedAddresses":{"wan":"10.45.200.18"},"CreateIndex":2158463,"ModifyIndex":3471241},"Service":{"ID":"f89a94600d4c:varnish_1:6085","Service":"shop-varnish-6085","Tags":null,"Address":"10.45.200.18","Port":33622,"EnableTagOverride":false,"CreateIndex":3313064,"ModifyIndex":3313064},"Checks":[{"Node":"toom-ci-content-2","CheckID":"serfHealth","Name":"Serf Health Status","Status":"passing","Notes":"","Output":"Agent alive and reachable","ServiceID":"","ServiceName":"","CreateIndex":2158464,"ModifyIndex":3297480}]}]
类定义是:
final case class TaggedAddresses (
wan: String)
final case class Node (
node: String,
address: String,
taggedAddresses: TaggedAddresses,
createIndex: Int,
modifyIndex: Int
)
final case class Service (
id: String,
service: String,
tags: String,
addresses: String,
port: Int,
enableTagOverride: String,
createIndex: Int,
modifyIndex: Int
)
final case class Check (
node: String,
checkId:String,
name: String,
status: String,
notes: String,
output: String,
serviceId: String,
serviceName:String,
createIndex: Int,
modifyIndex: Int
)
final case class NodeInfo(
node: Node,
service: Service,
checkList: List[Check]
)
package object VarnishInformation {}
然后我尝试解组:
val request = HttpRequest(method = HttpMethods.GET, uri = consulUrl)
val response = Await.result(Http().singleRequest(request), 10.seconds)
log.info("Entity: " + response.httpMessage)
val entries = Unmarshal(response).to[List[NodeInfo]]
并得到以下错误:
处理请求时出错:“尝试解码失败游标上的值:DownField(node),DownArray”。完成 500 内部服务器错误响应。要更改默认异常处理行为,请提供自定义 ExceptionHandler。
我看不到失败,其他人可以吗?