设为首页收藏本站

数码鹭岛论坛

 找回密码
 注-册

QQ登录

只需一步,快速开始

搜索
查看: 1153|回复: 0
打印 上一主题 下一主题

Using the avro schema-repo

[复制链接]
跳转到指定楼层
1#
发表于 2014-12-17 17:53:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
项目地址: https://github.com/schema-repo/schema-repo

Dependency Jars:

    avro-repo-bundle-1.7.5-SNAPSHOT-withdeps.jar
    avro-repo-client-1.7.5-SNAPSHOT.jar
    avro-repo-common-1.7.5-SNAPSHOT.jar
    avro-repo-server-1.7.5-SNAPSHOT.jar
    javax.inject-1.jar
    jersey-core-1.15.jar
    jersey-server-1.15.jar
    jersey-servlet-1.15.jar
    jetty-server-8.1.8.v20121106.jar
    jetty-util-8.1.8.v20121106.jar
    paranamer-2.3.jar
    schema-repo.jar
    servlet-api-2.5.jar

Properties file contents (if your property keys are incorrect you will see Guice exceptions):

cat test.prop

repo.class=org.apache.avro.repo.FileRepository
avro.repo.file-repo-path=target/data/

Filesystem Repo Directory:

    target/data/

Starting the repo:

    java -cp “*” org.apache.avro.repo.server.RepositoryServer test.prop

Create a subejct if it does not already exist:

curl -I -H "Content-Type: application/x-www-form-urlencoded" -XPUT "http://localhost:2876/schema-repo/tests"

Return:
HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked
Server: Jetty(8.y.z-SNAPSHOT)

Get a subject:

$ curl -I "http://localhost:2876/schema-repo/tests"

Return:
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 0
Server: Jetty(8.y.z-SNAPSHOT)

Register a schema with a subject:

$ curl -H "Content-type: text/plain" -XPUT "http://localhost:2876/schema-repo/tests/register" -d '{"namespace":"tts.tests.avro","type":"record","name":"Test","fields":[{"name":"test_name","type":"string"},{"name":"ts","type":"int"},{"name":"value","type":["string","null"]}]}'

Return (returns the schema id):
0

Get the latest schema for a subject:

$ curl "http://localhost:2876/schema-repo/tests/latest"

Return:
0 {“namespace”:”tts.tests.avro”,”type”:”record”,”name”:”Test”,”fields”:[{“name”:”test_name”,”type”:”string”},{“name”:”ts”,”type”:”int”},{“name”:”value”,”type”:[“string”,”null”]}]}

Get the config for a schema:

$ curl "http://localhost:2876/schema-repo/tests/config"

Return:
#Wed Apr 10 11:08:30 EDT 2013

Look up an id by a subject + schema pair:
curl -H "Content-type: text/plain" -XPOST "http://localhost:2876/schema-repo/tests/schema" -d '{"namespace":"tts.tests.avro","type":"record","name":"Test","fields":[{"name":"test_name","type":"string"},{"name":"ts","type":"int"},{"name":"value","type":["string","null"]}]}'

Return:
0

Look up schema by subject + id pair:

$ curl "http://localhost:2876/schema-repo/tests/id/0"

Return:
{“namespace”:”tts.tests.avro”,”type”:”record”,”name”:”Test”,”fields”:[{“name”:”test_name”,”type”:”string”},{“name”:”ts”,”type”:”int”},{“name”:”value”,”type”:[“string”,”null”]}]}

Look up all schemas for a subject (subject=tests):

$ curl "http://localhost:2876/schema-repo/tests/all"

Return:
0 {“namespace”:”tts.tests.avro”,”type”:”record”,”name”:”Test”,”fields”:[{“name”:”test_name”,”type”:”string”},{“name”:”ts”,”type”:”int”},{“name”:”value”,”type”:[“string”,”null”]}]}

Adding another schema to the same subject (*Note: if schemas are the same it returns the existing id):

$ curl -H "Content-type: text/plain" -XPUT "http://localhost:2876/schema-repo/tests/register" -d '{"namespace":"tts.tests.avro","type":"record","name":"Test","fields":[{"name":"test_name","type":"string"},{"name":"ts","type":"int"},{"name":"value","type":["string","null"]},{"note":"test_note","type":"string"}]}'

Return:
1

Look up all schemas for a subject … again (subject=tests):

$ curl "http://localhost:2876/schema-repo/tests/all"

Return:
1 {“namespace”:”tts.tests.avro”,”type”:”record”,”name”:”Test”,”fields”:[{“name”:”test_name”,”type”:”string”},{“name”:”ts”,”type”:”int”},{“name”:”value”,”type”:[“string”,”null”]},{“note”:”test_note”,”type”:”string”}]}
0 {“namespace”:”tts.tests.avro”,”type”:”record”,”name”:”Test”,”fields”:[{“name”:”test_name”,”type”:”string”},{“name”:”ts”,”type”:”int”},{“name”:”value”,”type”:[“string”,”null”]}]}

Exploring the filesystem:

    $ ll target/data/tests/
    total 32
    -rw-r–r– 1 w3ndns staff 177 Apr 10 11:06 0.schema
    -rw-r–r– 1 w3ndns staff 214 Apr 10 11:14 1.schema
    -rw-r–r– 1 w3ndns staff 4 Apr 10 11:14 schema_ids
    -rw-r–r– 1 w3ndns staff 68 Apr 10 10:59 subject.properties
    $ cd target/data/tests/
    $ ll
    total 32
    -rw-r–r– 1 w3ndns staff 177 Apr 10 11:06 0.schema
    -rw-r–r– 1 w3ndns staff 214 Apr 10 11:14 1.schema
    -rw-r–r– 1 w3ndns staff 4 Apr 10 11:14 schema_ids
    -rw-r–r– 1 w3ndns staff 68 Apr 10 10:59 subject.properties
    $ cat 0.schema
    {“namespace”:”tts.tests.avro”,”type”:”record”,”name”:”Test”,”fields”:[{“name”:”test_name”,”type”:”string”},{“name”:”ts”,”type”:”int”},{“name”:”value”,”type”:[“string”,”null”]}]}
    $ cat 1.schema
    {“namespace”:”tts.tests.avro”,”type”:”record”,”name”:”Test”,”fields”:[{“name”:”test_name”,”type”:”string”},{“name”:”ts”,”type”:”int”},{“name”:”value”,”type”:[“string”,”null”]},{“note”:”test_note”,”type”:”string”}]}
    $ cat schema_ids
    0
    1
    $ cat subject.properties
    #Schema Repository Subject Properties
    #Wed Apr 10 10:59:43 EDT 2013

    If you delete a(n) schema file(s), the schema will remain persistent in memory until the RepositoryServer is restarted.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享

相关帖子

您需要登录后才可以回帖 登录 | 注-册

本版积分规则

小黑屋|手机版|Archiver|数码鹭岛 ( 闽ICP备20006246号 )  

counter

GMT+8, 2025-12-3 13:54 , Processed in 0.073474 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表