Adding on demand producer to send messages.

This commit is contained in:
amrutprabhu
2021-12-11 12:29:24 +01:00
parent 8762f97c9c
commit 29cbea478b
3 changed files with 21 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
package com.amrut.prabhu;
import com.amrut.prabhu.dto.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class KafkaProducer {
@Autowired
private StreamBridge streamBridge;
@Scheduled(cron = "*/2 * * * * *")
public void sendMessage(){
streamBridge.send("producer-out-0",new Message(" jack from Stream bridge"));
}
}

View File

@@ -4,11 +4,13 @@ import com.amrut.prabhu.dto.Message;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.util.function.Consumer;
import java.util.function.Supplier;
@SpringBootApplication
@EnableScheduling
public class SpringCloudStreamKafkaApplication {
public static void main(String[] args) {

View File

@@ -14,7 +14,6 @@ public class MessageDeSerializer implements Deserializer<Message> {
@Override
public Message deserialize(String topic, byte[] data) {
try {
return objectMapper.readValue(new String(data), Message.class);
} catch (IOException e) {
throw new SerializationException(e);