File tree Expand file tree Collapse file tree 8 files changed +190
-0
lines changed
Expand file tree Collapse file tree 8 files changed +190
-0
lines changed Original file line number Diff line number Diff line change @@ -9,3 +9,7 @@ SpringBootCodeBase.iml
99/springBoot-Report /target /
1010/SpringBoot-Redis /target /
1111/springBoot-zookeeper /springBoot-zookeeper.iml
12+ /SpringBoot-MyBatis-Advances /target /
13+ /springBoot-Report /target /
14+ /springBoot-RocketMq /target /
15+ /springBoot-zookeeper /target /
Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
3+
4+ <parent >
5+ <artifactId >SpringBootCodeBase</artifactId >
6+ <groupId >com.fancv</groupId >
7+ <version >1.0-SNAPSHOT</version >
8+ </parent >
9+
10+ <modelVersion >4.0.0</modelVersion >
11+
12+ <artifactId >springBoot-RocketMq</artifactId >
13+
14+ <properties >
15+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
16+ </properties >
17+
18+ <dependencies >
19+
20+ <dependency >
21+ <groupId >org.apache.rocketmq</groupId >
22+ <artifactId >rocketmq-spring-boot-starter</artifactId >
23+ <version >2.2.0</version >
24+ </dependency >
25+
26+
27+ <dependency >
28+ <groupId >junit</groupId >
29+ <artifactId >junit</artifactId >
30+ <version >3.8.1</version >
31+ <scope >test</scope >
32+ </dependency >
33+ </dependencies >
34+ </project >
Original file line number Diff line number Diff line change 1+ package com .fancv ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+
6+ /**
7+ * Hello world!
8+ */
9+ @ SpringBootApplication
10+ public class SpringBootRocketMqApp {
11+ public static void main (String [] args ) {
12+ SpringApplication .run (SpringBootRocketMqApp .class , args );
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ package com .fancv .rocketMq ;
2+
3+ import com .fancv .service .DemoService ;
4+ import org .apache .rocketmq .common .message .MessageExt ;
5+ import org .apache .rocketmq .spring .annotation .RocketMQMessageListener ;
6+ import org .apache .rocketmq .spring .core .RocketMQListener ;
7+ import org .slf4j .Logger ;
8+ import org .slf4j .LoggerFactory ;
9+ import org .springframework .beans .factory .annotation .Autowired ;
10+ import org .springframework .stereotype .Service ;
11+
12+ @ Service
13+ @ RocketMQMessageListener (topic = "${rocketmq.topic}" , consumerGroup = "${rocketmq.consumer.group_a}" ,
14+ selectorExpression = "${rocketmq.tags_a}" )
15+ public class RocketmqConsumer implements RocketMQListener <MessageExt > {
16+ Logger logger = LoggerFactory .getLogger (RocketmqConsumer .class );
17+
18+ @ Autowired
19+ DemoService demoService ;
20+
21+ @ Override
22+ public void onMessage (MessageExt message ) {
23+ String msgBody = new String (message .getBody ());
24+ String serviceName = message .getTags ();
25+ logger .info ("本次消费服务名称: tags-a {}" , msgBody );
26+ demoService .getStart (serviceName );
27+
28+ }
29+ }
30+
31+
Original file line number Diff line number Diff line change 1+ package com .fancv .rocketMq ;
2+
3+ import com .fancv .service .DemoService ;
4+ import org .apache .rocketmq .common .message .MessageExt ;
5+ import org .apache .rocketmq .spring .annotation .RocketMQMessageListener ;
6+ import org .apache .rocketmq .spring .core .RocketMQListener ;
7+ import org .slf4j .Logger ;
8+ import org .slf4j .LoggerFactory ;
9+ import org .springframework .beans .factory .annotation .Autowired ;
10+ import org .springframework .stereotype .Service ;
11+
12+ @ Service
13+ @ RocketMQMessageListener (topic = "${rocketmq.topic}" , consumerGroup = "${rocketmq.consumer.group_b}" ,
14+ selectorExpression = "${rocketmq.tags_b}" )
15+ public class RocketmqConsumerTow implements RocketMQListener <MessageExt > {
16+ Logger logger = LoggerFactory .getLogger (RocketmqConsumerTow .class );
17+
18+ @ Autowired
19+ DemoService demoService ;
20+
21+ @ Override
22+ public void onMessage (MessageExt message ) {
23+ String msgBody = new String (message .getBody ());
24+ String serviceName = message .getTags ();
25+ logger .info ("本次消费服务名称:tags_b {}" , msgBody );
26+ demoService .getStart (serviceName );
27+
28+ }
29+ }
30+
31+
Original file line number Diff line number Diff line change 1+ package com .fancv .service ;
2+
3+ import lombok .extern .slf4j .Slf4j ;
4+ import org .springframework .stereotype .Service ;
5+
6+ /**
7+ *
8+ */
9+ @ Service
10+ @ Slf4j
11+ public class DemoService {
12+
13+ public String getStart (String num ) {
14+
15+ System .out .println ("业务逻辑开始运行" );
16+ log .info ("this num :{}" , num );
17+ return "ok" ;
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ server :
2+ servlet :
3+ application-display-name : rocket-MQ
4+ port : 8083
5+ spring :
6+ application :
7+
8+ name : springboot-rocketMq
9+
10+
11+ rocketmq :
12+ topic : my-1
13+ consumer :
14+ group_a : ' consumer_a'
15+ group_b : ' consumer_b'
16+ tags_a : ' A'
17+ tags_b : ' B'
18+ name-server : ' 192.168.0.23:9876'
19+
Original file line number Diff line number Diff line change 1+ package com .fancv ;
2+
3+ import junit .framework .Test ;
4+ import junit .framework .TestCase ;
5+ import junit .framework .TestSuite ;
6+
7+ /**
8+ * Unit test for simple App.
9+ */
10+ public class AppTest
11+ extends TestCase
12+ {
13+ /**
14+ * Create the test case
15+ *
16+ * @param testName name of the test case
17+ */
18+ public AppTest ( String testName )
19+ {
20+ super ( testName );
21+ }
22+
23+ /**
24+ * @return the suite of tests being tested
25+ */
26+ public static Test suite ()
27+ {
28+ return new TestSuite ( AppTest .class );
29+ }
30+
31+ /**
32+ * Rigourous Test :-)
33+ */
34+ public void testApp ()
35+ {
36+ assertTrue ( true );
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments