Merge branch 'master' into xxy
# Conflicts: # cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/Demo.javamaster
commit
6c2daa0d7e
|
@ -23,5 +23,11 @@
|
|||
<artifactId>kafka-clients</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 项目公共核心 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -89,7 +89,6 @@
|
|||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-kafka</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package com.muyu.mqtt;
|
||||
package com.muyu.server.mqtt;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.common.kafka.constants.KafkaConstants;
|
||||
|
||||
import com.muyu.domain.CarMessage;
|
||||
import com.muyu.service.CarMessageService;
|
||||
import com.muyu.server.service.CarMessageService;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
//@Component
|
||||
@Component
|
||||
public class Demo {
|
||||
@Resource
|
||||
private CarMessageService service;
|
||||
|
@ -24,10 +24,11 @@ public class Demo {
|
|||
private KafkaProducer<String, String> kafkaProducer;
|
||||
@PostConstruct
|
||||
public void test() {
|
||||
|
||||
String topic = "vehicle";
|
||||
String content = "Message from MqttPublishSample";
|
||||
int qos = 2;
|
||||
String broker = "tcp://60.204.221.52:1883";
|
||||
String broker = "tcp://106.15.136.7:1883";
|
||||
String clientId = "JavaSample";
|
||||
|
||||
try {
|
||||
|
@ -48,7 +49,7 @@ public class Demo {
|
|||
@Override
|
||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||
|
||||
List<CarMessage> list= service.selectCarMessage(1);
|
||||
List<CarMessage> list= service.selectCarMessageList(1,2);
|
||||
String str = new String( mqttMessage.getPayload() );
|
||||
System.out.println(str);
|
||||
String[] test = str.split(" ");
|
||||
|
@ -81,7 +82,7 @@ public class Demo {
|
|||
results[i] = futures.get(i).get();
|
||||
}
|
||||
String jsonString = JSONObject.toJSONString( results );
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<>( KafkaConstants.KafkaTopic, jsonString);
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<>( "carJsons", jsonString);
|
||||
kafkaProducer.send(producerRecord);
|
||||
}
|
||||
// 接收信息
|
||||
|
|
8
pom.xml
8
pom.xml
|
@ -42,6 +42,7 @@
|
|||
<hutool.version>5.8.27</hutool.version>
|
||||
<knife4j-openapi3.version>4.1.0</knife4j-openapi3.version>
|
||||
<xxl-job-core.version>2.4.1</xxl-job-core.version>
|
||||
<kafka.version>3.6.3</kafka.version>
|
||||
</properties>
|
||||
|
||||
<!-- 依赖声明 -->
|
||||
|
@ -218,6 +219,13 @@
|
|||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--kafka-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-kafka</artifactId>
|
||||
<version>${kafka.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 分布式事务 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
|
|
Loading…
Reference in New Issue