apache / apache/pulsar-client-python

Use Protobuf as schema registry for python client

未關閉
#49 3 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
75
分支
53
PR 合併指標
30 天內沒有已合併 PR

描述

**Is your enhancement request related to a problem? Please describe.**
I was wondering if there was a possibility to use protobuf in order to auto-generate code for my pulsar client services (both producer and consumer). By reading documentation and searching on the internet I was able to find some references related to other languages (like Java or C).

**Describe the solution you'd like**
I've tried to do something like that, obviously without success.
```
import _pulsar
from pulsar import Client
from pulsar.schema import Schema

from generated_schema.test_pb2 import TodoList

class ProtobufSchema(Schema):
def __init__(self, record_cls):
super(ProtobufSchema,
self).__init__(record_cls, _pulsar.SchemaType.PROTOBUF, ,
'PROTOBUF')

def encode(self, obj):
self._validate_object_type(obj)
return obj.SerializeToString()

def decode(self, data):
return self._record_cls.FromString(data)

def test():
client = Client('pulsar://localhost:6650')
producer = client.create_producer(topic='persistent://cloudacademy/accounts/sso-configuration-updated.v1',
schema=ProtobufSchema(TodoList))

producer.send(TodoList(owner_id=1, owner_name='test'))
```

**Additional context**
For a reference, I'm expecting something like the integration with Avro, but instead with Protobuf (with autogenerated classes)

貢獻指南

開啟貢獻指南

研究方向

先閱讀現有的 Avro 整合以及 issue 中引用的 schema 文件,然後追蹤 Schema 如何提供 schema 類型和序列化行為。當產生的 protobuf 類別可以同時用於 producer 和 consumer,且 schema 註冊與編碼/解碼能夠一致地運作時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
backend, distributed-systems
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。