|
|
@@ -8,6 +8,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.Random;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
@@ -20,10 +21,16 @@ import java.util.concurrent.TimeUnit;
|
|
|
public class KafkaService {
|
|
|
private final KafkaTemplate<String, Object> kafkaTemplate;
|
|
|
|
|
|
- @Scheduled(initialDelay = 0, fixedRate = 1, timeUnit = TimeUnit.MINUTES)
|
|
|
+ /**
|
|
|
+ * 模拟定时发送方
|
|
|
+ */
|
|
|
+ @Scheduled(initialDelay = 0, fixedRate = 1, timeUnit = TimeUnit.SECONDS)
|
|
|
public void job() {
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("123", LocalDateTimeUtil.formatNormal(LocalDateTimeUtil.now()));
|
|
|
- kafkaTemplate.send("iot.data", jsonObject.toJSONString());
|
|
|
+ for (int i = 0; i < 3000; i++) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("123", LocalDateTimeUtil.formatNormal(LocalDateTimeUtil.now()));
|
|
|
+ jsonObject.put("temp", new Random().nextInt());
|
|
|
+ kafkaTemplate.send("iot.data", jsonObject.toJSONString());
|
|
|
+ }
|
|
|
}
|
|
|
}
|