package com.example.demo.consumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import com.example.demo.User;
import com.example.demo.UserRepository;
@Service
public class MessageConsumer {
@Autowired
UserRepository userrepo;
@Autowired
EmailSenderService senderservice;
@KafkaListener(topics="k2-topic",groupId="mygroup2")
public void consumeFromTopic(String message) {
System.out.println("consumed message "+message);
String msg = message;
String vin = msg.substring(0, 17);
String verified = msg.substring(17, 18);
int sp = Integer.parseInt(msg.substring(18,21));
String alert = msg.substring(21,22);
char ch = alert.charAt(0);
String timeStamp = msg.substring(22);
String bd = "Hai There !\n Your CAR VIN NO IS : "+vin+"\nYou're crossing your SPEED
LIMIT : "+sp+"\nPlease Drive slowly\nSafe driving saves life.";
if(ch=='y') senderservice.sendEmail(bd);
User obj = new User(vin,verified,sp,alert,timeStamp);
userrepo.save(obj);
}
}
Hai in this code i am receiving message from kafka. based on that message i am sending mail before storing the message into database. But i want to send the mail after storing the data. if the response from db is ok then i will send mail otherwise not. So How to get DB response and how to know message is storing in DB or NOT. Iam using cassandra DB. Please Help.