mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-04-26 16:59:35 +08:00
update 修改包名为org.dromara
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package org.dromara.stream;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
|
||||
/**
|
||||
* SpringCloud-Stream-MQ 案例项目
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class RuoYiStreamMqApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication application = new SpringApplication(RuoYiStreamMqApplication.class);
|
||||
application.setApplicationStartup(new BufferingApplicationStartup(2048));
|
||||
application.run(args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ MQ案例模块启动成功 ლ(´ڡ`ლ)゙ ");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.dromara.stream.controller;
|
||||
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.stream.mq.producer.DelayProducer;
|
||||
import org.dromara.stream.mq.producer.LogStreamProducer;
|
||||
import org.dromara.stream.mq.producer.TestStreamProducer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 测试mq
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/test-mq")
|
||||
public class TestMqController {
|
||||
|
||||
private final DelayProducer delayProducer;
|
||||
private final TestStreamProducer testStreamProducer;
|
||||
private final LogStreamProducer logStreamProducer;
|
||||
|
||||
/**
|
||||
* 发送消息Rabbitmq
|
||||
*
|
||||
* @param msg 消息内容
|
||||
* @param delay 延时时间
|
||||
*/
|
||||
@GetMapping("/sendRabbitmq")
|
||||
public R<Void> sendRabbitmq(String msg, Long delay) {
|
||||
delayProducer.sendMsg(msg, delay);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息Rocketmq
|
||||
*
|
||||
* @param msg 消息内容
|
||||
*/
|
||||
@GetMapping("/sendRocketmq")
|
||||
public R<Void> sendRocketmq(String msg) {
|
||||
testStreamProducer.streamTestMsg(msg);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息Kafka
|
||||
*
|
||||
* @param msg 消息内容
|
||||
*/
|
||||
@GetMapping("/sendKafka")
|
||||
public R<Void> sendKafka(String msg) {
|
||||
logStreamProducer.streamLogMsg(msg);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.dromara.stream.mq;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class TestMessaging {
|
||||
/**
|
||||
* 消息id
|
||||
*/
|
||||
private String msgId;
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
private String msgText;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.dromara.stream.mq.consumer;
|
||||
|
||||
|
||||
import org.dromara.stream.mq.TestMessaging;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DelayConsumer {
|
||||
|
||||
@Bean
|
||||
Consumer<TestMessaging> delay() {
|
||||
log.info("初始化订阅");
|
||||
return obj -> {
|
||||
log.info("消息接收成功:" + obj);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.dromara.stream.mq.consumer;
|
||||
|
||||
import org.dromara.stream.mq.TestMessaging;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class LogStreamConsumer {
|
||||
|
||||
@Bean
|
||||
Consumer<TestMessaging> log() {
|
||||
log.info("初始化订阅");
|
||||
return msg -> {
|
||||
log.info("通过stream消费到消息 => {}", msg.toString());
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.dromara.stream.mq.consumer;
|
||||
|
||||
import org.dromara.stream.mq.TestMessaging;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TestStreamConsumer {
|
||||
|
||||
@Bean
|
||||
Consumer<TestMessaging> demo() {
|
||||
log.info("初始化订阅");
|
||||
return msg -> {
|
||||
log.info("通过stream消费到消息 => {}", msg.toString());
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.dromara.stream.mq.producer;
|
||||
|
||||
import org.dromara.stream.mq.TestMessaging;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.stream.function.StreamBridge;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
public class DelayProducer {
|
||||
|
||||
@Autowired
|
||||
private StreamBridge streamBridge;
|
||||
|
||||
public void sendMsg(String msg, Long delay) {
|
||||
// 构建消息对象
|
||||
TestMessaging testMessaging = new TestMessaging()
|
||||
.setMsgId(UUID.randomUUID().toString())
|
||||
.setMsgText(msg);
|
||||
Message<TestMessaging> message = MessageBuilder.withPayload(testMessaging)
|
||||
.setHeader("x-delay", delay).build();
|
||||
streamBridge.send("delay-out-0", message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.dromara.stream.mq.producer;
|
||||
|
||||
import org.dromara.stream.mq.TestMessaging;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.stream.function.StreamBridge;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
public class LogStreamProducer {
|
||||
|
||||
@Autowired
|
||||
private StreamBridge streamBridge;
|
||||
|
||||
public void streamLogMsg(String msg) {
|
||||
// 构建消息对象
|
||||
TestMessaging testMessaging = new TestMessaging()
|
||||
.setMsgId(UUID.randomUUID().toString())
|
||||
.setMsgText(msg);
|
||||
streamBridge.send("log-out-0", MessageBuilder.withPayload(testMessaging).build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.dromara.stream.mq.producer;
|
||||
|
||||
import org.dromara.stream.mq.TestMessaging;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.stream.function.StreamBridge;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
public class TestStreamProducer {
|
||||
|
||||
@Autowired
|
||||
private StreamBridge streamBridge;
|
||||
|
||||
public void streamTestMsg(String msg) {
|
||||
// 构建消息对象
|
||||
TestMessaging testMessaging = new TestMessaging()
|
||||
.setMsgId(UUID.randomUUID().toString())
|
||||
.setMsgText(msg);
|
||||
streamBridge.send("demo-out-0", MessageBuilder.withPayload(testMessaging).build());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user