def produce(self, **kwargs):
        '''
            Sends message to kafka by encoding with specified avro schema
            @:param: topic: topic name
            @:param: value: A dictionary object
            @:param: value_schema : Avro schema for value
            @:param: key: A dictionary object
            @:param: key_schema : Avro schema for key
            @:exception: SerializerError
        '''
        # get schemas from  kwargs if defined
        key_schema = kwargs.pop('key_schema', None)
        value_schema = kwargs.pop('value_schema', None)
        topic = kwargs.pop('topic', None)
        if not topic:
            log.error("Topic name not specified.")
            raise ClientError("Topic name not specified.")
        value = kwargs.pop('value', None)
        key = kwargs.pop('key', None)

        # if key_schema is not initialized, fall back on default key_schema passed as construction param.
        if not key_schema:
            key_schema = self.key_schema

        # if value_schema is not initialized, fall back on default value_schema passed as construction param.
        if not value_schema:
            value_schema = self.value_schema

        if value:
            if value_schema:
                value = self._serializer.encode_record_with_schema(
                    topic, value_schema, value)
            else:
                log.error("Schema required for value serialization")
                raise SerializerError("Avro schema required for value")

        if key:
            if key_schema:
                key = self._serializer.encode_record_with_schema(
                    topic, key_schema, key, True)
            else:
                log.error("Schema required for key serialization")
                raise SerializerError("Avro schema required for key")

        self._producer.produce(topic, value, key, **kwargs)
Exemplo n.º 2
0
 def get_compatibility(self, subject=None):
     raise ClientError("not implemented")
Exemplo n.º 3
0
 def update_compatibility(self, level, subject=None):
     raise ClientError("not implemented")
Exemplo n.º 4
0
 def test_compatibility(self, subject, avro_schema, version='latest'):
     raise ClientError("not implemented")