Saturday, 12 February 2022

Kafka Producer

We start producing messages to Kafka by creating a ProducerRecord, which must

include the topic we want to send the record to and a value. Optionally, we can also

specify a key and/or a partition. Once we send the ProducerRecord, the first thing the

producer will do is serialize the key and value objects to ByteArrays so they can be

sent over the network.

Next, the data is sent to a partitioner. If we specified a partition in the

ProducerRecord, the partitioner doesn’t do anything and simply returns the partition

we specified. If we didn’t, the partitioner will choose a partition for us, usually based

on the ProducerRecord key. Once a partition is selected, the producer knows which

topic and partition the record will go to. It then adds the record to a batch of records

that will also be sent to the same topic and partition. A separate thread is responsible

for sending those batches of records to the appropriate Kafka brokers.

When the broker receives the messages, it sends back a response. If the messages

were successfully written to Kafka, it will return a RecordMetadata object with the

topic, partition, and the offset of the record within the partition. If the broker failed

to write the messages, it will return an error. When the producer receives an error, it

may retry sending the message a few more times before giving up and returning an

error



Once we instantiate a producer, it is time to start sending messages. There are three

primary methods of sending messages:

Fire-and-forget

We send a message to the server and don’t really care if it arrives succesfully or

not. Most of the time, it will arrive successfully, since Kafka is highly available

and the producer will retry sending messages automatically. However, some mes‐

sages will get lost using this method.

Synchronous send

We send a message, the send() method returns a Future object, and we use get()

to wait on the future and see if the send() was successful or not.

Asynchronous send

We call the send() method with a callback function, which gets triggered when it

receives a response from the Kafka broker. 



acks

The acks parameter controls how many partition replicas must receive the record

before the producer can consider the write successful. This option has a significant

impact on how likely messages are to be lost. There are three allowed values for the

acks parameter: 0, 1, all

Monday, 31 January 2022

Update MySQL database engine

 SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_NAME = 'tabel_name' AND TABLE_SCHEMA='db_name';

ALTER TABLE table_name ENGINE = INNODB;

Friday, 3 September 2021

install java in ubuntu

 #Login as root

sudo su

#create jdk directory
mkdir /opt/jdk

#uncompress, change to your file name
tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk

#check if files are there
#ls /opt/jdk

#update alternatives so the command java point to the new jdk 
update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100


#update alternatives so the command javac point to the new jdk 
update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100

#check if java command is pointing to " link currently points to /opt/jdk/jdk1.8.0_05/bin/java"
update-alternatives --display java

#check if java command is pointing to " link currently points to /opt/jdk/jdk1.8.0_05/bin/javac"
update-alternatives --display javac

#check if java is running
java -version


sudo  update-alternatives --config java

Wednesday, 25 August 2021

Docker sample

 FROM maven:3.6.0-jdk-8-alpine AS MAVEN_BUILD

MAINTAINER Sushil
COPY pom.xml /build/
COPY src /build/src/
WORKDIR /build/
RUN mvn package
FROM openjdk:8-jre-alpine
WORKDIR /app
COPY --from=MAVEN_BUILD /build/target/name.jar /app/
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "name.jar"]

docker command

 


sudo docker image build -t sushil/verification ./


sudo docker container run -d -p 8087:8080 sushil/verification


list of images::


sudo docker ps


sudo docker logs -f d44b2b216e16


sudo docker exec -it d44b2b216e16 sh


tail -f verification.log


help:  https://dzone.com/articles/build-package-and-run-spring-boot-apps-with-docker



stop::


docker stop <container-name>

Saturday, 31 July 2021

Cassandra

 https://www.simplilearn.com/tutorials/big-data-tutorial/cassandra-architecture

Monday, 24 May 2021

Heap Sort(max heap)

 public class HeapSortNew {

    public static void main(String[] args) {

        int[] arr = {4,1,7,2,3,8,10};

        int n= arr.length;


        for(int i=n/2-1;i>=0;i--){

            heapify(arr,n,i);

        }


        System.out.println(Arrays.toString(arr));



        for(int i=n-1;i>=0;i--){

            swap(arr,i,0);

            heapify(arr,i,0);

        }

        System.out.println(Arrays.toString(arr));




    }


    static void heapify(int[] arr, int n, int i){

        int l = 2*i+1;

        int r = 2*i+2;


        int largest = i;



        if(l<n){

            if(arr[l]>arr[largest]){

                largest = l;

            }

        }


        if(r<n){

            if(arr[r]>arr[largest]){

                largest = r;

            }

        }


        //if value get updated

        if(largest!=i){

            swap(arr,i,largest);

            heapify(arr,n,largest);

        }


    }


    static void swap(int[] arr, int i, int j){

        int temp = arr[i];

        arr[i]  =arr[j];

        arr[j]=temp;

    }


}


output:
[10, 3, 8, 2, 1, 4, 7]
[1, 2, 3, 4, 7, 8, 10]he

links for Data Structure

  1) 𝐁𝐞𝐜𝐨𝐦𝐞 𝐌𝐚𝐬𝐭𝐞𝐫 𝐢𝐧 𝐋𝐢𝐧𝐤𝐞𝐝 𝐋𝐢𝐬𝐭:  https://lnkd.in/gXQux4zj 2) 𝐀𝐥𝐥 𝐭𝐲𝐩𝐞𝐬 𝐨𝐟 𝐓𝐫𝐞𝐞 𝐓𝐫𝐚𝐯𝐞𝐫𝐬𝐚𝐥𝐬...