From cbd5a98b785d5a31bb6ebd203f0e8315224bc7c5 Mon Sep 17 00:00:00 2001 From: Cool <747682928@qq.com> Date: Wed, 14 Aug 2024 23:55:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 ++++ pom.xml | 19 +++++++++++++ .../controller/IndexController.java | 6 +++++ .../com/cool/mqconsumer/entity/Message.java | 13 +++++++++ .../cool/mqconsumer/mq/InformSmsListen.java | 27 +++++++++++++++++++ .../cool/mqconsumer/service/SmsService.java | 10 +++++++ .../com/cool/mqconsumer/util/JsonUtils.java | 11 ++++++++ src/main/resources/application.yml | 11 +++++++- 8 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 src/main/java/com/cool/mqconsumer/controller/IndexController.java create mode 100644 src/main/java/com/cool/mqconsumer/entity/Message.java create mode 100644 src/main/java/com/cool/mqconsumer/mq/InformSmsListen.java create mode 100644 src/main/java/com/cool/mqconsumer/service/SmsService.java create mode 100644 src/main/java/com/cool/mqconsumer/util/JsonUtils.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fe381b4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/target/ + +/.idea/ + + diff --git a/pom.xml b/pom.xml index 48fe4bf..c3e92eb 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,25 @@ org.springframework.boot spring-boot-starter + + org.springframework.boot + spring-boot-starter-web + + + junit + junit + 4.13.2 + + + org.projectlombok + lombok + 1.18.26 + + + com.alibaba + fastjson + 1.2.83 + org.springframework.boot spring-boot-starter-amqp diff --git a/src/main/java/com/cool/mqconsumer/controller/IndexController.java b/src/main/java/com/cool/mqconsumer/controller/IndexController.java new file mode 100644 index 0000000..46e39ac --- /dev/null +++ b/src/main/java/com/cool/mqconsumer/controller/IndexController.java @@ -0,0 +1,6 @@ +package com.cool.mqconsumer.controller; + + +public class IndexController { + +} diff --git a/src/main/java/com/cool/mqconsumer/entity/Message.java b/src/main/java/com/cool/mqconsumer/entity/Message.java new file mode 100644 index 0000000..fcc900e --- /dev/null +++ b/src/main/java/com/cool/mqconsumer/entity/Message.java @@ -0,0 +1,13 @@ +package com.cool.mqconsumer.entity; + +import lombok.Data; + +@Data +public class Message { + private String nickname; + private String pic; + private String sendTime; + private String message; + + private String account; +} diff --git a/src/main/java/com/cool/mqconsumer/mq/InformSmsListen.java b/src/main/java/com/cool/mqconsumer/mq/InformSmsListen.java new file mode 100644 index 0000000..7dbafd5 --- /dev/null +++ b/src/main/java/com/cool/mqconsumer/mq/InformSmsListen.java @@ -0,0 +1,27 @@ +package com.cool.mqconsumer.mq; + +import com.alibaba.fastjson.JSON; +import com.cool.mqconsumer.entity.Message; +import org.springframework.amqp.core.ExchangeTypes; +import org.springframework.amqp.rabbit.annotation.Exchange; +import org.springframework.amqp.rabbit.annotation.Queue; +import org.springframework.amqp.rabbit.annotation.QueueBinding; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Service; + +@Service +public class InformSmsListen { + + + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = "queue_inform_sms"), + exchange = @Exchange(name = "exchange_topics_inform", type = ExchangeTypes.TOPIC), + key = {"inform.cool.sms.message"} + )) + public void SmsConsumer(String message) { + System.out.println(message); + Message message1 = JSON.parseObject(message, Message.class); + System.out.println(message1); + } + +} diff --git a/src/main/java/com/cool/mqconsumer/service/SmsService.java b/src/main/java/com/cool/mqconsumer/service/SmsService.java new file mode 100644 index 0000000..9c638f1 --- /dev/null +++ b/src/main/java/com/cool/mqconsumer/service/SmsService.java @@ -0,0 +1,10 @@ +package com.cool.mqconsumer.service; + +import org.springframework.stereotype.Service; + +@Service +public class SmsService { + + + +} diff --git a/src/main/java/com/cool/mqconsumer/util/JsonUtils.java b/src/main/java/com/cool/mqconsumer/util/JsonUtils.java new file mode 100644 index 0000000..ae6838a --- /dev/null +++ b/src/main/java/com/cool/mqconsumer/util/JsonUtils.java @@ -0,0 +1,11 @@ +package com.cool.mqconsumer.util; + +public class JsonUtils { + + +// public T jsonToJavaObject(Class clazz){ +// +// } + + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3fe2722..425177f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,4 +3,13 @@ server: spring: application: - name: Mq-Consumer \ No newline at end of file + name: Mq-Consumer + rabbitmq: + host: 119.29.254.99 + port: 5672 + username: cool + password: cool + virtual-host: / + listener: + simple: + prefetch: 1