├── .asf.yaml ├── .gitignore ├── .travis.yml ├── NOTICE ├── README.md ├── bump-version.sh ├── client ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── rocketmq │ │ └── schema │ │ └── registry │ │ └── client │ │ ├── CachedSchemaRegistryClient.java │ │ ├── NormalSchemaRegistryClient.java │ │ ├── SchemaRegistryClient.java │ │ ├── SchemaRegistryClientFactory.java │ │ ├── config │ │ ├── AvroSerdeConfig.java │ │ ├── JsonSerdeConfig.java │ │ └── SerdeConfig.java │ │ ├── exceptions │ │ ├── RestClientException.java │ │ └── SerializationException.java │ │ ├── rest │ │ ├── JacksonMapper.java │ │ ├── RestService.java │ │ └── UrlBuilder.java │ │ ├── serde │ │ ├── Deserializer.java │ │ ├── Serializer.java │ │ ├── avro │ │ │ ├── AvroDeserializer.java │ │ │ ├── AvroSerializer.java │ │ │ ├── GenericAvroDeserializer.java │ │ │ ├── GenericAvroSerde.java │ │ │ ├── GenericAvroSerializer.java │ │ │ ├── ReflectionAvroDeserializer.java │ │ │ ├── ReflectionAvroSerde.java │ │ │ ├── ReflectionAvroSerializer.java │ │ │ ├── SpecificAvroDeserializer.java │ │ │ ├── SpecificAvroSerde.java │ │ │ └── SpecificAvroSerializer.java │ │ └── json │ │ │ ├── JsonDeserializer.java │ │ │ ├── JsonSerde.java │ │ │ └── JsonSerializer.java │ │ └── util │ │ └── HttpUtil.java │ └── test │ └── java │ └── org │ └── apache │ └── rocketmq │ └── schema │ └── registry │ └── client │ ├── CachedSchemaRegistryClientTest.java │ └── serde │ ├── Charge.java │ ├── Person.java │ ├── SkipSchemaRegistrySerdeTest.java │ ├── avro │ ├── GenericAvroSerdeTest.java │ ├── ReflectionAvroSerdeTest.java │ └── SpecificAvroSerdeTest.java │ └── json │ └── JsonSerdeTest.java ├── common ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── apache │ └── rocketmq │ └── schema │ └── registry │ └── common │ ├── QualifiedName.java │ ├── auth │ ├── AccessControlService.java │ └── DefaultAccessControlServiceImpl.java │ ├── constant │ └── SchemaConstants.java │ ├── context │ ├── RequestContext.java │ ├── RequestContextManager.java │ ├── StoragePluginContext.java │ └── StorageServiceContext.java │ ├── dto │ ├── AuditDto.java │ ├── BaseDto.java │ ├── DeleteSchemeResponse.java │ ├── Field.java │ ├── GetSchemaResponse.java │ ├── RegisterSchemaRequest.java │ ├── RegisterSchemaResponse.java │ ├── SchemaDetailDto.java │ ├── SchemaDto.java │ ├── SchemaMetaDto.java │ ├── SchemaRecordDto.java │ ├── SchemaStorageDto.java │ ├── SubjectDto.java │ ├── UpdateSchemaRequest.java │ └── UpdateSchemaResponse.java │ ├── exception │ ├── SchemaAuthorizedException.java │ ├── SchemaCompatibilityException.java │ ├── SchemaException.java │ ├── SchemaExistException.java │ └── SchemaNotFoundException.java │ ├── filter │ └── RequestFilter.java │ ├── json │ ├── JsonConverter.java │ └── JsonConverterImpl.java │ ├── model │ ├── AuditInfo.java │ ├── BaseInfo.java │ ├── Compatibility.java │ ├── Dependency.java │ ├── FieldInfo.java │ ├── PluginLoadState.java │ ├── SchemaDefinition.java │ ├── SchemaDetailInfo.java │ ├── SchemaEntity.java │ ├── SchemaInfo.java │ ├── SchemaMetaInfo.java │ ├── SchemaOperation.java │ ├── SchemaRecordInfo.java │ ├── SchemaStorageInfo.java │ ├── SchemaType.java │ ├── StorageType.java │ └── SubjectInfo.java │ ├── properties │ ├── AclProperties.java │ ├── CacheProperties.java │ ├── DependencyProperties.java │ ├── GlobalConfig.java │ ├── GlobalConfigImpl.java │ ├── SchemaProperties.java │ ├── ServiceProperties.java │ └── StorageProperties.java │ ├── storage │ ├── DefaultStorageServiceImpl.java │ ├── SpringStorageFactory.java │ ├── StorageFactory.java │ ├── StorageManager.java │ ├── StoragePlugin.java │ ├── StoragePluginManager.java │ ├── StorageService.java │ └── StorageServiceProxy.java │ └── utils │ ├── CommonUtil.java │ ├── ErrorMessage.java │ ├── IdGenerator.java │ ├── MemoryJavaFileManager.java │ ├── SnowFlakeIdGenerator.java │ └── StorageUtil.java ├── core ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── schema │ │ │ └── registry │ │ │ └── core │ │ │ ├── CoreApplication.java │ │ │ ├── api │ │ │ ├── RequestProcessor.java │ │ │ └── v1 │ │ │ │ └── SchemaController.java │ │ │ ├── compatibility │ │ │ ├── AvroSchemaValidator.java │ │ │ ├── CompatibilityChecker.java │ │ │ └── SchemaValidator.java │ │ │ ├── config │ │ │ ├── SchemaManagerConfig.java │ │ │ ├── SchemaPropertiesConfig.java │ │ │ ├── SchemaServiceConfig.java │ │ │ ├── SchemaUtilsConfig.java │ │ │ └── SwaggerConfig.java │ │ │ ├── dependency │ │ │ ├── ArtifactoryDependencyServiceImpl.java │ │ │ ├── DependencyHelper.java │ │ │ ├── DependencyService.java │ │ │ ├── DynamicCompileProvider.java │ │ │ └── DynamicJarsProvider.java │ │ │ ├── expection │ │ │ └── RequestExceptionHandler.java │ │ │ ├── package-info.java │ │ │ └── service │ │ │ ├── SchemaInitializationService.java │ │ │ ├── SchemaService.java │ │ │ ├── SchemaServiceImpl.java │ │ │ └── Service.java │ └── resources │ │ ├── application.properties │ │ └── template.pom │ └── test │ └── java │ └── org │ └── apache │ └── rocketmq │ └── schema │ └── registry │ └── core │ ├── CoreApplicationTests.java │ └── controller │ └── HelloControllerTest.java ├── docs ├── architecture.png ├── id.png └── subject.png ├── example ├── pom.xml └── src │ └── main │ ├── avro │ └── Charge.avsc │ └── java │ └── org │ └── apache │ └── rocketmq │ └── schema │ └── registry │ └── example │ ├── DeleteSchemaDemo.java │ ├── GetSchemaDemo.java │ ├── RegisterSchemaDemo.java │ ├── UpdateSchemaDemo.java │ └── serde │ ├── Charge.java │ ├── Person.java │ ├── avro │ ├── GenericAvroSerdeDemo.java │ ├── ReflectionAvroSerdeDemo.java │ └── SpecificAvroSerdeDemo.java │ └── json │ ├── JsonSerdeDemo.java │ └── JsonSerdeWithoutServerDemo.java ├── pom.xml ├── storage-jdbc ├── embedded-hazelcast-on-kubernetes.md ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── apache │ │ └── rocketmq │ │ └── schema │ │ └── registry │ │ └── storage │ │ └── jdbc │ │ ├── JdbcStorageFactory.java │ │ ├── JdbcStoragePlugin.java │ │ ├── JdbcStorageService.java │ │ ├── cache │ │ ├── LocalCache.java │ │ └── SubjectLocalCache.java │ │ ├── common │ │ ├── ExpressionBuilder.java │ │ ├── IdentifierRules.java │ │ └── Operator.java │ │ ├── configs │ │ ├── JdbcStorageConfigConstants.java │ │ └── ServiceConfig.java │ │ ├── dialect │ │ ├── ConnectionProvider.java │ │ ├── DatabaseDialect.java │ │ ├── DatabaseDialectProvider.java │ │ ├── DiscoverDialectFactory.java │ │ ├── GenericDatabaseDialect.java │ │ ├── TableId.java │ │ └── mysql │ │ │ └── MysqlDatabaseDialect.java │ │ ├── handler │ │ ├── IHandler.java │ │ └── SchemaHandler.java │ │ └── store │ │ ├── IMapStore.java │ │ ├── JdbcSchemaMapStore.java │ │ ├── JdbcSchemaMapStoreFactory.java │ │ ├── JdbcSubjectMapStore.java │ │ └── JdbcSubjectMapStoreFactory.java │ └── resources │ ├── META-INF │ └── services │ │ ├── org.apache.rocketmq.schema.registry.common.storage.StoragePlugin │ │ └── org.apache.rocketmq.schema.registry.storage.jdbc.dialect.DatabaseDialectProvider │ ├── hazelcast.yaml │ └── mysql-storage-ddl.sql ├── storage-rocketmq ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── apache │ │ └── rocketmq │ │ └── schema │ │ └── registry │ │ └── storage │ │ └── rocketmq │ │ ├── RocketmqClient.java │ │ ├── RocketmqStorageClient.java │ │ ├── RocketmqStorageClientImpl.java │ │ ├── RocketmqStorageFactory.java │ │ ├── RocketmqStoragePlugin.java │ │ ├── RocketmqStorageService.java │ │ ├── RocketmqStorageUtils.java │ │ ├── configs │ │ ├── ClientConfig.java │ │ ├── RocketmqConfigConstants.java │ │ └── ServiceConfig.java │ │ └── package-info.java │ └── resources │ ├── META-INF │ └── services │ │ └── org.apache.rocketmq.schema.registry.common.storage.StoragePlugin │ └── rocketmq.properties ├── style ├── copyright │ ├── Apache.xml │ └── profiles_settings.xml ├── rmq_checkstyle.xml └── rmq_codeStyle.xml ├── tools └── avro-tools-1.11.0.jar └── war ├── pom.xml └── src └── main └── java └── org └── apache └── rocketmq └── schema └── registry └── StorageWar.java /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | github: 17 | description: "Apache RocketMQ Schema Registry" 18 | features: 19 | # Enable issue management 20 | issues: true 21 | # Enable wiki 22 | wiki: true 23 | 24 | collaborators: 25 | - humkum 26 | - ferrirW 27 | - MatrixHB 28 | 29 | protected_branches: 30 | 31 | notifications: 32 | commits: commits@rocketmq.apache.org 33 | issues: commits@rocketmq.apache.org 34 | pullrequests: commits@rocketmq.apache.org 35 | jobs: commits@rocketmq.apache.org 36 | discussions: dev@rocketmq.apache.org 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/test/**/target/ 5 | *.log 6 | log/ 7 | log/* 8 | schema-registry/ 9 | 10 | ### STS ### 11 | .apt_generated 12 | .classpath 13 | .factorypath 14 | .project 15 | .settings 16 | .springBeans 17 | .sts4-cache 18 | 19 | ### IntelliJ IDEA ### 20 | .idea 21 | *.iws 22 | *.iml 23 | *.ipr 24 | 25 | ### NetBeans ### 26 | /nbproject/private/ 27 | /nbbuild/ 28 | /dist/ 29 | /nbdist/ 30 | /.nb-gradle/ 31 | build/ 32 | !**/src/main/**/build/ 33 | !**/src/test/**/build/ 34 | 35 | ### VS Code ### 36 | .vscode/ 37 | 38 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | 3 | language: java 4 | 5 | jdk: 6 | - oraclejdk8 7 | - oraclejdk9 8 | - oraclejdk11 9 | - openjdk8 10 | 11 | before_install: 12 | - echo 'MAVEN_OPTS="$MAVEN_OPTS -Xmx1024m -XX:MaxPermSize=512m -XX:+BytecodeVerificationLocal"' >> ~/.mavenrc 13 | - cat ~/.mavenrc 14 | - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export JAVA_HOME=$(/usr/libexec/java_home); fi 15 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then jdk_switcher use "$CUSTOM_JDK"; fi 16 | 17 | script: 18 | - travis_retry mvn -B clean apache-rat:check 19 | - travis_retry mvn -B clean install cobertura:cobertura 20 | 21 | after_success: 22 | - bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload' -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache RocketMQ 2 | Copyright 2016-2022 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /bump-version.sh: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | #!/usr/bin/env bash 17 | if [[ $1 == "" ]]; then 18 | echo "Usage: bump-version.sh version" 19 | exit -1 20 | fi 21 | 22 | version=$1 23 | mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$version 24 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/SchemaRegistryClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.client; 19 | 20 | import org.apache.rocketmq.schema.registry.client.rest.RestService; 21 | 22 | import java.util.Map; 23 | 24 | public class SchemaRegistryClientFactory { 25 | 26 | /** 27 | * @param baseUrl schema-registry base url (http://ip:port/schema-registry/v1) 28 | * @param map optional http request headers 29 | * @return 30 | */ 31 | public static SchemaRegistryClient newClient(String baseUrl, Map map) { 32 | RestService restService = null == map ? new RestService(baseUrl) : new RestService(baseUrl, map); 33 | return new CachedSchemaRegistryClient(restService); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/config/AvroSerdeConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.client.config; 18 | 19 | import java.util.Map; 20 | 21 | public class AvroSerdeConfig extends SerdeConfig { 22 | /** 23 | * use generic datum reader to deserialize genericRecord. 24 | */ 25 | public final static String USE_GENERIC_DATUM_READER = 26 | "use.generic.datum.reader"; 27 | public final static boolean USE_GENERIC_DATUM_READER_DEFAULT = false; 28 | 29 | public AvroSerdeConfig(Map configs) { 30 | this.configs = configs; 31 | } 32 | 33 | public boolean useGenericReader() { 34 | return (boolean) configs.getOrDefault(USE_GENERIC_DATUM_READER, USE_GENERIC_DATUM_READER_DEFAULT); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/config/JsonSerdeConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.client.config; 18 | 19 | import java.util.Map; 20 | 21 | public class JsonSerdeConfig extends SerdeConfig { 22 | public JsonSerdeConfig(Map configs) { 23 | this.configs = configs; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/config/SerdeConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.client.config; 18 | 19 | import java.util.Map; 20 | 21 | public class SerdeConfig { 22 | public final static String SKIP_SCHEMA_REGISTRY = 23 | "skip.schema.registry"; 24 | public final static boolean SKIP_SCHEMA_REGISTRY_DEFAULT = false; 25 | public final static String DESERIALIZE_TARGET_TYPE = 26 | "deserialize.target.type"; 27 | /** 28 | * use target version schema to serialize/deserialize without recordId. 29 | * version default null, will use the latest version. 30 | */ 31 | public final static String USE_TARGET_VERSION_SCHEMA = 32 | "use.target.version.schema"; 33 | 34 | public final static boolean USE_TARGET_VERSION_SCHEMA_DEFAULT = false; 35 | 36 | public final static String SCHEMA_TARGET_VERSION = 37 | "schema.target.version"; 38 | 39 | public final static long SCHEMA_TARGET_VERSION_DEFAULT = -1; 40 | 41 | protected Map configs; 42 | 43 | public boolean skipSchemaRegistry() { 44 | return (boolean) configs.getOrDefault(SKIP_SCHEMA_REGISTRY, SKIP_SCHEMA_REGISTRY_DEFAULT); 45 | } 46 | 47 | public Class deserializeTargetType() { 48 | return (Class) configs.get(DESERIALIZE_TARGET_TYPE); 49 | } 50 | 51 | public boolean useTargetVersionSchema() { 52 | return (boolean) configs.getOrDefault(USE_TARGET_VERSION_SCHEMA, USE_TARGET_VERSION_SCHEMA_DEFAULT); 53 | } 54 | 55 | public long schemaTargetVersion() { 56 | return (long) configs.getOrDefault(SCHEMA_TARGET_VERSION, SCHEMA_TARGET_VERSION_DEFAULT); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/exceptions/RestClientException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.client.exceptions; 19 | 20 | public class RestClientException extends Exception { 21 | private static final long serialVersionUID = 5169207805322753739L; 22 | 23 | private final int status; 24 | 25 | public RestClientException(int status, String detailMessage) { 26 | super(detailMessage); 27 | this.status = status; 28 | } 29 | 30 | public int getStatus() { 31 | return status; 32 | } 33 | 34 | public String getMessage() { 35 | return super.getMessage(); 36 | } 37 | } -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/exceptions/SerializationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.client.exceptions; 19 | 20 | public class SerializationException extends RuntimeException { 21 | public SerializationException(){} 22 | 23 | public SerializationException(String msg, Throwable cause) { 24 | super(msg, cause); 25 | } 26 | 27 | public SerializationException(String msg) { 28 | super(msg); 29 | } 30 | 31 | public SerializationException(Throwable cause) { 32 | super(cause); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/rest/JacksonMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.client.rest; 19 | 20 | import com.fasterxml.jackson.core.json.JsonReadFeature; 21 | import com.fasterxml.jackson.databind.ObjectMapper; 22 | import com.fasterxml.jackson.databind.json.JsonMapper; 23 | 24 | public class JacksonMapper { 25 | public static final ObjectMapper INSTANCE = JsonMapper.builder(). 26 | enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS).build(); 27 | } 28 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/serde/Deserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.client.serde; 19 | 20 | import java.io.Closeable; 21 | import java.util.Map; 22 | 23 | public interface Deserializer extends Closeable { 24 | default void configure(Map configs) {} 25 | 26 | T deserialize(String subject, byte[] bytes); 27 | 28 | default void close(){}; 29 | } 30 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/serde/Serializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.client.serde; 19 | 20 | import java.io.Closeable; 21 | import java.util.Map; 22 | 23 | public interface Serializer extends Closeable { 24 | 25 | default void configure(Map configs) {} 26 | 27 | byte[] serialize(String subject, T originMessage); 28 | 29 | default void close(){} 30 | } 31 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/serde/avro/GenericAvroDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.client.serde.avro; 18 | 19 | import org.apache.avro.Schema; 20 | import org.apache.avro.generic.GenericRecord; 21 | import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient; 22 | import org.apache.rocketmq.schema.registry.client.serde.Deserializer; 23 | 24 | import java.util.Map; 25 | 26 | public class GenericAvroDeserializer implements Deserializer { 27 | private final AvroDeserializer inner; 28 | 29 | public GenericAvroDeserializer() { 30 | this.inner = new AvroDeserializer<>(); 31 | } 32 | 33 | public GenericAvroDeserializer(final SchemaRegistryClient client) { 34 | this.inner = new AvroDeserializer<>(client); 35 | } 36 | 37 | @Override 38 | public void configure(final Map configs) { 39 | this.inner.configure(configs); 40 | } 41 | 42 | @Override 43 | public GenericRecord deserialize(String subject, byte[] bytes) { 44 | return this.inner.deserialize(subject, bytes); 45 | } 46 | 47 | public GenericRecord deserialize(String subject, byte[] bytes, Schema readerSchema) { 48 | return this.inner.deserialize(subject, bytes, readerSchema); 49 | } 50 | 51 | @Override 52 | public void close() { 53 | this.inner.close(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/serde/avro/GenericAvroSerde.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.client.serde.avro; 18 | 19 | import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | import java.util.Map; 24 | 25 | public class GenericAvroSerde implements Closeable { 26 | private final GenericAvroSerializer serializer; 27 | private final GenericAvroDeserializer deserializer; 28 | 29 | public GenericAvroSerde() { 30 | this.serializer = new GenericAvroSerializer(); 31 | this.deserializer = new GenericAvroDeserializer(); 32 | } 33 | 34 | public GenericAvroSerde(final SchemaRegistryClient client) { 35 | if (null == client) { 36 | throw new IllegalArgumentException("please initialize the schema registry client first"); 37 | } 38 | this.serializer = new GenericAvroSerializer(client); 39 | this.deserializer = new GenericAvroDeserializer(client); 40 | } 41 | 42 | public void configure(final Map configs) { 43 | this.serializer.configure(configs); 44 | this.deserializer.configure(configs); 45 | } 46 | 47 | public GenericAvroSerializer serializer() { 48 | return this.serializer; 49 | } 50 | 51 | public GenericAvroDeserializer deserializer() { 52 | return this.deserializer; 53 | } 54 | 55 | @Override 56 | public void close() throws IOException { 57 | this.serializer.close(); 58 | this.deserializer.close(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/serde/avro/GenericAvroSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.client.serde.avro; 18 | 19 | import org.apache.avro.generic.GenericRecord; 20 | import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient; 21 | import org.apache.rocketmq.schema.registry.client.serde.Serializer; 22 | 23 | import java.util.Map; 24 | 25 | public class GenericAvroSerializer implements Serializer { 26 | 27 | private final AvroSerializer inner; 28 | 29 | public GenericAvroSerializer() { 30 | this.inner = new AvroSerializer<>(); 31 | } 32 | 33 | public GenericAvroSerializer(final SchemaRegistryClient client) { 34 | this.inner = new AvroSerializer<>(client); 35 | } 36 | @Override 37 | public void configure(final Map configs) { 38 | this.inner.configure(configs); 39 | } 40 | 41 | @Override 42 | public byte[] serialize(final String subject, final GenericRecord record) { 43 | return this.inner.serialize(subject, record); 44 | } 45 | 46 | @Override 47 | public void close() { 48 | this.inner.close(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/serde/avro/ReflectionAvroSerde.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.client.serde.avro; 18 | 19 | import org.apache.avro.specific.SpecificRecord; 20 | import org.apache.rocketmq.schema.registry.client.serde.Deserializer; 21 | import org.apache.rocketmq.schema.registry.client.serde.Serializer; 22 | 23 | import java.io.Closeable; 24 | import java.io.IOException; 25 | import java.util.Map; 26 | 27 | public class ReflectionAvroSerde implements Closeable { 28 | private final ReflectionAvroSerializer serializer; 29 | private final ReflectionAvroDeserializer deserializer; 30 | 31 | public ReflectionAvroSerde() { 32 | this.serializer = new ReflectionAvroSerializer<>(); 33 | this.deserializer = new ReflectionAvroDeserializer<>(); 34 | } 35 | 36 | public Serializer serializer() { 37 | return this.serializer; 38 | } 39 | 40 | public Deserializer deserializer() { 41 | return this.deserializer; 42 | } 43 | 44 | public void configure(final Map configs) { 45 | this.serializer.configure(configs); 46 | this.deserializer.configure(configs); 47 | } 48 | 49 | @Override 50 | public void close() throws IOException { 51 | this.serializer.close(); 52 | this.deserializer.close(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/serde/avro/SpecificAvroDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.client.serde.avro; 18 | 19 | import org.apache.avro.Schema; 20 | import org.apache.avro.specific.SpecificRecord; 21 | import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient; 22 | import org.apache.rocketmq.schema.registry.client.serde.Deserializer; 23 | 24 | import java.util.Map; 25 | 26 | public class SpecificAvroDeserializer implements Deserializer { 27 | 28 | private final AvroDeserializer inner; 29 | 30 | public SpecificAvroDeserializer() { 31 | this.inner = new AvroDeserializer<>(); 32 | } 33 | 34 | public SpecificAvroDeserializer(final SchemaRegistryClient client) { 35 | this.inner = new AvroDeserializer<>(client); 36 | } 37 | 38 | @Override 39 | public void configure(final Map configs) { 40 | this.inner.configure(configs); 41 | } 42 | 43 | @SuppressWarnings("unchecked") 44 | @Override 45 | public T deserialize(String subject, byte[] bytes) { 46 | return (T) this.inner.deserialize(subject, bytes); 47 | } 48 | 49 | @SuppressWarnings("unchecked") 50 | public T deserialize(String subject, byte[] bytes, Schema readerSchema) { 51 | return (T) this.inner.deserialize(subject, bytes, readerSchema); 52 | } 53 | 54 | @Override 55 | public void close() { 56 | this.inner.close(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/serde/avro/SpecificAvroSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.client.serde.avro; 18 | 19 | import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient; 20 | import org.apache.rocketmq.schema.registry.client.serde.Serializer; 21 | 22 | import java.util.Map; 23 | 24 | public class SpecificAvroSerializer implements Serializer { 25 | 26 | private final AvroSerializer inner; 27 | 28 | public SpecificAvroSerializer() { 29 | this.inner = new AvroSerializer<>(); 30 | } 31 | 32 | public SpecificAvroSerializer(final SchemaRegistryClient client) { 33 | this.inner = new AvroSerializer<>(client); 34 | } 35 | 36 | @Override 37 | public void configure(final Map configs) { 38 | this.inner.configure(configs); 39 | } 40 | 41 | @Override 42 | public byte[] serialize(String subject, T record) { 43 | return this.inner.serialize(subject, record); 44 | } 45 | 46 | @Override 47 | public void close() { 48 | this.inner.close(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /client/src/main/java/org/apache/rocketmq/schema/registry/client/serde/json/JsonSerde.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.client.serde.json; 19 | 20 | import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient; 21 | 22 | import java.io.Closeable; 23 | import java.io.IOException; 24 | import java.util.Map; 25 | 26 | public class JsonSerde implements Closeable { 27 | private final JsonSerializer serializer; 28 | private final JsonDeserializer deserializer; 29 | 30 | public JsonSerde() { 31 | this.serializer = new JsonSerializer<>(); 32 | this.deserializer = new JsonDeserializer<>(); 33 | } 34 | 35 | public JsonSerde(SchemaRegistryClient registryClient) { 36 | this.serializer = new JsonSerializer<>(registryClient); 37 | this.deserializer = new JsonDeserializer<>(registryClient); 38 | } 39 | 40 | public void configure(final Map configs) { 41 | this.serializer.configure(configs); 42 | this.deserializer.configure(configs); 43 | } 44 | 45 | public JsonSerializer serializer() { 46 | return this.serializer; 47 | } 48 | 49 | public JsonDeserializer deserializer() { 50 | return this.deserializer; 51 | } 52 | 53 | @Override 54 | public void close() throws IOException { 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/rocketmq/schema/registry/client/serde/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.client.serde; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnore; 21 | import com.fasterxml.jackson.annotation.JsonPropertyOrder; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Builder; 24 | import lombok.Data; 25 | import lombok.NoArgsConstructor; 26 | 27 | import java.util.Objects; 28 | 29 | @Data 30 | @Builder 31 | @AllArgsConstructor 32 | @NoArgsConstructor 33 | @JsonPropertyOrder(alphabetic = true) 34 | public class Person { 35 | @JsonIgnore 36 | private Long id; 37 | private String name; 38 | private int age; 39 | 40 | @Override 41 | public boolean equals(Object o) { 42 | if (this == o) return true; 43 | if (o == null || getClass() != o.getClass()) return false; 44 | Person person = (Person) o; 45 | return age == person.age && Objects.equals(name, person.name); 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return Objects.hash(name, age); 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "Person{" + 56 | "name='" + name + '\'' + 57 | ", age=" + age + 58 | '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/rocketmq/schema/registry/client/serde/SkipSchemaRegistrySerdeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.client.serde; 18 | 19 | import org.apache.rocketmq.schema.registry.client.config.JsonSerdeConfig; 20 | import org.apache.rocketmq.schema.registry.client.serde.json.JsonSerde; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import java.io.IOException; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | public class SkipSchemaRegistrySerdeTest { 28 | 29 | @Test 30 | public void testJsonSerde() { 31 | Person person = new Person(1L, "name", 18); 32 | System.out.printf("person before serialize is %s\n", person); 33 | 34 | try(JsonSerde jsonSerde = new JsonSerde<>()) { 35 | Map configs = new HashMap<>(); 36 | configs.put(JsonSerdeConfig.SKIP_SCHEMA_REGISTRY, true); 37 | configs.put(JsonSerdeConfig.DESERIALIZE_TARGET_TYPE, Person.class); 38 | jsonSerde.configure(configs); 39 | byte[] bytes = jsonSerde.serializer().serialize("TopicTest", person); 40 | 41 | Person person1 = jsonSerde.deserializer().deserialize("TopicTest", bytes); 42 | System.out.printf("after deserialize new person is %s\n", person1); 43 | System.out.printf("person == person1 : %b\n", person1.equals(person)); 44 | } catch (IOException e) { 45 | System.out.println("serde shutdown failed"); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/rocketmq/schema/registry/client/serde/avro/ReflectionAvroSerdeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.client.serde.avro; 18 | 19 | import org.apache.rocketmq.schema.registry.client.config.AvroSerdeConfig; 20 | import org.apache.rocketmq.schema.registry.client.serde.Charge; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import java.io.IOException; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | import static org.assertj.core.api.Assertions.assertThat; 28 | 29 | public class ReflectionAvroSerdeTest { 30 | @Test 31 | public void testReflectionAvroSerde() { 32 | Charge charge = new Charge("specific", 100.0); 33 | Map configs = new HashMap<>(); 34 | configs.put(AvroSerdeConfig.DESERIALIZE_TARGET_TYPE, charge.getClass()); 35 | try (ReflectionAvroSerde serde = new ReflectionAvroSerde()) { 36 | //serialize 37 | serde.configure(configs); 38 | 39 | byte[] bytes = serde.serializer().serialize("TopicTest", charge); 40 | //deserialize 41 | Charge charge1 = (Charge) serde.deserializer().deserialize("TopicTest", bytes); 42 | assertThat(charge1).isEqualTo(charge); 43 | } catch (IOException e) { 44 | System.out.println("serde shutdown failed"); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/auth/AccessControlService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.auth; 19 | 20 | import org.apache.rocketmq.schema.registry.common.exception.SchemaAuthorizedException; 21 | import org.apache.rocketmq.schema.registry.common.model.SchemaOperation; 22 | 23 | public interface AccessControlService { 24 | 25 | default void checkPermission( 26 | final String role, 27 | final String resource, 28 | final SchemaOperation operation 29 | ) throws SchemaAuthorizedException { 30 | // default do nothing 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/constant/SchemaConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.constant; 19 | 20 | public class SchemaConstants { 21 | public static final int SCHEMA_RECORD_ID_LENGTH = 8; 22 | public static final char SUBJECT_SEPARATOR = '/'; 23 | public static final int SCHEMA_VERSION_BITS = 14; 24 | } 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/context/RequestContextManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.context; 19 | 20 | public class RequestContextManager { 21 | 22 | private static final ThreadLocal CONTEXTS = new ThreadLocal<>(); 23 | 24 | private RequestContextManager() { 25 | } 26 | 27 | public static void removeContext() { 28 | CONTEXTS.remove(); 29 | } 30 | 31 | public static RequestContext getContext() { 32 | RequestContext result = CONTEXTS.get(); 33 | if (result == null) { 34 | result = new RequestContext(); 35 | putContext(result); 36 | } 37 | return result; 38 | } 39 | 40 | public static void putContext(final RequestContext context) { 41 | CONTEXTS.set(context); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/context/StoragePluginContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.context; 19 | 20 | import lombok.AllArgsConstructor; 21 | import lombok.Data; 22 | import org.apache.rocketmq.schema.registry.common.properties.GlobalConfig; 23 | 24 | @Data 25 | @AllArgsConstructor 26 | public class StoragePluginContext { 27 | 28 | /** 29 | * global config 30 | */ 31 | private final GlobalConfig config; 32 | } 33 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/context/StorageServiceContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.context; 19 | 20 | import lombok.AllArgsConstructor; 21 | import lombok.Data; 22 | import lombok.NoArgsConstructor; 23 | 24 | @Data 25 | @AllArgsConstructor 26 | @NoArgsConstructor 27 | public class StorageServiceContext { 28 | private long timestamp; 29 | private String userName; 30 | } 31 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/AuditDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModelProperty; 21 | import java.util.Date; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Builder; 24 | import lombok.Data; 25 | import lombok.EqualsAndHashCode; 26 | import lombok.NoArgsConstructor; 27 | 28 | @Data 29 | @EqualsAndHashCode(callSuper = false) 30 | @Builder 31 | @AllArgsConstructor 32 | @NoArgsConstructor 33 | public class AuditDto extends BaseDto { 34 | private static final long serialVersionUID = -2306105985602090836L; 35 | 36 | @ApiModelProperty(value = "Description of this resource") 37 | private String desc; 38 | 39 | @ApiModelProperty(value = "The user who creates the resource") 40 | private String createdBy; 41 | 42 | @ApiModelProperty(value = "The time of this resource was created") 43 | private Date createdTime; 44 | 45 | @ApiModelProperty(value = "The user who updates the resource") 46 | private String lastModifiedBy; 47 | 48 | @ApiModelProperty(value = "The time of this resource was updated") 49 | private Date lastModifiedTime; 50 | } 51 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/BaseDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.common.dto; 18 | 19 | import java.io.Serializable; 20 | import org.apache.rocketmq.schema.registry.common.json.JsonConverter; 21 | import org.apache.rocketmq.schema.registry.common.json.JsonConverterImpl; 22 | 23 | /** 24 | * Base class for all DTOs, and all DTOs should be READ-ONLY. 25 | */ 26 | public abstract class BaseDto implements Serializable { 27 | protected static final JsonConverter JSON_CONVERTER = new JsonConverterImpl(); 28 | 29 | /** 30 | * {@inheritDoc} 31 | */ 32 | @Override 33 | public String toString() { 34 | return JSON_CONVERTER.toString(this); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/DeleteSchemeResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModelProperty; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | import lombok.NoArgsConstructor; 26 | 27 | @Data 28 | @EqualsAndHashCode(callSuper = false) 29 | @Builder 30 | @NoArgsConstructor 31 | @AllArgsConstructor 32 | public class DeleteSchemeResponse extends BaseDto { 33 | private static final long serialVersionUID = 5487372544128191038L; 34 | 35 | @ApiModelProperty(value = "Deleted schema record unique id", required = true) 36 | private long recordId; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/Field.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModel; 21 | import io.swagger.annotations.ApiModelProperty; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Builder; 24 | import lombok.Data; 25 | import lombok.EqualsAndHashCode; 26 | import lombok.NoArgsConstructor; 27 | 28 | @ApiModel(description = "Schema field/column information") 29 | @SuppressWarnings("unused") 30 | @Data 31 | @EqualsAndHashCode(callSuper = false) 32 | @NoArgsConstructor 33 | @Builder 34 | @AllArgsConstructor 35 | public class Field extends BaseDto { 36 | private static final long serialVersionUID = -8336499483006254487L; 37 | 38 | @ApiModelProperty(value = "Position of the field") 39 | private Integer pos; 40 | 41 | @ApiModelProperty(value = "Name of the field", required = true) 42 | private String name; 43 | 44 | @ApiModelProperty(value = "Type of the field", required = true) 45 | private String type; 46 | 47 | @ApiModelProperty(value = "Comment of the field") 48 | private String comment; 49 | 50 | @ApiModelProperty(value = "Can the field be null, default is true") 51 | private Boolean isNullable = true; 52 | 53 | @ApiModelProperty(value = "Default value of the field") 54 | private String defaultValue; 55 | 56 | @ApiModelProperty(value = "This filed sorted type, like: ascending, descending, ignore") 57 | private String sortType; 58 | 59 | @ApiModelProperty(value = "Extra info of the field") 60 | private String extra; 61 | } 62 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/RegisterSchemaRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModelProperty; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | import lombok.NoArgsConstructor; 26 | import org.apache.rocketmq.schema.registry.common.model.Compatibility; 27 | import org.apache.rocketmq.schema.registry.common.model.SchemaType; 28 | 29 | @Data 30 | @EqualsAndHashCode(callSuper = false) 31 | @Builder 32 | @NoArgsConstructor 33 | @AllArgsConstructor 34 | public class RegisterSchemaRequest extends BaseDto { 35 | private static final long serialVersionUID = 7890248374919863930L; 36 | 37 | @ApiModelProperty(value = "First IDL of this schema", example = "{\"type\": \"string\"}", required = true) 38 | private String schemaIdl; 39 | 40 | @ApiModelProperty(value = "Schema type") 41 | private SchemaType schemaType = SchemaType.AVRO; 42 | 43 | @ApiModelProperty(value = "Schema owner", example = "li") 44 | private String owner = ""; 45 | 46 | @ApiModelProperty(value = "Schema compatibility") 47 | private Compatibility compatibility = Compatibility.BACKWARD; 48 | 49 | @ApiModelProperty(value = "Schema description", example = "my first schema") 50 | private String desc = ""; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/RegisterSchemaResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModelProperty; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | import lombok.NoArgsConstructor; 26 | 27 | @Data 28 | @EqualsAndHashCode(callSuper = false) 29 | @Builder 30 | @NoArgsConstructor 31 | @AllArgsConstructor 32 | public class RegisterSchemaResponse extends BaseDto { 33 | private static final long serialVersionUID = 5961720146684473323L; 34 | 35 | @ApiModelProperty(value = "Schema record unique id", required = true) 36 | private long recordId; 37 | 38 | @ApiModelProperty(value = "Version of this schema record") 39 | private long version; 40 | } 41 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/SchemaDetailDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModelProperty; 21 | import java.util.List; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Builder; 24 | import lombok.Data; 25 | import lombok.EqualsAndHashCode; 26 | import lombok.NoArgsConstructor; 27 | 28 | @Data 29 | @EqualsAndHashCode(callSuper = false) 30 | @Builder 31 | @AllArgsConstructor 32 | @NoArgsConstructor 33 | public class SchemaDetailDto extends BaseDto { 34 | private static final long serialVersionUID = -2397649152515693952L; 35 | 36 | @ApiModelProperty(value = "Schema record with different version", required = true) 37 | private List schemaRecords; 38 | // private Map props = ; 39 | } 40 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/SchemaDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModel; 21 | import io.swagger.annotations.ApiModelProperty; 22 | import java.util.Map; 23 | import lombok.AllArgsConstructor; 24 | import lombok.Builder; 25 | import lombok.Data; 26 | import lombok.EqualsAndHashCode; 27 | import lombok.NoArgsConstructor; 28 | import org.apache.rocketmq.schema.registry.common.QualifiedName; 29 | 30 | @ApiModel(description = "Schema detail information") 31 | @Data 32 | @EqualsAndHashCode(callSuper = false) 33 | @Builder 34 | @NoArgsConstructor 35 | @AllArgsConstructor 36 | public class SchemaDto extends BaseDto { 37 | private static final long serialVersionUID = -441512542075118183L; 38 | 39 | @ApiModelProperty(value = "The qualified name of this entity") 40 | private QualifiedName qualifiedName; 41 | 42 | @ApiModelProperty(value = "Information about schema changes") 43 | private AuditDto audit; 44 | 45 | @ApiModelProperty(value = "Information about schema meta", required = true) 46 | private SchemaMetaDto meta; 47 | 48 | @ApiModelProperty(value = "Information about schema details", required = true) 49 | private SchemaDetailDto details; 50 | 51 | @ApiModelProperty(value = "Information about schema persistence") 52 | private SchemaStorageDto storage; 53 | 54 | @ApiModelProperty(value = "Extra schema parameters") 55 | private Map extras; 56 | 57 | public SchemaDto setQualifiedName(QualifiedName qualifiedName) { 58 | this.qualifiedName = qualifiedName; 59 | return this; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/SchemaMetaDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModelProperty; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | import lombok.NoArgsConstructor; 26 | import org.apache.rocketmq.schema.registry.common.model.Compatibility; 27 | import org.apache.rocketmq.schema.registry.common.model.SchemaType; 28 | 29 | @Data 30 | @EqualsAndHashCode(callSuper = false) 31 | @Builder 32 | @AllArgsConstructor 33 | @NoArgsConstructor 34 | public class SchemaMetaDto extends BaseDto { 35 | private static final long serialVersionUID = -4377140936300258473L; 36 | 37 | @ApiModelProperty(value = "The type of the schema") 38 | private SchemaType type; 39 | 40 | @ApiModelProperty(value = "The tenant of the schema") 41 | private String tenant; 42 | 43 | @ApiModelProperty(value = "The namespace of the schema") 44 | private String namespace; 45 | 46 | @ApiModelProperty(value = "The struct name of the schema") 47 | private String schemaName; 48 | 49 | @ApiModelProperty(value = "Compatibility of the schema") 50 | private Compatibility compatibility; 51 | 52 | @ApiModelProperty(value = "Owner of the schema") 53 | private String owner; 54 | 55 | @ApiModelProperty(value = "The unique id of the schema") 56 | private long uniqueId; 57 | } 58 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/SchemaRecordDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModelProperty; 21 | import java.util.List; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Builder; 24 | import lombok.Data; 25 | import lombok.EqualsAndHashCode; 26 | import lombok.NoArgsConstructor; 27 | import org.apache.rocketmq.schema.registry.common.model.Dependency; 28 | import org.apache.rocketmq.schema.registry.common.model.SchemaType; 29 | 30 | @Data 31 | @EqualsAndHashCode(callSuper = false) 32 | @Builder 33 | @AllArgsConstructor 34 | @NoArgsConstructor 35 | public class SchemaRecordDto { 36 | 37 | @ApiModelProperty(value = "Schema name", required = true) 38 | private String schema; 39 | 40 | @ApiModelProperty(value = "Schema unique id", required = true) 41 | private long schemaId; 42 | 43 | @ApiModelProperty(value = "Version of this schema record") 44 | private long version; 45 | 46 | @ApiModelProperty(value = "Schema record unique id") 47 | private long recordId; 48 | 49 | @ApiModelProperty(value = "IDL of this schema record", required = true) 50 | private String idl; 51 | 52 | @ApiModelProperty(value = "Dependency of this schema record") 53 | private Dependency dependency; 54 | 55 | @ApiModelProperty(value = "Subjects of this record binding") 56 | private List subjects; 57 | 58 | @ApiModelProperty(value = "Schema type") 59 | private SchemaType type; 60 | } 61 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/SchemaStorageDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModelProperty; 21 | import java.util.Map; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Builder; 24 | import lombok.Data; 25 | import lombok.EqualsAndHashCode; 26 | import lombok.NoArgsConstructor; 27 | import org.apache.rocketmq.schema.registry.common.model.Dependency; 28 | 29 | @Data 30 | @EqualsAndHashCode(callSuper = false) 31 | @Builder 32 | @AllArgsConstructor 33 | @NoArgsConstructor 34 | public class SchemaStorageDto extends BaseDto { 35 | private static final long serialVersionUID = -3298771958844258686L; 36 | 37 | @ApiModelProperty(value = "Protocol of the schema serializer / deserializer") 38 | private String serdeProtocol; 39 | 40 | @ApiModelProperty(value = "Uploaded dependency library of the schema") 41 | private Dependency dependency; 42 | 43 | @ApiModelProperty(value = "Extra storage parameters") 44 | private Map serdeInfo; 45 | 46 | @ApiModelProperty(value = "URI of the schema") 47 | private String uri; 48 | } 49 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/SubjectDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModelProperty; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | import lombok.NoArgsConstructor; 26 | 27 | @Data 28 | @EqualsAndHashCode(callSuper = false) 29 | @Builder 30 | @AllArgsConstructor 31 | @NoArgsConstructor 32 | public class SubjectDto { 33 | 34 | @ApiModelProperty(value = "Cluster of this subject", required = true) 35 | private String cluster; 36 | 37 | @ApiModelProperty(value = "Tenant of this subject", required = true) 38 | private String tenant; 39 | 40 | @ApiModelProperty(value = "Name of this subject", required = true) 41 | private String subject; 42 | } 43 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/UpdateSchemaRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModelProperty; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | import lombok.NoArgsConstructor; 26 | 27 | @Data 28 | @EqualsAndHashCode(callSuper = false) 29 | @Builder 30 | @NoArgsConstructor 31 | @AllArgsConstructor 32 | public class UpdateSchemaRequest extends BaseDto { 33 | private static final long serialVersionUID = 2966846398643703675L; 34 | 35 | @ApiModelProperty(value = "Update IDL of this schema", example = "{\"type\": \"int\"}", required = true) 36 | private String schemaIdl; 37 | 38 | @ApiModelProperty(value = "Schema owner", example = "li") 39 | private String owner = ""; 40 | 41 | @ApiModelProperty(value = "Schema description", example = "update schema") 42 | private String desc = ""; 43 | } 44 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/UpdateSchemaResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.dto; 19 | 20 | import io.swagger.annotations.ApiModelProperty; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | import lombok.NoArgsConstructor; 26 | 27 | @Data 28 | @EqualsAndHashCode(callSuper = false) 29 | @Builder 30 | @NoArgsConstructor 31 | @AllArgsConstructor 32 | public class UpdateSchemaResponse extends BaseDto { 33 | private static final long serialVersionUID = 822296169833367618L; 34 | 35 | @ApiModelProperty(value = "Schema record unique id", required = true) 36 | private long recordId; 37 | 38 | @ApiModelProperty(value = "Version of this schema record") 39 | private long version; 40 | } 41 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/exception/SchemaAuthorizedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.exception; 19 | 20 | import lombok.Getter; 21 | 22 | @Getter 23 | public class SchemaAuthorizedException extends SchemaException { 24 | private static final long serialVersionUID = 204882338833006991L; 25 | 26 | private final int errorCode = 40101; 27 | 28 | public SchemaAuthorizedException(final String tenant, final String schemaName) { 29 | this(String.format("Schema: %s/%s not found, please check your configuration.", tenant, schemaName)); 30 | } 31 | 32 | public SchemaAuthorizedException(final String msg) { 33 | super(msg); 34 | } 35 | 36 | public SchemaAuthorizedException(final String msg, final Throwable cause) { 37 | super(msg, cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/exception/SchemaCompatibilityException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.exception; 19 | 20 | import lombok.Getter; 21 | import org.apache.rocketmq.schema.registry.common.QualifiedName; 22 | 23 | @Getter 24 | public class SchemaCompatibilityException extends SchemaException { 25 | private static final long serialVersionUID = 2602020608319903212L; 26 | 27 | private final int errorCode = 40901; 28 | 29 | public SchemaCompatibilityException(final QualifiedName qualifiedName) { 30 | this(String.format("Schema: %s validate failed.", qualifiedName)); 31 | } 32 | 33 | public SchemaCompatibilityException(final String msg) { 34 | super(msg); 35 | } 36 | 37 | public SchemaCompatibilityException(final String msg, final Throwable cause) { 38 | super(msg, cause); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/exception/SchemaException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.exception; 19 | 20 | import lombok.Getter; 21 | 22 | @Getter 23 | public class SchemaException extends RuntimeException { 24 | 25 | private final int errorCode = 50001; 26 | 27 | /** 28 | * Constructor. 29 | */ 30 | public SchemaException() { 31 | super(); 32 | } 33 | 34 | /** 35 | * Constructor. 36 | * 37 | * @param msg The error message 38 | */ 39 | public SchemaException(final String msg) { 40 | super(msg); 41 | } 42 | 43 | /** 44 | * Constructor. 45 | * 46 | * @param msg The error message 47 | * @param cause The cause of the error 48 | */ 49 | public SchemaException(final String msg, final Throwable cause) { 50 | super(msg, cause); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/exception/SchemaExistException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.exception; 19 | 20 | import lombok.Getter; 21 | import org.apache.rocketmq.schema.registry.common.QualifiedName; 22 | 23 | @Getter 24 | public class SchemaExistException extends SchemaException { 25 | private static final long serialVersionUID = -9177284523006645052L; 26 | 27 | private final int errorCode = 40401; 28 | 29 | public SchemaExistException(final QualifiedName qualifiedName) { 30 | this(String.format("Schema: %s is exist, please check your configuration.", qualifiedName.schemaFullName())); 31 | } 32 | 33 | public SchemaExistException(final String msg) { 34 | super(msg); 35 | } 36 | 37 | public SchemaExistException(final String msg, final Throwable cause) { 38 | super(msg, cause); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/exception/SchemaNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.exception; 19 | 20 | import lombok.Getter; 21 | import org.apache.rocketmq.schema.registry.common.QualifiedName; 22 | 23 | @Getter 24 | public class SchemaNotFoundException extends SchemaException { 25 | private static final long serialVersionUID = 554251224980156176L; 26 | 27 | private final int errorCode = 40402; 28 | 29 | public SchemaNotFoundException(final QualifiedName qualifiedName) { 30 | this(String.format("Schema: %s not found, please check your configuration.", qualifiedName)); 31 | } 32 | 33 | public SchemaNotFoundException(final String msg) { 34 | super(msg); 35 | } 36 | 37 | public SchemaNotFoundException(final String msg, final Throwable cause) { 38 | super(msg, cause); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/AuditInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | import java.io.Serializable; 21 | import java.util.Date; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Builder; 24 | import lombok.Data; 25 | import lombok.EqualsAndHashCode; 26 | import lombok.NoArgsConstructor; 27 | import org.apache.commons.lang3.StringUtils; 28 | 29 | @Data 30 | @EqualsAndHashCode(callSuper = false) 31 | @Builder 32 | @AllArgsConstructor 33 | @NoArgsConstructor 34 | public class AuditInfo implements Serializable { 35 | private static final long serialVersionUID = 2258089775496856662L; 36 | 37 | private String desc; 38 | private String createdBy; 39 | private Date createdTime; 40 | private String lastModifiedBy; 41 | private Date lastModifiedTime; 42 | 43 | public void createBy(String user, String desc) { 44 | this.desc = desc; 45 | this.createdBy = user; 46 | this.lastModifiedBy = user; 47 | this.createdTime = this.lastModifiedTime = new Date(System.currentTimeMillis()); 48 | } 49 | 50 | public void updateBy(String user, String desc) { 51 | if (StringUtils.isNotBlank(user)) { 52 | this.lastModifiedBy = user; 53 | } 54 | if (StringUtils.isNotBlank(desc)) { 55 | this.desc = desc; 56 | } 57 | this.lastModifiedTime = new Date(System.currentTimeMillis()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/BaseInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | import java.io.Serializable; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Data; 23 | import lombok.NoArgsConstructor; 24 | import org.apache.rocketmq.schema.registry.common.QualifiedName; 25 | 26 | @AllArgsConstructor 27 | @NoArgsConstructor 28 | @Data 29 | public class BaseInfo implements Serializable { 30 | private static final long serialVersionUID = 3058601529800238252L; 31 | 32 | private QualifiedName qualifiedName; 33 | 34 | private AuditInfo audit; 35 | 36 | public String schemaFullName() { 37 | return qualifiedName.schemaFullName(); 38 | } 39 | 40 | public String subjectFullName() { 41 | return qualifiedName.subjectFullName(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/Compatibility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | public enum Compatibility { 21 | NONE(1), 22 | BACKWARD(2), 23 | BACKWARD_TRANSITIVE(3), 24 | FORWARD(4), 25 | FORWARD_TRANSITIVE(5), 26 | FULL(6), 27 | FULL_TRANSITIVE(7); 28 | 29 | private final int value; 30 | 31 | Compatibility(int value) { 32 | this.value = value; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/Dependency.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | import java.io.Serializable; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Data; 24 | import lombok.NoArgsConstructor; 25 | 26 | @Data 27 | @Builder 28 | @AllArgsConstructor 29 | @NoArgsConstructor 30 | public class Dependency implements Serializable { 31 | private static final long serialVersionUID = -5947555406026133852L; 32 | 33 | private String groupId; 34 | private String artifactId; 35 | private String version; 36 | 37 | @Override 38 | public String toString() { 39 | final StringBuilder sb = new StringBuilder("{"); 40 | sb.append("\"groupId\":\"") 41 | .append(groupId).append('\"'); 42 | sb.append(",\"artifactId\":\"") 43 | .append(artifactId).append('\"'); 44 | sb.append(",\"version\":\"") 45 | .append(version).append('\"'); 46 | sb.append('}'); 47 | return sb.toString(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/FieldInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | import java.io.Serializable; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Data; 23 | import lombok.NoArgsConstructor; 24 | 25 | @AllArgsConstructor 26 | @NoArgsConstructor 27 | @Data 28 | public class FieldInfo implements Serializable { 29 | private static final long serialVersionUID = -7630383008028496477L; 30 | 31 | private Integer pos; 32 | private String name; 33 | private String type; 34 | private String comment; 35 | private Boolean isNullable; 36 | private Integer size; 37 | private String defaultValue; 38 | private Boolean isSortable; 39 | private String sortType; 40 | private String extra; 41 | } 42 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/PluginLoadState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | public enum PluginLoadState { 21 | INIT, 22 | LOADING, 23 | LOADED, 24 | STARTING, 25 | STARTED 26 | } 27 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/SchemaDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | public class SchemaDefinition { 21 | } 22 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/SchemaDetailInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | import java.io.Serializable; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import lombok.AllArgsConstructor; 24 | import lombok.Data; 25 | import lombok.NoArgsConstructor; 26 | import org.apache.rocketmq.schema.registry.common.exception.SchemaException; 27 | 28 | @Data 29 | @NoArgsConstructor 30 | @AllArgsConstructor 31 | public class SchemaDetailInfo implements Serializable { 32 | private static final long serialVersionUID = 3113021009662503334L; 33 | 34 | private List schemaRecords = new ArrayList<>(); 35 | 36 | public SchemaDetailInfo(SchemaRecordInfo firstSchemaRecord) { 37 | this.schemaRecords.add(firstSchemaRecord); 38 | } 39 | 40 | public SchemaRecordInfo lastRecord() { 41 | if (schemaRecords == null || schemaRecords.isEmpty()) { 42 | throw new SchemaException("Schema record could not been empty"); 43 | } 44 | return schemaRecords.get(schemaRecords.size() - 1); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/SchemaEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | import java.io.Serializable; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | import lombok.NoArgsConstructor; 26 | 27 | @Deprecated 28 | @Data 29 | @EqualsAndHashCode(callSuper = false) 30 | @Builder 31 | @NoArgsConstructor 32 | @AllArgsConstructor 33 | public class SchemaEntity implements Serializable { 34 | private static final long serialVersionUID = 3371325175580091718L; 35 | 36 | private SchemaMetaInfo meta; 37 | private SchemaRecordInfo record; 38 | private SchemaStorageInfo storage; 39 | } 40 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/SchemaMetaInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | import java.io.Serializable; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | import lombok.NoArgsConstructor; 26 | 27 | @Data 28 | @EqualsAndHashCode(callSuper = false) 29 | @Builder 30 | @NoArgsConstructor 31 | @AllArgsConstructor 32 | public class SchemaMetaInfo implements Serializable { 33 | private static final long serialVersionUID = -7872862344708837525L; 34 | 35 | private SchemaType type; 36 | private String tenant; 37 | private String namespace; 38 | private String schemaName; 39 | private Compatibility compatibility; 40 | private String owner; 41 | private long uniqueId; 42 | } 43 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/SchemaOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | public enum SchemaOperation { 21 | 22 | /** 23 | * Operation type: register. 24 | */ 25 | REGISTER, 26 | /** 27 | * Operation type: delete. 28 | */ 29 | DELETE, 30 | /** 31 | * Operation type: update. 32 | */ 33 | UPDATE, 34 | /** 35 | * Operation type: get. 36 | */ 37 | GET 38 | } 39 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/SchemaRecordInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | import java.io.Serializable; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import lombok.AllArgsConstructor; 24 | import lombok.Data; 25 | import lombok.NoArgsConstructor; 26 | import org.apache.rocketmq.schema.registry.common.exception.SchemaException; 27 | 28 | @Data 29 | @NoArgsConstructor 30 | @AllArgsConstructor 31 | public class SchemaRecordInfo implements Serializable { 32 | private static final long serialVersionUID = 6215296681034788729L; 33 | 34 | private String schema; 35 | private long schemaId; 36 | private long version = 1L; 37 | private String idl; 38 | private Dependency dependency; 39 | private List subjects = new ArrayList<>(); 40 | private SchemaType type; 41 | // private List fields; 42 | 43 | public void bindSubject(final SubjectInfo subjectInfo) { 44 | getSubjects().add(subjectInfo); 45 | } 46 | 47 | public void unbindSubject(final SubjectInfo subjectInfo) { 48 | getSubjects().remove(subjectInfo); 49 | } 50 | 51 | public SubjectInfo lastBindSubject() { 52 | if (getSubjects() == null) { 53 | throw new SchemaException("Schema record haven't bind any subject"); 54 | } 55 | return getSubjects().get(subjects.size() - 1); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/SchemaStorageInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | import java.io.Serializable; 21 | import java.util.Map; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Builder; 24 | import lombok.Data; 25 | import lombok.EqualsAndHashCode; 26 | import lombok.NoArgsConstructor; 27 | 28 | @Data 29 | @EqualsAndHashCode(callSuper = false) 30 | @Builder 31 | @NoArgsConstructor 32 | @AllArgsConstructor 33 | public class SchemaStorageInfo implements Serializable { 34 | private static final long serialVersionUID = -6655281552098217740L; 35 | 36 | private String serdeProtocol; 37 | private String serializationLib; 38 | private Map serdeInfo; 39 | private String uri; 40 | } 41 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/SchemaType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | public enum SchemaType { 21 | 22 | /** 23 | * Avro type 24 | */ 25 | AVRO(1), 26 | /** 27 | * Protobuf type 28 | */ 29 | PROTOBUF(2), 30 | /** 31 | * Thrift type 32 | */ 33 | THRIFT(3), 34 | /** 35 | * Json type 36 | */ 37 | JSON(4), 38 | /** 39 | * Text type for reserved 40 | */ 41 | TEXT(5), 42 | /** 43 | * Binlog type for reserved 44 | */ 45 | BINLOG(6); 46 | 47 | private final int value; 48 | 49 | SchemaType(final int value) { 50 | this.value = value; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/StorageType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | public enum StorageType { 21 | 22 | /** 23 | * Rocketmq type 24 | */ 25 | ROCKETMQ(1), 26 | /** 27 | * Jdbc type 28 | */ 29 | JDBC(2); 30 | 31 | private final int value; 32 | 33 | StorageType(final int value) { 34 | this.value = value; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/model/SubjectInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.model; 19 | 20 | import java.io.Serializable; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | import lombok.NoArgsConstructor; 26 | import org.apache.rocketmq.schema.registry.common.constant.SchemaConstants; 27 | 28 | @Data 29 | @EqualsAndHashCode(callSuper = false) 30 | @Builder 31 | @AllArgsConstructor 32 | @NoArgsConstructor 33 | public class SubjectInfo implements Serializable { 34 | private static final long serialVersionUID = -92808722007777844L; 35 | 36 | private String cluster; 37 | private String tenant; 38 | private String subject; 39 | 40 | public String fullName() { 41 | return cluster + SchemaConstants.SUBJECT_SEPARATOR + tenant 42 | + SchemaConstants.SUBJECT_SEPARATOR + subject; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | final StringBuilder sb = new StringBuilder("{"); 48 | sb.append("\"cluster\":\"") 49 | .append(cluster).append('\"'); 50 | sb.append("\"tenant\":\"") 51 | .append(tenant).append('\"'); 52 | sb.append(",\"subject\":\"") 53 | .append(subject).append('\"'); 54 | sb.append('}'); 55 | return sb.toString(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/properties/CacheProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.properties; 19 | 20 | import lombok.Data; 21 | 22 | @Data 23 | public class CacheProperties { 24 | private boolean enabled; 25 | private long ttl; 26 | } 27 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/properties/DependencyProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.properties; 19 | 20 | import lombok.Data; 21 | 22 | @Data 23 | public class DependencyProperties { 24 | private boolean uploadEnabled; 25 | private String compilePath; 26 | private String jdkPath; 27 | private String localRepositoryPath; 28 | private String repositoryUrl; 29 | private String username; 30 | private String password; 31 | private String template = "core/src/main/resources/template.pom"; 32 | } 33 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/properties/SchemaProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.properties; 19 | 20 | import lombok.Data; 21 | import lombok.NonNull; 22 | 23 | @Data 24 | public class SchemaProperties { 25 | 26 | @NonNull 27 | private CacheProperties cache = new CacheProperties(); 28 | 29 | @NonNull 30 | private DependencyProperties dependency = new DependencyProperties(); 31 | 32 | @NonNull 33 | private AclProperties acl = new AclProperties(); 34 | 35 | @NonNull 36 | private StorageProperties storage = new StorageProperties(); 37 | 38 | @NonNull 39 | private ServiceProperties service = new ServiceProperties(); 40 | } 41 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/properties/ServiceProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.properties; 19 | 20 | import lombok.Data; 21 | 22 | @Data 23 | public class ServiceProperties { 24 | private long regionId = 0; 25 | private long nodeId = 0; 26 | } 27 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/properties/StorageProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.properties; 19 | 20 | import lombok.Data; 21 | import org.apache.rocketmq.schema.registry.common.model.StorageType; 22 | 23 | @Data 24 | public class StorageProperties { 25 | private StorageType type; 26 | private String configPath; 27 | 28 | @Data 29 | public static class Config { 30 | private String path; 31 | } 32 | 33 | public StorageType getType() { 34 | return type; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/storage/DefaultStorageServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.storage; 19 | 20 | import org.apache.rocketmq.schema.registry.common.model.SchemaInfo; 21 | 22 | public class DefaultStorageServiceImpl implements StorageService { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/storage/StorageFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.storage; 19 | 20 | import org.apache.rocketmq.schema.registry.common.model.SchemaInfo; 21 | import org.apache.rocketmq.schema.registry.common.model.StorageType; 22 | 23 | public interface StorageFactory { 24 | 25 | /** 26 | * Standard error message for all default implementations. 27 | */ 28 | String ERROR_MESSAGE_DEFAULT = "Not supported by this storage layer"; 29 | 30 | /** 31 | * Returns the storage service implementation of the config type. 32 | * 33 | * @return Returns the storage service implementation of the config type. 34 | */ 35 | default StorageService getStorageService() { 36 | throw new UnsupportedOperationException(ERROR_MESSAGE_DEFAULT); 37 | } 38 | 39 | /** 40 | * Returns the type of the storage. 41 | * 42 | * @return Returns the type of the storage. 43 | */ 44 | StorageType getStorageType(); 45 | 46 | /** 47 | * Stop and clear the factory. 48 | */ 49 | void stop(); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/storage/StoragePlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.storage; 19 | 20 | import org.apache.rocketmq.schema.registry.common.context.StoragePluginContext; 21 | import org.apache.rocketmq.schema.registry.common.model.StorageType; 22 | 23 | public interface StoragePlugin { 24 | 25 | /** 26 | * Returns the type of the storage plugin. 27 | * 28 | * @return type of the plugin. 29 | */ 30 | StorageType getType(); 31 | 32 | /** 33 | * Returns the storage service implementation for the type. 34 | * 35 | * @param storageContext registry for spectator 36 | * @return connector factory 37 | */ 38 | StorageFactory load(StoragePluginContext storageContext); 39 | } 40 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/storage/StoragePluginManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.storage; 19 | 20 | import java.util.concurrent.atomic.AtomicReference; 21 | import lombok.extern.slf4j.Slf4j; 22 | import org.apache.rocketmq.schema.registry.common.model.PluginLoadState; 23 | import org.apache.rocketmq.schema.registry.common.properties.GlobalConfig; 24 | 25 | @Slf4j 26 | public class StoragePluginManager { 27 | 28 | private final GlobalConfig config; 29 | private final StorageManager storageManager; 30 | 31 | private static final AtomicReference STATE = new AtomicReference<>(); 32 | 33 | /** 34 | * Constructor. 35 | * 36 | * @param storageManager storage manager 37 | */ 38 | public StoragePluginManager(GlobalConfig config, StorageManager storageManager) { 39 | this.config = config; 40 | this.storageManager = storageManager; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/utils/ErrorMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.utils; 19 | 20 | import lombok.AllArgsConstructor; 21 | import lombok.Builder; 22 | import lombok.Data; 23 | import lombok.EqualsAndHashCode; 24 | import lombok.NoArgsConstructor; 25 | import org.apache.rocketmq.schema.registry.common.exception.SchemaException; 26 | 27 | @Data 28 | @EqualsAndHashCode(callSuper = false) 29 | @Builder 30 | @NoArgsConstructor 31 | @AllArgsConstructor 32 | public class ErrorMessage { 33 | 34 | public int status; 35 | public String message; 36 | 37 | public ErrorMessage(SchemaException exception) { 38 | this.status = exception.getErrorCode(); 39 | this.message = exception.getMessage(); 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | final StringBuilder sb = new StringBuilder("{"); 45 | sb.append("\"status\":") 46 | .append(status); 47 | sb.append(",\"message\":\"") 48 | .append(message).append('\"'); 49 | sb.append('}'); 50 | return sb.toString(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/rocketmq/schema/registry/common/utils/IdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.common.utils; 19 | 20 | public interface IdGenerator { 21 | 22 | /** 23 | * @return unique id 24 | */ 25 | public long nextId(); 26 | } 27 | -------------------------------------------------------------------------------- /core/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/rocketmq/schema/registry/core/CoreApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.core; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration; 22 | import org.springframework.context.annotation.ComponentScan; 23 | import org.springframework.context.annotation.ComponentScan.Filter; 24 | import org.springframework.context.annotation.FilterType; 25 | import org.springframework.scheduling.annotation.EnableScheduling; 26 | import springfox.documentation.oas.annotations.EnableOpenApi; 27 | 28 | @SpringBootApplication(exclude = {HazelcastAutoConfiguration.class}) 29 | @EnableScheduling 30 | @EnableOpenApi 31 | @ComponentScan(excludeFilters = @Filter(type = FilterType.ASPECTJ, pattern = "org.apache.rocketmq.schema.registry.storage..*")) 32 | public class CoreApplication { 33 | 34 | public CoreApplication() { 35 | } 36 | 37 | public static void main(String[] args) { 38 | SpringApplication.run(CoreApplication.class, args); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/rocketmq/schema/registry/core/compatibility/CompatibilityChecker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.core.compatibility; 19 | 20 | import org.apache.rocketmq.schema.registry.common.exception.SchemaCompatibilityException; 21 | import org.apache.rocketmq.schema.registry.common.model.SchemaType; 22 | 23 | public class CompatibilityChecker { 24 | 25 | private static final SchemaValidator SCHEMA_VALIDATOR_AVRO = new AvroSchemaValidator(); 26 | 27 | public static SchemaValidator getValidator(SchemaType schemaType) { 28 | switch (schemaType) { 29 | case AVRO: 30 | return SCHEMA_VALIDATOR_AVRO; 31 | case JSON: 32 | return null; 33 | default: 34 | throw new SchemaCompatibilityException("Unsupported schema type: " + schemaType); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/rocketmq/schema/registry/core/compatibility/SchemaValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.core.compatibility; 19 | 20 | import org.apache.rocketmq.schema.registry.common.model.SchemaInfo; 21 | 22 | public interface SchemaValidator { 23 | 24 | void validate(SchemaInfo update, SchemaInfo current); 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/rocketmq/schema/registry/core/config/SchemaManagerConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.core.config; 19 | 20 | import org.apache.rocketmq.schema.registry.common.properties.GlobalConfig; 21 | import org.apache.rocketmq.schema.registry.common.storage.StorageManager; 22 | import org.apache.rocketmq.schema.registry.core.dependency.ArtifactoryDependencyServiceImpl; 23 | import org.apache.rocketmq.schema.registry.core.dependency.DependencyService; 24 | import org.springframework.context.annotation.Bean; 25 | import org.springframework.context.annotation.Configuration; 26 | 27 | @Configuration 28 | public class SchemaManagerConfig { 29 | 30 | /** 31 | * Manager of the storages. 32 | * 33 | * @param config global config 34 | * @return The storage manager 35 | */ 36 | @Bean 37 | public StorageManager storageManager(final GlobalConfig config) { 38 | return new StorageManager(config); 39 | } 40 | 41 | /** 42 | * Manager of the dependencies. 43 | * 44 | * @param config global config 45 | * @return The storage manager 46 | */ 47 | @Bean 48 | public DependencyService dependencyManager(final GlobalConfig config) { 49 | return new ArtifactoryDependencyServiceImpl(config); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/rocketmq/schema/registry/core/config/SchemaPropertiesConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.core.config; 19 | 20 | import org.apache.rocketmq.schema.registry.common.properties.GlobalConfig; 21 | import org.apache.rocketmq.schema.registry.common.properties.GlobalConfigImpl; 22 | import org.apache.rocketmq.schema.registry.common.properties.SchemaProperties; 23 | import org.springframework.boot.context.properties.ConfigurationProperties; 24 | import org.springframework.context.annotation.Bean; 25 | import org.springframework.context.annotation.Configuration; 26 | 27 | @Configuration 28 | public class SchemaPropertiesConfig { 29 | 30 | /** 31 | * Binding properties from configuration file. 32 | * 33 | * @return The schema properties object. 34 | */ 35 | @Bean 36 | @ConfigurationProperties(prefix = "schema") 37 | public SchemaProperties schemaProperties() { 38 | return new SchemaProperties(); 39 | } 40 | 41 | /** 42 | * Init the global config. 43 | * 44 | * @param schemaProperties The overall properties to use 45 | * @return The global config object 46 | */ 47 | @Bean 48 | public GlobalConfig config(final SchemaProperties schemaProperties) { 49 | return new GlobalConfigImpl(schemaProperties); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/rocketmq/schema/registry/core/config/SchemaUtilsConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.core.config; 19 | 20 | import org.apache.rocketmq.schema.registry.common.utils.StorageUtil; 21 | import org.springframework.context.annotation.Bean; 22 | import org.springframework.context.annotation.Configuration; 23 | 24 | @Configuration 25 | public class SchemaUtilsConfig { 26 | 27 | /** 28 | * Storage utility bean. 29 | * 30 | * @return The storage util instance 31 | */ 32 | @Bean 33 | public StorageUtil storageUtil() { 34 | return new StorageUtil(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/rocketmq/schema/registry/core/dependency/DependencyService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.core.dependency; 19 | 20 | import org.apache.rocketmq.schema.registry.common.model.Dependency; 21 | import org.apache.rocketmq.schema.registry.common.model.SchemaInfo; 22 | 23 | public interface DependencyService { 24 | 25 | String ERROR_MESSAGE_DEFAULT = "Not implemented dependency service method"; 26 | 27 | /** 28 | * Compile the dependency and upload generate file 29 | * 30 | * @param schemaInfo compile needed information 31 | * @return generated file path 32 | */ 33 | default Dependency compile(SchemaInfo schemaInfo) { 34 | throw new UnsupportedOperationException(ERROR_MESSAGE_DEFAULT); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/rocketmq/schema/registry/core/dependency/DynamicJarsProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.core.dependency; 19 | 20 | import lombok.extern.slf4j.Slf4j; 21 | 22 | @Slf4j 23 | public class DynamicJarsProvider { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/rocketmq/schema/registry/core/expection/RequestExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.core.expection; 19 | 20 | import java.io.IOException; 21 | import javax.servlet.http.HttpServletResponse; 22 | import lombok.extern.slf4j.Slf4j; 23 | import org.apache.rocketmq.schema.registry.common.exception.SchemaException; 24 | import org.apache.rocketmq.schema.registry.common.utils.ErrorMessage; 25 | import org.springframework.web.bind.annotation.ControllerAdvice; 26 | import org.springframework.web.bind.annotation.ExceptionHandler; 27 | 28 | @ControllerAdvice 29 | @Slf4j 30 | public class RequestExceptionHandler { 31 | 32 | /** 33 | * Handle Schema service Exceptions. 34 | * 35 | * @param response The HTTP response 36 | * @param e The inner exception to handle 37 | * @throws IOException on error in sending error 38 | */ 39 | @ExceptionHandler(SchemaException.class) 40 | public void handleException( 41 | final SchemaException e, 42 | final HttpServletResponse response 43 | ) throws IOException { 44 | ErrorMessage errorMessage = new ErrorMessage(e); 45 | log.error("Global handle SchemaException: " + errorMessage, e); 46 | response.setContentType("application/json"); 47 | response.setStatus(e.getErrorCode()); 48 | response.setCharacterEncoding("UTF-8"); 49 | response.getWriter().write(errorMessage.toString()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/rocketmq/schema/registry/core/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | @ParametersAreNonnullByDefault 19 | package org.apache.rocketmq.schema.registry.core; 20 | 21 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /core/src/main/java/org/apache/rocketmq/schema/registry/core/service/Service.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.core.service; 19 | 20 | import org.apache.rocketmq.schema.registry.common.dto.BaseDto; 21 | 22 | public interface Service { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=dev 2 | spring.application.name=rocketmq-schema-registry 3 | server.port=8080 4 | logging.file.name=schema-registry/log/app.log 5 | schema.dependency.upload-enabled=false 6 | #schema.dependency.jdk-path 7 | #schema.dependency.compile-path 8 | #schema.dependency.local-repository-path 9 | #schema.dependency.repository-url 10 | #schema.dependency.username 11 | #schema.dependency.password 12 | 13 | schema.storage.type=rocketmq 14 | schema.storage.config-path=storage-rocketmq/src/main/resources/rocketmq.properties 15 | 16 | #schema.storage.type=jdbc 17 | #schema.storage.config-path=storage-jdbc/src/main/resources/hazelcast.yaml 18 | 19 | springfox.documentation.swagger-ui.enabled=true 20 | management.health.db.enabled=true 21 | server.error.include-stacktrace=on_param 22 | server.error.include-message=always 23 | spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER 24 | spring.main.allow-bean-definition-overriding=true 25 | management.health.elasticsearch.enabled=false 26 | management.endpoints.enabled-by-default=true 27 | management.endpoints.web.exposure.include=health,info 28 | management.endpoints.web.exposure.exclude=httptrace,shutdown -------------------------------------------------------------------------------- /core/src/main/resources/template.pom: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 4.0.0 22 | $groupId 23 | $artifactId 24 | $version 25 | schema service auto generated POM 26 | 27 | 28 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/rocketmq/schema/registry/core/CoreApplicationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.core; 19 | 20 | import org.junit.jupiter.api.Test; 21 | import org.springframework.boot.test.context.SpringBootTest; 22 | 23 | @SpringBootTest 24 | class CoreApplicationTests { 25 | 26 | @Test 27 | void contextLoads() { 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/rocketmq/schema/registry/core/controller/HelloControllerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.core.controller; 19 | 20 | import org.junit.jupiter.api.Test; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 23 | import org.springframework.boot.test.context.SpringBootTest; 24 | import org.springframework.http.MediaType; 25 | import org.springframework.test.web.servlet.MockMvc; 26 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 27 | 28 | import static org.hamcrest.Matchers.equalTo; 29 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 30 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 31 | 32 | @SpringBootTest 33 | @AutoConfigureMockMvc 34 | public class HelloControllerTest { 35 | @Autowired 36 | private MockMvc mvc; 37 | 38 | @Test 39 | public void getHello() throws Exception { 40 | mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)) 41 | .andExpect(status().isOk()) 42 | .andExpect(content().string(equalTo("Greetings from Spring Boot!"))); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /docs/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/rocketmq-schema-registry/e5314c6dd42f1774fb681fc8cc97fa442a01c80b/docs/architecture.png -------------------------------------------------------------------------------- /docs/id.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/rocketmq-schema-registry/e5314c6dd42f1774fb681fc8cc97fa442a01c80b/docs/id.png -------------------------------------------------------------------------------- /docs/subject.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/rocketmq-schema-registry/e5314c6dd42f1774fb681fc8cc97fa442a01c80b/docs/subject.png -------------------------------------------------------------------------------- /example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | rocketmq-schema-registry-all 21 | org.apache.rocketmq 22 | 0.1.1-SNAPSHOT 23 | 24 | 4.0.0 25 | 26 | schema-registry-example 27 | 28 | 29 | 30 | org.apache.rocketmq 31 | schema-registry-client 32 | ${project.version} 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-checkstyle-plugin 41 | 42 | true 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /example/src/main/avro/Charge.avsc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | { 19 | "type":"record", 20 | "name":"Charge", 21 | "namespace":"org.apache.rocketmq.schema.registry.example.serde", 22 | "fields":[ 23 | { 24 | "name":"item", 25 | "type":"string" 26 | }, 27 | { 28 | "name":"amount", 29 | "type":"double" 30 | } 31 | ] 32 | } -------------------------------------------------------------------------------- /example/src/main/java/org/apache/rocketmq/schema/registry/example/DeleteSchemaDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.example; 19 | 20 | import java.io.IOException; 21 | 22 | import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient; 23 | import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory; 24 | import org.apache.rocketmq.schema.registry.client.exceptions.RestClientException; 25 | import org.apache.rocketmq.schema.registry.common.dto.DeleteSchemeResponse; 26 | 27 | public class DeleteSchemaDemo { 28 | 29 | public static void main(String[] args) { 30 | 31 | String baseUrl = "http://localhost:8080"; 32 | SchemaRegistryClient schemaRegistryClient = SchemaRegistryClientFactory.newClient(baseUrl, null); 33 | 34 | String topic = "TopicTest"; 35 | try { 36 | DeleteSchemeResponse response 37 | = schemaRegistryClient.deleteSchema("default", "default", topic, 2); 38 | System.out.println("delete schema by subject and version success, schemaId: " + response.getRecordId()); 39 | 40 | Thread.sleep(5000); 41 | System.out.println("current schema: " + schemaRegistryClient.getSchemaBySubject(topic)); 42 | 43 | DeleteSchemeResponse response1 44 | = schemaRegistryClient.deleteSchema("default", "default", topic); 45 | System.out.println("delete schema by subject success, schemaId: " + response1.getRecordId()); 46 | } catch (RestClientException | IOException | InterruptedException e) { 47 | e.printStackTrace(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /example/src/main/java/org/apache/rocketmq/schema/registry/example/serde/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.example.serde; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnore; 21 | import com.fasterxml.jackson.annotation.JsonPropertyOrder; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Builder; 24 | import lombok.Data; 25 | import lombok.NoArgsConstructor; 26 | 27 | import java.util.Objects; 28 | 29 | @Data 30 | @Builder 31 | @AllArgsConstructor 32 | @NoArgsConstructor 33 | @JsonPropertyOrder(alphabetic = true) 34 | public class Person { 35 | @JsonIgnore 36 | private Long id; 37 | private String name; 38 | private int age; 39 | 40 | @Override 41 | public boolean equals(Object o) { 42 | if (this == o) return true; 43 | if (o == null || getClass() != o.getClass()) return false; 44 | Person person = (Person) o; 45 | return age == person.age && Objects.equals(name, person.name); 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return Objects.hash(name, age); 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "Person{" + 56 | "name='" + name + '\'' + 57 | ", age=" + age + 58 | '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /example/src/main/java/org/apache/rocketmq/schema/registry/example/serde/avro/ReflectionAvroSerdeDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.example.serde.avro; 18 | 19 | import org.apache.rocketmq.schema.registry.client.config.AvroSerdeConfig; 20 | import org.apache.rocketmq.schema.registry.client.serde.avro.ReflectionAvroSerde; 21 | import org.apache.rocketmq.schema.registry.example.serde.Charge; 22 | 23 | import java.io.IOException; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | public class ReflectionAvroSerdeDemo { 28 | public static void main(String[] args) { 29 | Charge charge = new Charge("specific", 100.0); 30 | Map configs = new HashMap<>(); 31 | configs.put(AvroSerdeConfig.DESERIALIZE_TARGET_TYPE, charge.getClass()); 32 | try (ReflectionAvroSerde serde = new ReflectionAvroSerde()) { 33 | //serialize 34 | serde.configure(configs); 35 | 36 | byte[] bytes = serde.serializer().serialize("TopicTest", charge); 37 | //deserialize 38 | Charge charge1 = (Charge) serde.deserializer().deserialize("TopicTest", bytes); 39 | System.out.println("charge before ser/de is " + charge); 40 | System.out.println("charge after ser/de is " + charge1); 41 | System.out.printf("charge == charge1 : %b", charge.equals(charge1)); 42 | } catch (IOException e) { 43 | System.out.println("serde shutdown failed"); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /example/src/main/java/org/apache/rocketmq/schema/registry/example/serde/json/JsonSerdeWithoutServerDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.example.serde.json; 19 | 20 | import org.apache.rocketmq.schema.registry.client.config.JsonSerdeConfig; 21 | import org.apache.rocketmq.schema.registry.client.serde.json.JsonSerde; 22 | import org.apache.rocketmq.schema.registry.example.serde.Person; 23 | 24 | import java.io.IOException; 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | 28 | public class JsonSerdeWithoutServerDemo { 29 | 30 | public static void main(String[] args) { 31 | Person person = new Person(1L, "name", 18); 32 | System.out.printf("person before serialize is %s\n", person); 33 | 34 | try(JsonSerde jsonSerde = new JsonSerde<>()) { 35 | Map configs = new HashMap<>(); 36 | configs.put(JsonSerdeConfig.DESERIALIZE_TARGET_TYPE, Person.class); 37 | configs.put(JsonSerdeConfig.SKIP_SCHEMA_REGISTRY, true); 38 | jsonSerde.configure(configs); 39 | byte[] bytes = jsonSerde.serializer().serialize("TopicTest", person); 40 | 41 | Person person1 = jsonSerde.deserializer().deserialize("TopicTest", bytes); 42 | System.out.printf("after deserialize new person is %s\n", person1); 43 | System.out.printf("person == person1 : %b\n", person1.equals(person)); 44 | } catch (IOException e) { 45 | System.out.println("serde shutdown failed"); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /storage-jdbc/embedded-hazelcast-on-kubernetes.md: -------------------------------------------------------------------------------- 1 | embedded-hazelcast-on-kubernetes 2 | ================ 3 | https://hazelcast.com/blog/how-to-use-embedded-hazelcast-on-kubernetes/ -------------------------------------------------------------------------------- /storage-jdbc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | rocketmq-schema-registry-all 23 | org.apache.rocketmq 24 | 0.1.1-SNAPSHOT 25 | 26 | 4.0.0 27 | 28 | schema-registry-storage-jdbc 29 | jar 30 | 31 | 32 | 8.0.28 33 | 5.3.0 34 | 35 | 36 | 37 | 38 | org.apache.rocketmq 39 | schema-registry-common 40 | ${project.version} 41 | 42 | 43 | 44 | mysql 45 | mysql-connector-java 46 | ${mysql.version} 47 | 48 | 49 | 50 | com.hazelcast 51 | hazelcast 52 | ${hazelcast.version} 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/JdbcStorageFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc; 19 | 20 | import org.apache.rocketmq.schema.registry.common.context.StoragePluginContext; 21 | import org.apache.rocketmq.schema.registry.common.model.SchemaInfo; 22 | import org.apache.rocketmq.schema.registry.common.storage.SpringStorageFactory; 23 | import org.apache.rocketmq.schema.registry.common.storage.StorageService; 24 | import org.apache.rocketmq.schema.registry.storage.jdbc.configs.ServiceConfig; 25 | 26 | import java.io.IOException; 27 | 28 | public class JdbcStorageFactory 29 | extends SpringStorageFactory { 30 | public JdbcStorageFactory(StoragePluginContext context) { 31 | super(context); 32 | super.registerClazz(ServiceConfig.class); 33 | super.refresh(); 34 | } 35 | 36 | @Override 37 | public StorageService getStorageService() { 38 | return this.ctx.getBean(JdbcStorageService.class); 39 | } 40 | 41 | @Override 42 | public void stop() { 43 | try { 44 | getStorageService().close(); 45 | } catch (IOException e) { 46 | // Ignore this error 47 | } 48 | super.stop(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/JdbcStoragePlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc; 19 | 20 | import org.apache.rocketmq.schema.registry.common.context.StoragePluginContext; 21 | import org.apache.rocketmq.schema.registry.common.model.StorageType; 22 | import org.apache.rocketmq.schema.registry.common.storage.StorageFactory; 23 | import org.apache.rocketmq.schema.registry.common.storage.StoragePlugin; 24 | 25 | /** 26 | * Mysql storage plugin 27 | */ 28 | public class JdbcStoragePlugin 29 | implements StoragePlugin { 30 | @Override 31 | public StorageType getType() { 32 | return StorageType.JDBC; 33 | } 34 | 35 | @Override 36 | public StorageFactory load(StoragePluginContext context) { 37 | return new JdbcStorageFactory(context); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/cache/LocalCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.cache; 19 | 20 | import java.util.Map; 21 | import java.util.function.Consumer; 22 | 23 | public interface LocalCache { 24 | 25 | V put(K k, V v); 26 | 27 | V get(K k, Consumer consumer); 28 | 29 | V get(K k); 30 | 31 | V remove(K k); 32 | 33 | boolean containsKey(K k); 34 | 35 | Map getCache(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/cache/SubjectLocalCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.cache; 19 | 20 | import com.google.common.collect.Maps; 21 | import org.apache.rocketmq.schema.registry.common.model.SchemaRecordInfo; 22 | 23 | import java.util.Map; 24 | import java.util.function.Consumer; 25 | 26 | public class SubjectLocalCache implements LocalCache { 27 | 28 | public static Map subjectCache = Maps.newConcurrentMap(); 29 | 30 | @Override 31 | public SchemaRecordInfo put(String subjectFullName, SchemaRecordInfo schemaRecordInfo) { 32 | return subjectCache.get(subjectFullName); 33 | } 34 | 35 | @Override 36 | public SchemaRecordInfo get(String subjectFullName, Consumer consumer) { 37 | if (!containsKey(subjectFullName)) { 38 | consumer.accept(subjectFullName); 39 | } 40 | return subjectCache.get(subjectFullName); 41 | } 42 | 43 | @Override 44 | public SchemaRecordInfo get(String subjectFullName) { 45 | return subjectCache.get(subjectFullName); 46 | } 47 | 48 | @Override 49 | public SchemaRecordInfo remove(String s) { 50 | return subjectCache.remove(s); 51 | } 52 | 53 | @Override 54 | public boolean containsKey(String fullName) { 55 | return subjectCache.containsKey(fullName); 56 | } 57 | 58 | @Override 59 | public Map getCache() { 60 | return subjectCache; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/common/Operator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.common; 19 | 20 | /** 21 | * update mode 22 | */ 23 | public enum Operator { 24 | INSERT, 25 | DELETE, 26 | UPSERT, 27 | UPDATE, 28 | SELECT 29 | } -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/configs/JdbcStorageConfigConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.schema.registry.storage.jdbc.configs; 18 | 19 | public class JdbcStorageConfigConstants { 20 | 21 | // jdbc storage config 22 | public final static String STORAGE_JDBC_TYPE = "storage.jdbc.type"; 23 | public final static String STORAGE_JDBC_TYPE_MYSQL = "mysql"; 24 | public final static String STORAGE_JDBC_URL = "storage.jdbc.url"; 25 | public final static String STORAGE_JDBC_USER = "storage.jdbc.user"; 26 | public final static String STORAGE_JDBC_PASSWORD = "storage.jdbc.password"; 27 | public final static String STORAGE_JDBC_DATABASE_NAME = "storage.jdbc.database.name"; 28 | public final static String STORAGE_JDBC_SCHEMA_NAME = "storage.jdbc.schema.name"; 29 | public final static String STORAGE_JDBC_TABLE_NAME = "storage.jdbc.table.name"; 30 | public final static String MAX_CONNECTIONS_ATTEMPTS = "max.connections.attempts"; 31 | public final static String MAX_CONNECTIONS_ATTEMPTS_DEFAULT = "3"; 32 | public final static String CONNECTION_RETRY_BACKOFF = "connection.retry.backoff"; 33 | public final static String CONNECTION_RETRY_BACKOFF_DEFAULT = "1000"; 34 | public final static String HAZELCAST_YAML_PATH = "storage.jdbc.hazelcast.yaml.path"; 35 | public final static String DATABASE_DEFAULT = "schema_registry"; 36 | public final static String TABLE_NAME_DEFAULT = "schema_table"; 37 | } 38 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/configs/ServiceConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.configs; 19 | 20 | import org.apache.rocketmq.schema.registry.common.context.StoragePluginContext; 21 | import org.apache.rocketmq.schema.registry.storage.jdbc.JdbcStorageService; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | 25 | @Configuration 26 | public class ServiceConfig { 27 | 28 | /** 29 | * mysql storage service 30 | * 31 | * @param context 32 | * @return 33 | */ 34 | @Bean 35 | public JdbcStorageService jdbcStorageService(StoragePluginContext context) { 36 | return new JdbcStorageService(context); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/dialect/ConnectionProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.dialect; 19 | 20 | import java.sql.Connection; 21 | import java.sql.SQLException; 22 | 23 | /** 24 | * A provider of JDBC {@link Connection} instances. 25 | */ 26 | public interface ConnectionProvider extends AutoCloseable { 27 | 28 | /** 29 | * Create a connection. 30 | * 31 | * @return the connection; never null 32 | * @throws SQLException if there is a problem getting the connection 33 | */ 34 | Connection getConnection() throws SQLException; 35 | 36 | /** 37 | * connection valid 38 | * 39 | * @param connection 40 | * @param timeout 41 | * @return 42 | * @throws SQLException 43 | */ 44 | boolean isConnectionValid(Connection connection, int timeout) throws SQLException; 45 | 46 | /** 47 | * Close this connection provider. 48 | */ 49 | @Override 50 | void close(); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/dialect/DatabaseDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.dialect; 19 | 20 | import org.apache.rocketmq.schema.registry.storage.jdbc.common.Operator; 21 | 22 | import java.sql.Connection; 23 | import java.sql.PreparedStatement; 24 | import java.sql.SQLException; 25 | import java.util.Collection; 26 | import java.util.List; 27 | 28 | /** 29 | * database dialect 30 | */ 31 | public interface DatabaseDialect extends ConnectionProvider { 32 | String dbType(); 33 | 34 | TableId tableId(); 35 | 36 | List fields(); 37 | 38 | PreparedStatement createPreparedStatement(Connection db, String sql) throws SQLException; 39 | 40 | String buildSelectStatement(); 41 | 42 | String buildSelectOneStatement(String keyField); 43 | 44 | String buildUpsertStatement(TableId tableId, Collection fields); 45 | 46 | String buildInsertStatement(TableId tableId, Collection columns); 47 | 48 | String buildUpdateStatement(TableId tableId, Collection keyColumns, Collection columns); 49 | 50 | String buildDeleteStatement(TableId tableId, Collection keyColumns); 51 | 52 | void bindRecord(PreparedStatement statement, Collection keyValues, 53 | Collection noKeyValues, Operator mode) throws SQLException; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/dialect/DatabaseDialectProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.dialect; 19 | 20 | import java.io.IOException; 21 | import java.util.Properties; 22 | 23 | public interface DatabaseDialectProvider { 24 | 25 | DatabaseDialect createDialect(Properties config) throws IOException; 26 | 27 | String databaseType(); 28 | } 29 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/dialect/DiscoverDialectFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.dialect; 19 | 20 | import com.google.common.collect.Maps; 21 | 22 | import java.util.Iterator; 23 | import java.util.Map; 24 | import java.util.ServiceLoader; 25 | 26 | /** 27 | * Discover dialect factory 28 | */ 29 | public class DiscoverDialectFactory { 30 | 31 | private static final Map DIALECT_CACHE = Maps.newConcurrentMap(); 32 | 33 | static { 34 | loadDialects(); 35 | } 36 | 37 | private static void loadDialects() { 38 | ServiceLoader dialects = ServiceLoader.load(DatabaseDialectProvider.class); 39 | Iterator dialectIterator = dialects.iterator(); 40 | while (dialectIterator.hasNext()) { 41 | DatabaseDialectProvider dialect = dialectIterator.next(); 42 | DIALECT_CACHE.put(dialect.databaseType(), dialect); 43 | } 44 | } 45 | 46 | public static DatabaseDialectProvider getDialectProvider(String dbType) { 47 | return DIALECT_CACHE.get(dbType); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/dialect/TableId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.dialect; 19 | 20 | import lombok.AllArgsConstructor; 21 | import lombok.Builder; 22 | import lombok.Data; 23 | import org.apache.rocketmq.schema.registry.storage.jdbc.common.IdentifierRules; 24 | 25 | @Data 26 | @AllArgsConstructor 27 | @Builder 28 | public class TableId { 29 | public static final String DB_NAME = "#DBNAME#"; 30 | public static final String SCHEMA_NAME = "#SCHEMANAME#"; 31 | public static final String TABLE_NAME = "#TABLENAME#"; 32 | private String tableName; 33 | private String catalogName; 34 | private String schemaName; 35 | 36 | private void appendTo(StringBuilder builder, String name, String quote) { 37 | builder.append(name.trim()).append(quote); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | StringBuilder builder = new StringBuilder(); 43 | if (catalogName != null) { 44 | appendTo(builder, catalogName.trim(), IdentifierRules.DEFAULT_ID_DELIM); 45 | } 46 | if (schemaName != null) { 47 | appendTo(builder, schemaName.trim(), IdentifierRules.DEFAULT_ID_DELIM); 48 | } 49 | builder.append(tableName.trim()); 50 | return builder.toString(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/store/IMapStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.store; 19 | 20 | import com.hazelcast.map.MapLoaderLifecycleSupport; 21 | import com.hazelcast.map.MapStore; 22 | 23 | public interface IMapStore extends MapStore, MapLoaderLifecycleSupport { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/store/JdbcSchemaMapStoreFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.store; 19 | 20 | import com.hazelcast.map.MapLoader; 21 | import com.hazelcast.map.MapStoreFactory; 22 | import org.apache.rocketmq.schema.registry.common.model.SchemaInfo; 23 | 24 | import java.util.Properties; 25 | 26 | public class JdbcSchemaMapStoreFactory implements MapStoreFactory { 27 | @Override 28 | public MapLoader newMapStore(String s, Properties properties) { 29 | return new JdbcSchemaMapStore(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/store/JdbcSubjectMapStoreFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.jdbc.store; 19 | 20 | import com.hazelcast.map.MapLoader; 21 | import com.hazelcast.map.MapStoreFactory; 22 | import org.apache.rocketmq.schema.registry.common.model.SchemaRecordInfo; 23 | 24 | import java.util.Properties; 25 | 26 | public class JdbcSubjectMapStoreFactory implements MapStoreFactory { 27 | 28 | @Override 29 | public MapLoader newMapStore(String s, Properties properties) { 30 | return new JdbcSubjectMapStore(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/resources/META-INF/services/org.apache.rocketmq.schema.registry.common.storage.StoragePlugin: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | org.apache.rocketmq.schema.registry.storage.jdbc.JdbcStoragePlugin 19 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/resources/META-INF/services/org.apache.rocketmq.schema.registry.storage.jdbc.dialect.DatabaseDialectProvider: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | org.apache.rocketmq.schema.registry.storage.jdbc.dialect.mysql.MysqlDatabaseDialect$Provider -------------------------------------------------------------------------------- /storage-jdbc/src/main/resources/hazelcast.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | hazelcast: 19 | cluster-name: schema-registry 20 | instance-name: schema-registry 21 | network: 22 | port: 23 | auto-increment: false 24 | port: 5801 25 | map: 26 | schemas: 27 | map-store: 28 | write-delay-seconds: 0 29 | enabled: true 30 | initial-mode: EAGER 31 | factory-class-name: org.apache.rocketmq.schema.registry.storage.jdbc.store.JdbcSchemaMapStoreFactory 32 | properties: 33 | storage.jdbc.type: mysql 34 | storage.jdbc.url: jdbc:mysql://localhost:3306 35 | storage.jdbc.user: root 36 | storage.jdbc.password: root 37 | storage.jdbc.database.name: schema_registry 38 | storage.jdbc.table.name: schema_table 39 | subjects: 40 | map-store: 41 | write-delay-seconds: 0 42 | enabled: true 43 | initial-mode: EAGER 44 | factory-class-name: org.apache.rocketmq.schema.registry.storage.jdbc.store.JdbcSubjectMapStoreFactory 45 | properties: 46 | cache.size: 1000 47 | properties: 48 | hazelcast.invocation.max.retry.count: 20 49 | hazelcast.tcp.join.port.try.count: 30 50 | hazelcast.logging.type: log4j2 51 | hazelcast.operation.generic.thread.count: 100 52 | 53 | -------------------------------------------------------------------------------- /storage-jdbc/src/main/resources/mysql-storage-ddl.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Licensed to the Apache Software Foundation (ASF) under one or more 3 | -- contributor license agreements. See the NOTICE file distributed with 4 | -- this work for additional information regarding copyright ownership. 5 | -- The ASF licenses this file to You under the Apache License, Version 2.0 6 | -- (the "License"); you may not use this file except in compliance with 7 | -- the License. You may obtain a copy of the License at 8 | -- 9 | -- http://www.apache.org/licenses/LICENSE-2.0 10 | -- 11 | -- Unless required by applicable law or agreed to in writing, software 12 | -- distributed under the License is distributed on an "AS IS" BASIS, 13 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | -- See the License for the specific language governing permissions and 15 | -- limitations under the License. 16 | -- 17 | -- ---------------------------------------------------------------------------------------------------------------- 18 | -- DATABASE: mysql storage database 19 | -- ---------------------------------------------------------------------------------------------------------------- 20 | create database IF NOT EXISTS #DBNAME#; 21 | -- ---------------------------------------------------------------------------------------------------------------- 22 | CREATE TABLE IF NOT EXISTS `#DBNAME#`.`#TABLENAME#`( 23 | `schema_full_name` VARCHAR(255) NOT NULL PRIMARY KEY, 24 | `schema_info` TEXT NOT NULL COMMENT 'schema info', 25 | `modified_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'modified time', 26 | `description` VARCHAR(512) 27 | ) 28 | -------------------------------------------------------------------------------- /storage-rocketmq/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | rocketmq-schema-registry-all 22 | org.apache.rocketmq 23 | 0.1.1-SNAPSHOT 24 | 25 | 4.0.0 26 | 27 | schema-registry-storage-rocketmq 28 | jar 29 | 30 | 31 | 5.0.0-ALPHA 32 | 33 | 34 | 35 | 36 | org.apache.rocketmq 37 | schema-registry-common 38 | ${project.version} 39 | 40 | 41 | 42 | org.apache.rocketmq 43 | rocketmq-client 44 | 45 | 46 | 47 | org.apache.rocketmq 48 | rocketmq-tools 49 | 50 | 51 | 52 | org.rocksdb 53 | rocksdbjni 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /storage-rocketmq/src/main/java/org/apache/rocketmq/schema/registry/storage/rocketmq/RocketmqStorageFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.rocketmq; 19 | 20 | import org.apache.rocketmq.schema.registry.common.context.StoragePluginContext; 21 | import org.apache.rocketmq.schema.registry.common.model.SchemaInfo; 22 | import org.apache.rocketmq.schema.registry.common.storage.SpringStorageFactory; 23 | import org.apache.rocketmq.schema.registry.common.storage.StorageService; 24 | import org.apache.rocketmq.schema.registry.storage.rocketmq.configs.ClientConfig; 25 | import org.apache.rocketmq.schema.registry.storage.rocketmq.configs.ServiceConfig; 26 | 27 | public class RocketmqStorageFactory extends SpringStorageFactory { 28 | 29 | public RocketmqStorageFactory(final StoragePluginContext storageServiceContext) { 30 | super(storageServiceContext); 31 | super.registerClazz(ClientConfig.class, ServiceConfig.class); 32 | super.refresh(); 33 | } 34 | 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @Override 39 | public StorageService getStorageService() { 40 | return this.ctx.getBean(RocketmqStorageService.class); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /storage-rocketmq/src/main/java/org/apache/rocketmq/schema/registry/storage/rocketmq/RocketmqStoragePlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.rocketmq; 19 | 20 | import org.apache.rocketmq.schema.registry.common.context.StoragePluginContext; 21 | import org.apache.rocketmq.schema.registry.common.model.StorageType; 22 | import org.apache.rocketmq.schema.registry.common.storage.StorageFactory; 23 | import org.apache.rocketmq.schema.registry.common.storage.StoragePlugin; 24 | 25 | public class RocketmqStoragePlugin implements StoragePlugin { 26 | private static final StorageType STORAGE_TYPE = StorageType.ROCKETMQ; 27 | 28 | /** 29 | * {@inheritDoc} 30 | */ 31 | @Override 32 | public StorageType getType() { 33 | return STORAGE_TYPE; 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | public StorageFactory load(final StoragePluginContext storageContext) { 41 | return new RocketmqStorageFactory(storageContext); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /storage-rocketmq/src/main/java/org/apache/rocketmq/schema/registry/storage/rocketmq/RocketmqStorageUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.rocketmq; 19 | 20 | import java.nio.charset.StandardCharsets; 21 | import java.util.Arrays; 22 | import org.rocksdb.RocksDB; 23 | import org.rocksdb.RocksDBException; 24 | 25 | public class RocketmqStorageUtils { 26 | 27 | public static void checkAndPut(String key, byte[] value, RocksDB db) throws RocksDBException { 28 | byte[] oldValue = db.get(key.getBytes(StandardCharsets.UTF_8)); 29 | if (oldValue == null || !Arrays.equals(oldValue, value)) { 30 | db.put(key.getBytes(StandardCharsets.UTF_8), value); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /storage-rocketmq/src/main/java/org/apache/rocketmq/schema/registry/storage/rocketmq/configs/ClientConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.rocketmq.configs; 19 | 20 | import org.apache.rocketmq.schema.registry.common.context.StoragePluginContext; 21 | import org.apache.rocketmq.schema.registry.storage.rocketmq.RocketmqStorageClient; 22 | import org.apache.rocketmq.schema.registry.storage.rocketmq.RocketmqStorageClientImpl; 23 | import org.springframework.context.annotation.Bean; 24 | import org.springframework.context.annotation.Configuration; 25 | 26 | @Configuration 27 | public class ClientConfig { 28 | 29 | /** 30 | * RocketMQ client instance. 31 | * 32 | * @param context storage plugin context 33 | * @return RocketmqStorageClient 34 | */ 35 | @Bean 36 | public RocketmqStorageClient rocketmqStorageClient(StoragePluginContext context) { 37 | return new RocketmqStorageClientImpl(context); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /storage-rocketmq/src/main/java/org/apache/rocketmq/schema/registry/storage/rocketmq/configs/ServiceConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry.storage.rocketmq.configs; 19 | 20 | import org.apache.rocketmq.schema.registry.storage.rocketmq.RocketmqStorageClient; 21 | import org.apache.rocketmq.schema.registry.storage.rocketmq.RocketmqStorageService; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | 25 | @Configuration 26 | public class ServiceConfig { 27 | 28 | /** 29 | * create rocketmq storage service. 30 | * 31 | * @param storageClient rocketmq storage Client 32 | * @return rocketmq storage Service 33 | */ 34 | @Bean 35 | public RocketmqStorageService rocketmqStorageService(RocketmqStorageClient storageClient) { 36 | return new RocketmqStorageService(storageClient); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /storage-rocketmq/src/main/java/org/apache/rocketmq/schema/registry/storage/rocketmq/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | @ParametersAreNonnullByDefault 19 | package org.apache.rocketmq.schema.registry.storage.rocketmq; 20 | 21 | import javax.annotation.ParametersAreNonnullByDefault; 22 | -------------------------------------------------------------------------------- /storage-rocketmq/src/main/resources/META-INF/services/org.apache.rocketmq.schema.registry.common.storage.StoragePlugin: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | org.apache.rocketmq.schema.registry.storage.rocketmq.RocketmqStoragePlugin 19 | -------------------------------------------------------------------------------- /storage-rocketmq/src/main/resources/rocketmq.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | #storage.type=rocketmq 19 | #storage.local.cache.path -------------------------------------------------------------------------------- /style/copyright/Apache.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 24 | -------------------------------------------------------------------------------- /tools/avro-tools-1.11.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/rocketmq-schema-registry/e5314c6dd42f1774fb681fc8cc97fa442a01c80b/tools/avro-tools-1.11.0.jar -------------------------------------------------------------------------------- /war/src/main/java/org/apache/rocketmq/schema/registry/StorageWar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.schema.registry; 19 | 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.boot.builder.SpringApplicationBuilder; 22 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 23 | import org.springframework.context.annotation.ComponentScan; 24 | import org.springframework.context.annotation.ComponentScan.Filter; 25 | import org.springframework.context.annotation.FilterType; 26 | 27 | @SpringBootApplication 28 | @ComponentScan(excludeFilters = @Filter(type = FilterType.ASPECTJ, pattern = "com.netflix.metacat.connector..*")) 29 | public class StorageWar extends SpringBootServletInitializer { 30 | 31 | public StorageWar() { 32 | } 33 | 34 | public static void main(String[] args) { 35 | new StorageWar().configure(new SpringApplicationBuilder(StorageWar.class)) 36 | .run(args); 37 | } 38 | } 39 | --------------------------------------------------------------------------------