Class KafkaIasiosProducer
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 Summary
ConstructorDescriptionKafkaIasiosProducer
(SimpleStringProducer stringProducer, String topic, IasValueStringSerializer serializer) Build a KafkaIasioProducer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.int
void
push
(Collection<IASValue<?>> values) Asynchronously pushes a set of IASValues in a kafka topic.void
push
(Collection<IASValue<?>> values, int timeout, TimeUnit unit) Synchronously pushes the passed values in the topic with default key and partition.void
push
(Collection<IASValue<?>> values, Integer partition, String key) Asynchronously pushes a set of IASValues in a kafka topic.void
Synchronously pushes the passed value in the topic.void
Asynchronously pushes a IASValue in a kafka topic with default partition and keyvoid
Synchronously pushes the passed value in the topic with default key and partition.void
Asynchronously pushes a IASValue in a kafka topic.void
Synchronously pushes the passed value in the topicvoid
setUp()
Initialize the producer with default propertiesvoid
setUp
(Properties props) Initialize the producer with the given propertiesvoid
tearDown()
Closes the producer
-
Constructor Details
-
KafkaIasiosProducer
public KafkaIasiosProducer(SimpleStringProducer stringProducer, String topic, IasValueStringSerializer serializer) Build a KafkaIasioProducer. Normally theSimpleStringProducer
is only one in a process unless there are performance issues: in that case it might help to instantiate a new SimpleStringProducer.- Parameters:
stringProducer
- TheSimpleStringProducer
to push strings in the topictopic
- The topic to send strings toserializer
- 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 notnull
IASValue to publish in the topicpartition
- The partitionkey
- The keytimeout
- the time to wait if sync is setunit
- the unit of the timeout- Throws:
KafkaUtilsException
- in case of error or timeout sending the value
-
push
Synchronously pushes the passed value in the topic with default key and partition.- Parameters:
value
- The notnull
IASValue to publish in the topictimeout
- the time to wait if sync is setunit
- the unit of the timeout- Throws:
KafkaUtilsException
- in case of error or timeout sending the value
-
push
Asynchronously pushes a IASValue in a kafka topic.- Parameters:
value
- The notnull
value to publish in the topicpartition
- The partitionkey
- The key- Throws:
KafkaUtilsException
- in case of error sending the value
-
push
Asynchronously pushes a IASValue in a kafka topic with default partition and key- Parameters:
value
- The notnull
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 notnull
nor empty collection of values to publish in the topicpartition
- The partition to use for sending all the values in the coillectionkey
- The key to use for sending all the values in the coillection- Throws:
KafkaUtilsException
- in case of error sending the value
-
push
Asynchronously pushes a set of IASValues in a kafka topic.This method pushes each value with the default partition/key.
- Parameters:
values
- The notnull
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 notnull
nor empty collection of values to publish in the topictimeout
- the time to wait if sync is setunit
- 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 notnull
nor empty collection of values to publish in the topicpartition
- The partitionkey
- The keytimeout
- the time to wait if sync is setunit
- 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
Initialize the producer with the given propertiesServers 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
-