class documentation

class ProtobufNativeSchema(Schema): (source)

Constructor: ProtobufNativeSchema(record_cls)

View In Hierarchy

Schema for protobuf messages using the native protobuf binary encoding.

The schema definition is stored as a JSON-encoded ProtobufNativeSchemaData (fileDescriptorSet, rootMessageTypeName, rootFileDescriptorName), which is compatible with the Java client's ProtobufNativeSchema.

Example

import pulsar
from pulsar.schema import ProtobufNativeSchema
from my_proto_pb2 import MyMessage

client = pulsar.Client('pulsar://localhost:6650')
schema = ProtobufNativeSchema(MyMessage)
producer = client.create_producer('my-topic', schema=schema)
consumer = client.subscribe('my-topic', 'my-sub', schema=schema)

message = MyMessage()
message.field = 'value'
producer.send(message)

received = consumer.receive(timeout_millis=5000)
typed_value = received.value()
consumer.acknowledge(received)

assert isinstance(typed_value, MyMessage)
assert typed_value.field == 'value'

consumer.close()
producer.close()
client.close()
Parameters
record_clsA generated protobuf message class (subclass of google.protobuf.message.Message).
Method __init__ Undocumented
Method __str__ Undocumented
Method decode Undocumented
Method encode Undocumented

Inherited from Schema:

Method attach_client Undocumented
Method decode_message Undocumented
Method schema_info Undocumented
Method _validate_object_type Undocumented
Instance Variable _client Undocumented
Instance Variable _record_cls Undocumented
Instance Variable _schema_info Undocumented
def __init__(self, record_cls): (source)

Undocumented

def __str__(self): (source)

Undocumented

def decode(self, data): (source)

Undocumented

def encode(self, obj): (source)

Undocumented