Tuesday, January 14, 2020

7. KAFKA : Sample Program5 : With Future object return

7. KAFKA : Sample Program5 : With Future object return


//Future object -SynchronousProducer.java (get())
#####################################-
 -> get() -> returns Future object wchich contains metadata of msg which partition it went in...
metadata.partition()
metadata.offset()

-----------------------------------------------
Key is : Key1
Message is sent to Partition no 4 and offset 1
SynchronousProducer Completed with success.
----------------------------------------------

Run program any number of times it will go to same partition (i.e Partition no 4), because Key = Key1 ("Key1".hashCode() will be always same)

Change the key -> so that it will got to different partition, bez which partition decides based on key

//changed key to -> String key = "Key12345";

-----------------------------------------------
Key is : Key12345
Message is sent to Partition no 0 and offset 0
SynchronousProducer Completed with success.
----------------------------------------------




No comments:

Post a Comment