def handler():
    consumer = Consumer(
        CONSUMER_CONFIG,
        topics=['location.events'],
        key_deserializer=AvroDeserializer(
            schema_registry_url=config.SCHEMA_REGISTRY_URL),
        value_deserializer=AvroDeserializer(
            schema_registry_url=config.SCHEMA_REGISTRY_URL),
    )

    for message in consumer:
        handle(message)
        consumer.commit()
示例#2
0
def handler():
    consumer = Consumer(
        CONSUMER_CONFIG,
        topics=['location_ingress'],
        key_deserializer=AvroDeserializer(
            schema_registry_url=os.environ['SCHEMA_REGISTRY_URL']),
        value_deserializer=AvroDeserializer(
            schema_registry_url=os.environ['SCHEMA_REGISTRY_URL']),
    )

    for message in consumer:
        message_rep = repr_message(message)

        if message.value().schema.fullname == 'locations.LocationReceived':
            # Do handle the message
            logger.info("Handling message", **message_rep)
        else:
            logger.warning("Message not handled", **message_rep)

        consumer.commit()
示例#3
0
def consumer():
    return Consumer(CONSUMER_CONFIG, [TEST_TOPIC])
示例#4
0
import uuid
from pprint import pprint

from kafkian import Consumer
from kafkian.message import Message

from kafkian_example import config

CONSUMER_CONFIG = {
    'bootstrap.servers': config.KAFKA_BOOTSTRAP_SERVERS,
    'default.topic.config': {
        'auto.offset.reset': 'earliest',
    },
    'group.id': str(uuid.uuid4())
}

consumer = Consumer(
    CONSUMER_CONFIG,
    topics=["test"],
)


def repr_message(message: Message):
    return {
        'topic': message.topic,
        'partition': message.partition,
        'timestamp': message.timestamp,
        'key': message.key,
        'value': message.value,
    }
示例#5
0
def consumer():
    return Consumer(CONSUMER_CONFIG, [TEST_TOPIC],
                    value_deserializer=deserializer)
def consumer():
    return Consumer(CONSUMER_CONFIG, [TEST_TOPIC],
                    key_deserializer=AvroDeserializer(
                        schema_registry_url=SCHEMA_REGISTRY_URL),
                    value_deserializer=AvroDeserializer(
                        schema_registry_url=SCHEMA_REGISTRY_URL))