MediaWiki REL1_37
EventRelayerKafka.php
Go to the documentation of this file.
1<?php
2
3use Kafka\Produce;
4
16 protected $config;
17
23 protected $producer;
24
30 public function __construct( array $params ) {
31 parent::__construct( $params );
32
33 $this->config = new HashConfig( $params );
34 if ( !$this->config->has( 'KafkaEventHost' ) ) {
35 throw new InvalidArgumentException( "KafkaEventHost must be configured" );
36 }
37 }
38
43 protected function getKafkaProducer() {
44 if ( !$this->producer ) {
45 $this->producer = Produce::getInstance(
46 null, null, $this->config->get( 'KafkaEventHost' ) );
47 }
48 return $this->producer;
49 }
50
51 protected function doNotify( $channel, array $events ) {
52 $jsonEvents = array_map( 'json_encode', $events );
53 try {
54 $producer = $this->getKafkaProducer();
55 $producer->setMessages( $channel, 0, $jsonEvents );
56 $producer->send();
57 } catch ( \Kafka\Exception $e ) {
58 $this->logger->warning( "Sending events failed: $e" );
59 return false;
60 }
61 return true;
62 }
63}
Event relayer for Apache Kafka.
doNotify( $channel, array $events)
__construct(array $params)
Create Kafka producer.
getKafkaProducer()
Get the producer object from kafka-php.
Config $config
Configuration.
Produce $producer
Kafka producer.
Base class for reliable event relays.
A Config instance which stores all settings as a member variable.
Interface for configuration instances.
Definition Config.php:30