我有一个 no-sql 数据库,在其中存储序列化的 avro 对象。我使用sbt-avro插件专门生成 java 类addSbtPlugin("com.cavorite" % "sbt-avro-1-8" % "1.1.5")。现在我想向架构添加新字段,并且还希望与现有数据向后兼容。但是使用新模式对旧数据进行反序列化会引发问题java.io.EOFException
旧架构:
{
"name": "DNode",
"namespace": "my.model",
"type": "record",
"fields": [
{"name": "prev", "type": ["null", "string"]},
{"name": "next", "type": ["null", "string"]}
]
}
Run Code Online (Sandbox Code Playgroud)
新架构:
{
"name": "DNode",
"namespace": "my.model",
"type": "record",
"fields": [
{"name": "prev", "type": ["null", "string"]},
{"name": "next", "type": ["null", "string"]},
{"name": "size", "type": ["null", "long"], "default": null}
]
}
Run Code Online (Sandbox Code Playgroud)
反序列化代码
def deserialize(bytes: Array[Byte]) = {
val reader = new SpecificDatumReader[DNode](classOf[DNode])
val decoder …Run Code Online (Sandbox Code Playgroud) 我正在使用 HttpsURLConnection 向服务器发出服务请求,如下面的代码:
URL url = new URL("service/url");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setConnectionTimeout(300000);
connection.setReadTimeout(300000);
parse (connection.getInputStream());
Run Code Online (Sandbox Code Playgroud)
服务有时可能需要更长的时间,所以理想情况下我应该期待超时异常,但客户端正在重试并再次发送相同的请求。有没有办法明确禁用任何类型的重试?而且我什至不确定设置的超时方法是否有任何区别。
我正在使用 Java 1.6
更新
我尝试了 connect() 和 getResponseCode() 而不是 getInputStream() 但相同的行为:
URL url = new URL("service/url");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setConnectionTimeout(300000);
connection.setReadTimeout(300000);
connection.connect();
connection.getResponseCode();
Run Code Online (Sandbox Code Playgroud)
即使这是提出 2 个请求。
更新
HttpClient修复了该问题。在 HttpClient 中,您可以明确地将重试设置为 false