apache / apache/pulsar-client-python

Use Protobuf as schema registry for python client

Đang mở
#49 3 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
75
Fork
53
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.