Class KafkaIasiosProducer

java.lang.Object
org.eso.ias.kafkautils.KafkaIasiosProducer

public class KafkaIasiosProducer extends Object
KafkaIasioProducer writes IASValue in the kafka topic by delegating to SimpleStringProducer

The producer converts the IASValues to string with the serializer.

KafkaIasioProducer delegates the publishing to SimpleStringProducer. Normally the SimpleStringProducer is only one in a process unless there are performance issues: in that case it might help to instantiate a new SimpleStringProducer. For methods that do not specify partition and key, the partition is set to the ID of the IASValue and no partition is used.

Author:
acaproni
See Also:
  • Constructor Details

    • KafkaIasiosProducer

      public KafkaIasiosProducer(SimpleStringProducer stringProducer, String topic, IasValueStringSerializer serializer)
      Build a KafkaIasioProducer. Normally the SimpleStringProducer is only one in a process unless there are performance issues: in that case it might help to instantiate a new SimpleStringProducer.
      Parameters:
      stringProducer - The SimpleStringProducer to push strings in the topic
      topic - The topic to send strings to
      serializer - The serializer to convert IASValues to strings
  • Method Details

    • push

      public void push(IASValue<?> value, Integer partition, String key, int timeout, TimeUnit unit) throws KafkaUtilsException
      Synchronously pushes the passed value in the topic
      Parameters:
      value - The not null IASValue to publish in the topic
      partition - The partition
      key - The key
      timeout - the time to wait if sync is set
      unit - the unit of the timeout
      Throws:
      KafkaUtilsException - in case of error or timeout sending the value
    • push

      public void push(IASValue<?> value, int timeout, TimeUnit unit) throws KafkaUtilsException
      Synchronously pushes the passed value in the topic with default key and partition.
      Parameters:
      value - The not null IASValue to publish in the topic
      timeout - the time to wait if sync is set
      unit - the unit of the timeout
      Throws:
      KafkaUtilsException - in case of error or timeout sending the value
    • push

      public void push(IASValue<?> value, Integer partition, String key) throws KafkaUtilsException
      Asynchronously pushes a IASValue in a kafka topic.
      Parameters:
      value - The not null value to publish in the topic
      partition - The partition
      key - The key
      Throws:
      KafkaUtilsException - in case of error sending the value
    • push

      public void push(IASValue<?> value) throws KafkaUtilsException
      Asynchronously pushes a IASValue in a kafka topic with default partition and key
      Parameters:
      value - The not null value to publish in the topic
      Throws:
      KafkaUtilsException - in case of error sending the value
    • push

      public void push(Collection<IASValue<?>> values, Integer partition, String key) throws KafkaUtilsException
      Asynchronously pushes a set of IASValues in a kafka topic.

      This method pushes all the values with the same partition/key so it is not very convenient. You should probably prefer push(Collection)

      Parameters:
      values - The not null nor empty collection of values to publish in the topic
      partition - The partition to use for sending all the values in the coillection
      key - The key to use for sending all the values in the coillection
      Throws:
      KafkaUtilsException - in case of error sending the value
    • push

      public void push(Collection<IASValue<?>> values) throws KafkaUtilsException
      Asynchronously pushes a set of IASValues in a kafka topic.

      This method pushes each value with the default partition/key.

      Parameters:
      values - The not null nor empty collection of values to publish in the topic
      Throws:
      KafkaUtilsException - in case of error sending the value
    • push

      public void push(Collection<IASValue<?>> values, int timeout, TimeUnit unit) throws KafkaUtilsException
      Synchronously pushes the passed values in the topic with default key and partition.

      This method synchronously pushes each value using the passed timeout.

      Parameters:
      values - The not null nor empty collection of values to publish in the topic
      timeout - the time to wait if sync is set
      unit - the unit of the timeout
      Throws:
      KafkaUtilsException - in case of error or timeout sending the value
    • push

      public void push(Collection<IASValue<?>> values, Integer partition, String key, int timeout, TimeUnit unit) throws KafkaUtilsException
      Synchronously pushes the passed value in the topic.

      This method synchronously pushes each value using the passed timeout.

      This method pushes all the values with the same partition/key so it is not very convenient. You should probably prefer push(Collection,int,TimeUnit).

      Parameters:
      values - The not null nor empty collection of values to publish in the topic
      partition - The partition
      key - The key
      timeout - the time to wait if sync is set
      unit - the unit of the timeout
      Throws:
      KafkaUtilsException - in case of error or timeout sending the value
    • flush

      public void flush()
      Ensures all the records have been delivered to the broker especially useful while sending records asynchronously and want be sure they have all been sent.
    • setUp

      public void setUp()
      Initialize the producer with default properties
    • setUp

      public void setUp(Properties props)
      Initialize the producer with the given properties

      Servers and ID passed in the constructor override those in the passed properties

      Parameters:
      props - user defined properties
    • tearDown

      public void tearDown()
      Closes the producer
    • getNumOfValuessSent

      public int getNumOfValuessSent()
      Returns:
      the number of the values sent