我有一个 avro 模式,其中我已将捕获声明为布尔值,并且我想将默认值指定为true
。
{
"namespace": "abc",
"type": "record",
"name": "Request",
"fields": [
{
"name": "amount",
"type": "long",
},
{
"name": "currency",
"type": ["string", "null"],
},
{
"name": "capture",
"type": "boolean",
"default": true
}
}
Run Code Online (Sandbox Code Playgroud)
当在 Java 中使用它时,它会获得默认值null
。我需要做什么才能将其默认为true
?
我正在使用以下 docker-compose 文件
version: '3.7'
services:
db_container:
image: mongo:latest
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
MONGO_INITDB_DATABASE: root-db
ports:
- 27017:27017
volumes:
- ./database/initdb.js:/docker-entrypoint-initdb.d/initdb.js:ro
- ./data:/data/db
Run Code Online (Sandbox Code Playgroud)
这是我的 initdb.js 文件
db.createUser(
{
user: "api-test",
pwd: "api-test",
roles: [
{
role: "readWrite",
db: "api-test"
}
]
}
);
Run Code Online (Sandbox Code Playgroud)
我只能看到 3 个数据库并且无法连接到api-test
数据库
如果缺少什么,请帮助我
我正在使用 Maven 插件 avro-maven-plugin (1.9.2) 从 AVRO-schema-file (avsc) 生成 Java 类。我定义一个日期字段如下:
{
"name": "inceptionDate",
"type": "int",
"logicalType": "date"
}
Run Code Online (Sandbox Code Playgroud)
我面临的问题是,它生成一个int而不是Date或LocalDate。
private int inceptionDate;
Run Code Online (Sandbox Code Playgroud)
pom.xml配置定义如下:
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.9.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<dateTimeLogicalTypeImplementation>JSR310</dateTimeLogicalTypeImplementation>
<sourceDirectory>${project.basedir}/src/main/resources/schema/</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/main/java/</outputDirectory>
<stringType>String</stringType>
<fieldVisibility>PRIVATE</fieldVisibility>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
有什么想法吗,有什么问题吗?
avro ×2
java ×2
apache-kafka ×1
avro-tools ×1
boolean ×1
default ×1
docker ×1
java-8 ×1
mongodb ×1
mongoose ×1