예제 #1
0
def create_input_serializer(avro, binary, state):
    if binary:
        input_serializer = RawSerializer(RawSerializerConfig(scheme="raw"))
    elif avro:
        input_serializer = RegistryAvroSerializer(
            RegistryAvroSerializerConfig(scheme="reg-avro", schema_registry_uri=state.config.schema_registry)
        )
    else:
        input_serializer = StringSerializer(StringSerializerConfig(scheme="str"))
    input_message_serializer = MessageSerializer(key_serializer=input_serializer, value_serializer=input_serializer)
    return input_message_serializer
예제 #2
0
def create_input_message_serializer(directory: pathlib.Path, avro: bool,
                                    binary: bool) -> MessageSerializer:
    if avro:
        serializer = RegistryAvroSerializer(
            RegistryAvroSerializerConfig(
                scheme="reg-avro", schema_registry_uri=f"path:///{directory}"))
    elif binary:
        serializer = RawSerializer(RawSerializerConfig(scheme="raw"))
    else:
        serializer = StringSerializer(StringSerializerConfig(scheme="str"))
    return MessageSerializer(key_serializer=serializer,
                             value_serializer=serializer)
예제 #3
0
def create_output_message_serializer(
    write_to_stdout: bool, directory: pathlib.Path, avro: bool, binary: bool
) -> MessageSerializer:
    if avro and write_to_stdout:
        serializer = JsonSerializer(JsonSerializerConfig(scheme="json"))
    elif avro and not write_to_stdout:
        serializer = RegistryAvroSerializer(
            RegistryAvroSerializerConfig(scheme="reg-avro", schema_registry_uri=f"path:///{directory}")
        )
    elif binary:
        serializer = RawSerializer(RawSerializerConfig(scheme="raw"))
    else:
        serializer = StringSerializer(StringSerializerConfig(scheme="str"))
    return MessageSerializer(key_serializer=serializer, value_serializer=serializer)
예제 #4
0
def create_output_serializer(avro: bool, binary: bool, topic: str, state: State) -> MessageSerializer:
    if binary and avro:
        raise ValueError("Cannot set data to be interpreted as binary AND avro.")

    elif binary:
        key_serializer = RawSerializer(RawSerializerConfig(scheme="raw"))
        value_serializer = key_serializer

    elif avro:
        config = RegistryAvroSerializerConfig(scheme="reg-avro", schema_registry_uri=state.config.schema_registry)
        key_serializer = RegistryAvroSerializer(config.with_key_subject_for_topic(topic))
        value_serializer = RegistryAvroSerializer(config.with_value_subject_for_topic(topic))
    else:
        key_serializer = StringSerializer(StringSerializerConfig(scheme="str"))
        value_serializer = key_serializer

    message_serializer = MessageSerializer(key_serializer=key_serializer, value_serializer=value_serializer)
    return message_serializer
def case_string_serializer() -> DataSerializer:
    return StringSerializer(StringSerializerConfig(scheme="str"))
예제 #6
0
 def _create_default_input_serializer(self) -> MessageSerializer:
     serializer = StringSerializer(config=StringSerializerConfig(
         scheme="str"))
     return MessageSerializer(key_serializer=serializer,
                              value_serializer=serializer)