Class StatKafkaProducerFactory

Class Documentation

class StatKafkaProducerFactory

A factory class that produces instances of StatKafkaProducer.

This class will used the connection string to work out what producer class instantiate. This helps in unit testing to ensure that we don’t need a Kafka instance up.

Public Functions

StatKafkaProducerFactory()

Construct the factory.

virtual ~StatKafkaProducerFactory() = default

Default destructor.

std::shared_ptr<StatKafkaProducer> create_producer(const KafkaConnectionDetails &connection_details)

Create a producer instance for a given Kafka connection string.

Parameters

connection_details – the connection string of the Kafka to connect to.

Throws

std::runtime_exception – if connection string is invalid.

Returns

std::shared_ptr<StatKafkaProducer>

void register_producer_scheme(std::string scheme, ProducerFuncPtr producer_func_ptr)

Register function pointer that creates a shared pointer to StatKafkaProducer instance.

This function pointer requires a string argument that is the address of the connection and returns as shared_ptr to a StatKafkaProducer instance. An example of this is passing a lambda to accepts as string and then it calls std::make_shared on a base class.

The implementation of the no-arg constructor of StatKafkaProducerFactory registers the CppKafkaProducer but this is also used in the unit testing framework to allow for mocked producers.

Parameters
  • scheme – the connection scheme

  • producer_func_ptr – a function pointer that creates a shared pointer to a StatKafkaProducer instance.