merlimat commented on a change in pull request #3904: [go schema] support go 
schema for pulsar-client-go
URL: https://github.com/apache/pulsar/pull/3904#discussion_r273743033
 
 

 ##########
 File path: pulsar-client-go/pulsar/schema_test.go
 ##########
 @@ -0,0 +1,502 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package pulsar
+
+import (
+       "context"
+       "testing"
+
+       log "github.com/apache/pulsar/pulsar-client-go/logutil"
+       "github.com/apache/pulsar/pulsar-client-go/pulsar/pb"
+       "github.com/stretchr/testify/assert"
+)
+
+type testSchema struct {
+       ID   int    `json:"id"`
+       Name string `json:"name"`
+}
+
+func TestJsonSchema(t *testing.T) {
+       // create client
+       lookupUrl := "pulsar://localhost:6650"
+       client, err := NewClient(ClientOptions{
+               URL: lookupUrl,
+       })
+       assert.Nil(t, err)
+       defer client.Close()
+
+       // create producer
+       js := new(JsonSchema)
+       schema, err := js.Serialize(testSchema{
+               ID:   100,
+               Name: "pulsar",
+       })
+       str := string(schema)
+       schemaJsonInfo := NewSchemaInfo("jsonTopic", str, JSON)
 
 Review comment:
   @wolfstudy Yes, the API really will depend on the language ergonomics, 
though the main idea is to have a "type-safe" API (to the max extent) and allow 
user to precisely define the schema.
   
   In Java this is don through POJO definitions (and recently we added option 
to override the schema definition directly).
   https://pulsar.apache.org/docs/en/client-libraries-java/#schemas
   
   In Python, since it's not possible to extract a meaningful schema from an 
class, we have added the concept of `Record` base class that can be used to 
declare the schema: 
https://pulsar.apache.org/docs/en/client-libraries-python/#schema 
   
   In Go, I would expect that we should be able to convert the `json:'adas'` 
annotations from a struct into an Avro schema definitition for the struct, or 
that the Avro library will be able to do that directly for Avro.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to