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
ConstructorsConstructorDescriptionKafkaIasiosProducer(SimpleStringProducer stringProducer, String topic, IasValueStringSerializer serializer) Build a KafkaIasioProducer. -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()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.intvoidpush(Collection<IASValue<?>> values) Asynchronously pushes a set of IASValues in a kafka topic.voidpush(Collection<IASValue<?>> values, int timeout, TimeUnit unit) Synchronously pushes the passed values in the topic with default key and partition.voidpush(Collection<IASValue<?>> values, Integer partition, String key) Asynchronously pushes a set of IASValues in a kafka topic.voidSynchronously pushes the passed value in the topic.voidAsynchronously pushes a IASValue in a kafka topic with default partition and keyvoidSynchronously pushes the passed value in the topic with default key and partition.voidAsynchronously pushes a IASValue in a kafka topic.voidSynchronously pushes the passed value in the topicvoidsetUp()Initialize the producer with default propertiesvoidsetUp(Properties props) Initialize the producer with the given propertiesvoidtearDown()Closes the producer
-
Constructor Details
-
KafkaIasiosProducer
public KafkaIasiosProducer(SimpleStringProducer stringProducer, String topic, IasValueStringSerializer serializer) Build a KafkaIasioProducer. Normally theSimpleStringProduceris only one in a process unless there are performance issues: in that case it might help to instantiate a new SimpleStringProducer.- Parameters:
stringProducer- TheSimpleStringProducerto 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 notnullIASValue 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 notnullIASValue 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 notnullvalue 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 notnullvalue 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 notnullnor 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 notnullnor 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 notnullnor 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 notnullnor 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
-