Apicurio / apicurio-registry

An API/Schema registry - stores APIs and Schemas.
https://www.apicur.io/registry/
Apache License 2.0
594 stars 264 forks source link

Use apicurio registry to retrieve the schema #4517

Open JoergWende opened 3 years ago

JoergWende commented 3 years ago

I want to get the schema from my registry and not store it in my java code - is there any way for a producer to connect to a registry and retrieve schema and its version and configure the client for this ?

Thanks J.

EricWittmann commented 3 years ago

Yes for sure - but the specifics will depend a lot on your particular use case. For example, are you using Avro schemas or JSON Schema? Or protobuf? Here is an example of using Avro:

https://github.com/Apicurio/apicurio-registry-examples/blob/master/simple-avro-maven/src/main/java/io/apicurio/registry/examples/simple/avro/maven/SimpleAvroMavenExample.java

That example will fail if the schema is not already registered. It also shows how the apicurio registry maven plugin can be used to do that registration.

Can you provide some additional details about what you're trying to accomplish?

JoergWende commented 3 years ago

Thanks Eric - that helps. I'm trying to connect to the Apicuro instance provided by IBM Event Streams and create(Registry_URL) returns :

Okt 21, 2020 8:49:57 AM io.apicurio.registry.client.request.RequestHandler$ResultCallback handleError
SCHWERWIEGEND: Error getting call result
java.lang.RuntimeException: java.net.UnknownServiceException: Unable to find acceptable protocols. isFallback=false, modes=[ConnectionSpec(cipherSuites=[TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA], tlsVersions=[TLS_1_3, TLS_1_2], supportsTlsExtensions=true), ConnectionSpec()], supported protocols=[TLSv1]
    at io.apicurio.registry.utils.ConcurrentUtil.get(ConcurrentUtil.java:43)
    at io.apicurio.registry.utils.ConcurrentUtil.get(ConcurrentUtil.java:27)
    at io.apicurio.registry.client.request.RequestHandler$ResultCallback.getResult(RequestHandler.java:49)
    at io.apicurio.registry.client.request.RequestHandler.execute(RequestHandler.java:20)
    at io.apicurio.registry.client.RegistryRestClientImpl.getLatestArtifact(RegistryRestClientImpl.java:227)
    at Producer.main(Producer.java:91)
JoergWende commented 3 years ago

Update: works against a Red Hat Integration Service Registry with a non-secure endpoint. Had to change the code for reading the results thus:

        RegistryRestClient client = RegistryRestClientFactory
                .create(REGISTRY_URL);
        String schemaData = null;
        String artifactId = subjectName;
        try (InputStream latestArtifact = client.getLatestArtifact(artifactId)) {
            try (BufferedReader br = new BufferedReader(new InputStreamReader(latestArtifact, Charset.forName("UTF-8")))) {
                schemaData= br.lines().collect(Collectors.joining(System.lineSeparator()));
            }
katheris commented 3 years ago

Hi @JoergWende, what form is the REGISTRY_URL you provide? Is it a service address e.g my-service.prod.svc.cluster.local, or a Route address or an IP address?

JoergWende commented 3 years ago

does not work: String REGISTRY_URL ="https://:@eventstreams-public-address"; works: String REGISTRY_URL = "http://example-apicurioregistry-public-address/api"; J.

katheris commented 3 years ago

@JoergWende The standalone Apicurio Registry operator does not have authentication in front of it, however when running as part of Event Streams it does. For the first address you need to generate some credentials in the Event Streams UI and then if e.g. you have username "user" and password "pass" the address would be "https://user:pass@eventstreams-public-address".

JoergWende commented 3 years ago

that is what I did ... and it works for the 'IBM' interface J.

apicurio-bot[bot] commented 6 months ago

Thank you for reporting an issue!

Pinging @andreaTP to respond or triage.