Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7b83286

Browse files
committed
add SpringBoot + RocketMQ
1 parente9a053e commit7b83286

File tree

11 files changed

+291
-0
lines changed

11 files changed

+291
-0
lines changed

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@
22
springboot-cli for quickly build project base springboot
33

44
springboot-cli主要用于能够快速搭建基于springboot的项目框架,例如SpringBoot+SpringCloud,SpringBoot+SpringSecurity等,方便开发者们能够开箱即用。
5+
6+
#demo
7+
8+
- Oauth2
9+
10+
- SSO
11+
12+
- SpringBoot + RocketMQ
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
packagecom.springbootcli.springbootspringsecurityoauth2resource.config;
2+
3+
importorg.springframework.context.annotation.Bean;
4+
importorg.springframework.context.annotation.Configuration;
5+
importorg.springframework.data.redis.connection.RedisConnectionFactory;
6+
importorg.springframework.security.config.annotation.web.builders.HttpSecurity;
7+
importorg.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
8+
importorg.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
9+
importorg.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
10+
importorg.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
11+
12+
importjavax.annotation.Resource;
13+
14+
/**
15+
* 资源服务器配置
16+
* @author lhy
17+
* @date 2021/7/4
18+
*/
19+
@Configuration
20+
@EnableResourceServer
21+
publicclassResourceServerConfigextendsResourceServerConfigurerAdapter {
22+
23+
@Resource
24+
privateRedisConnectionFactoryredisConnectionFactory;
25+
26+
@Bean
27+
publicRedisTokenStoreredisTokenStore() {
28+
returnnewRedisTokenStore(redisConnectionFactory);
29+
}
30+
31+
@Override
32+
publicvoidconfigure(HttpSecurityhttp)throwsException {
33+
http.csrf().disable()// 取消跨站请求伪造保护
34+
.requestMatchers().antMatchers("/**")
35+
.and()
36+
.authorizeRequests()
37+
.antMatchers("/**").authenticated();
38+
}
39+
40+
@Override
41+
publicvoidconfigure(ResourceServerSecurityConfigurerresource)throwsException{
42+
resource.tokenStore(redisTokenStore());
43+
}
44+
}

‎rocketmq-consumer/pom.xml‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.3.1.RELEASE</version>
9+
<relativePath/><!-- lookup parent from repository-->
10+
</parent>
11+
<groupId>com.springcli</groupId>
12+
<artifactId>rocketmq-consumer</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>rocketmqconsumer</name>
15+
<description>rocketmqconsumer</description>
16+
<properties>
17+
<java.version>1.8</java.version>
18+
</properties>
19+
<dependencies>
20+
21+
<dependency>
22+
<groupId>org.apache.rocketmq</groupId>
23+
<artifactId>rocketmq-spring-boot-starter</artifactId>
24+
<version>2.1.0</version>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-web</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.projectlombok</groupId>
34+
<artifactId>lombok</artifactId>
35+
<optional>true</optional>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-test</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
</dependencies>
43+
44+
<build>
45+
<plugins>
46+
<plugin>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-maven-plugin</artifactId>
49+
<configuration>
50+
<excludes>
51+
<exclude>
52+
<groupId>org.projectlombok</groupId>
53+
<artifactId>lombok</artifactId>
54+
</exclude>
55+
</excludes>
56+
</configuration>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
61+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
packagecom.springcli.rocketmqconsumer;
2+
3+
importorg.springframework.boot.SpringApplication;
4+
importorg.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
publicclassRocketmqconsumerApplication {
8+
9+
publicstaticvoidmain(String[]args) {
10+
SpringApplication.run(RocketmqconsumerApplication.class,args);
11+
}
12+
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
packagecom.springcli.rocketmqconsumer.mq;
2+
3+
importorg.apache.rocketmq.spring.annotation.RocketMQMessageListener;
4+
importorg.apache.rocketmq.spring.core.RocketMQListener;
5+
importorg.springframework.stereotype.Service;
6+
7+
/**
8+
* @author lhy
9+
* @date 2021/7/25
10+
*/
11+
@Service
12+
@RocketMQMessageListener(topic ="${springboot.cli.rocketmq-consume.topic}",
13+
consumerGroup ="${spirngboot.cli.rocketmq-consume.group}",
14+
nameServer ="${spirngboot.cli.rocketmq-consume.namesrv.address}")
15+
publicclassConsumerDemoimplementsRocketMQListener<String> {
16+
17+
@Override
18+
publicvoidonMessage(Strings) {
19+
System.out.println("收到消息了,内容是:" +s);
20+
}
21+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
server.port=8082
2+
3+
# rocketmqťů´ĄĹäÖĂ
4+
springboot.cli.rocketmq-consume.topic=springboot-cli-topic
5+
spirngboot.cli.rocketmq-consume.group=springboot-rocketmq-group
6+
spirngboot.cli.rocketmq-consume.namesrv.address=127.0.0.1:9876
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
packagecom.springcli.rocketmqconsumer;
2+
3+
importorg.junit.jupiter.api.Test;
4+
importorg.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
classRocketmqconsumerApplicationTests {
8+
9+
@Test
10+
voidcontextLoads() {
11+
}
12+
13+
}

‎rocketmq-producer/pom.xml‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.3.1.RELEASE</version>
9+
<relativePath/><!-- lookup parent from repository-->
10+
</parent>
11+
<groupId>com.springcli</groupId>
12+
<artifactId>rocketmq-producer</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>rocketmqproducer</name>
15+
<description>rocketmqproducer</description>
16+
<properties>
17+
<java.version>1.8</java.version>
18+
</properties>
19+
<dependencies>
20+
21+
<dependency>
22+
<groupId>org.apache.rocketmq</groupId>
23+
<artifactId>rocketmq-spring-boot-starter</artifactId>
24+
<version>2.1.0</version>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-web</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.projectlombok</groupId>
34+
<artifactId>lombok</artifactId>
35+
<optional>true</optional>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-test</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
</dependencies>
43+
44+
<build>
45+
<plugins>
46+
<plugin>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-maven-plugin</artifactId>
49+
<configuration>
50+
<excludes>
51+
<exclude>
52+
<groupId>org.projectlombok</groupId>
53+
<artifactId>lombok</artifactId>
54+
</exclude>
55+
</excludes>
56+
</configuration>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
61+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
packagecom.springcli.rocketmqdemo;
2+
3+
importorg.springframework.boot.SpringApplication;
4+
importorg.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
publicclassRocketmqProducerApplication {
8+
9+
publicstaticvoidmain(String[]args) {
10+
SpringApplication.run(RocketmqProducerApplication.class,args);
11+
}
12+
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
server.port=8081
2+
3+
# rocketmq基础配置
4+
springboot.cli.rocketmq-producer.topic=springboot-cli-topic
5+
spirngboot.cli.rocketmq-namesrv.address=127.0.0.1:9876
6+
spirngboot.cli.rocketmq-producer.group=springboot-rocketmq-group
7+
8+
# rocketmq
9+
rocketmq.name-server=${spirngboot.cli.rocketmq-namesrv.address}
10+
rocketmq.producer.group=${spirngboot.cli.rocketmq-producer.group}
11+
# 发送消息超时时间
12+
rocketmq.producer.send-message-timeout=30000
13+
rocketmq.producer.compress-message-body-threshold=4096
14+
rocketmq.producer.max-message-size=4194304
15+
rocketmq.producer.retry-times-when-send-async-failed=0
16+
# 开启重试
17+
rocketmq.producer.retry-next-server=true
18+
# 重试次数
19+
rocketmq.producer.retry-times-when-send-failed=2
20+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp