Skip to content

Commit

Permalink
添加Spring Boot模式消费消息的注释
Browse files Browse the repository at this point in the history
  • Loading branch information
metaphysical-road committed Jun 26, 2023
1 parent 08cf2b5 commit 1a85022
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

/**
* 第一种消费消息模式:监听器自动消费消息
* 第二种消费消息的模式:RocketMQTemplate模式
* 线上只允许使用一种
*/
@SpringBootApplication
@EnableDiscoveryClient
public class UseSpringBootConsumeApplication {
public class
UseSpringBootConsumeApplication {
public static void main(String[] args) {
SpringApplication.run(UseSpringBootConsumeApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public void startConsume(){
executorService.submit(new ConsumeMessage());
}

/**
* 第二种消费消息的模式:RocketMQTemplate模式
*/
class ConsumeMessage implements Runnable {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
@Service
@RocketMQMessageListener(topic = "${rocketmq.consumer.topic}", consumerGroup = "use-spring-boot-access-rocketmq")
public class StringConsumer implements RocketMQListener<String> {

/**
* 第一种消费消息模式:监听器自动消费消息
* @param message
*/
@Override
public void onMessage(String message) {
System.out.printf("------- StringConsumer received: %s \n", message);
Expand Down

0 comments on commit 1a85022

Please sign in to comment.