Ejemplo n.º 1
0
    def send_heartbeat_message(self, topic, msg):
        assert topic is not None
        assert msg is not None

        try:
            if self.kproducer_heartbeat is None:
                if self.kafka_endpoint.startswith('@'):
                    _k_endpoint = get_endpoint_from_consul(
                        self.consul_endpoint, self.kafka_endpoint[1:])
                else:
                    _k_endpoint = self.kafka_endpoint

                # Using 2 seconds timeout for heartbeat producer; default of 5 minutes is too long
                self.kproducer_heartbeat = _kafkaProducer({
                    'bootstrap.servers': _k_endpoint,
                    'default.topic.config': {
                        'message.timeout.ms': 2000
                    },
                })

            log.debug('sending-kafka-heartbeat-message', topic=topic)
            msgs = [msg]

            self.kproducer_heartbeat.produce(
                topic, msg, callback=self.handle_kafka_delivery_report)

        except Exception as e:
            self.faulty = True
            self.alive_state_handler.callback(self.alive)
            log.error('failed-to-send-kafka-heartbeat-msg', e=e)
Ejemplo n.º 2
0
    def _get_kafka_producer(self):

        try:

            if self.kafka_endpoint.startswith('@'):
                try:
                    _k_endpoint = get_endpoint_from_consul(
                        self.consul_endpoint, self.kafka_endpoint[1:])
                    log.debug('found-kafka-service', endpoint=_k_endpoint)

                except Exception as e:
                    log.exception('no-kafka-service-in-consul', e=e)

                    self.kproducer = None
                    self.kclient = None
                    return
            else:
                _k_endpoint = self.kafka_endpoint
            self.kproducer = _kafkaProducer({
                'bootstrap.servers': _k_endpoint,
            })
            pass
        except Exception as e:
            log.exception('failed-get-kafka-producer', e=e)
            return
Ejemplo n.º 3
0
    def _get_kafka_producer(self):
        try:
            _k_endpoint = self.kafka_endpoint
            self.kproducer = _kafkaProducer({
                'bootstrap.servers': _k_endpoint,
            })

        except Exception as e:
            log.exception('failed-get-kafka-producer', e=e)
            return