-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhengjiaao
committed
Dec 16, 2022
1 parent
85ca97a
commit 621b73b
Showing
9 changed files
with
533 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# starter-amqp | ||
|
||
**MQ消息中间件: rabbitmq** | ||
|
||
- [rabbitmq 官网](https://www.rabbitmq.com/) | ||
- [rabbitmq spring官网](https://spring.io/projects/spring-amqp) | ||
- [rabbitmq github](https://github.com/rabbitmq) | ||
- [rabbitmq 参考](https://www.jianshu.com/p/a205606182e7) | ||
|
||
## 依赖引入 | ||
|
||
```xml | ||
<!--MQ rabbitmq--> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-amqp</artifactId> | ||
<!--内置 amqp-client 5.9.0--> | ||
</dependency> | ||
<!--MQ rabbitmq Json 消息转换器--> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-xml</artifactId> | ||
</dependency> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.zja</groupId> | ||
<artifactId>spring-boot-starter-test-root</artifactId> | ||
<version>2.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>com.zja</groupId> | ||
<artifactId>starter-amqp</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<!--MQ rabbitmq--> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-amqp</artifactId> | ||
<!--内置 amqp-client 5.9.0--> | ||
</dependency> | ||
<!--MQ rabbitmq Json 消息转换器--> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-xml</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-boot-starter</artifactId> | ||
<version>3.0.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2022-12-16 10:22 | ||
* @Since: | ||
*/ | ||
package com.zja; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* http://localhost:8080/swagger-ui/index.html#/ | ||
*/ | ||
@SpringBootApplication | ||
public class AmqpApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AmqpApplication.class, args); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
starter-amqp/src/main/java/com/zja/config/FanoutConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2022-12-14 17:15 | ||
* @Since: | ||
*/ | ||
package com.zja.config; | ||
|
||
import org.springframework.amqp.core.Binding; | ||
import org.springframework.amqp.core.BindingBuilder; | ||
import org.springframework.amqp.core.FanoutExchange; | ||
import org.springframework.amqp.core.Queue; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class FanoutConfig { | ||
|
||
/** | ||
* 声明交换机 | ||
* @return Fanout类型交换机 | ||
*/ | ||
@Bean | ||
public FanoutExchange fanoutExchange() { | ||
return new FanoutExchange("stone.fanout"); | ||
} | ||
|
||
/** | ||
* 第1个队列 | ||
*/ | ||
@Bean | ||
public Queue fanoutQueue1() { | ||
return new Queue("fanout.queue1"); | ||
} | ||
|
||
/** | ||
* 绑定队列和交换机 | ||
*/ | ||
@Bean | ||
public Binding bindingQueue1(Queue fanoutQueue1, FanoutExchange fanoutExchange) { | ||
return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange); | ||
} | ||
|
||
/** | ||
* 第2个队列 | ||
*/ | ||
@Bean | ||
public Queue fanoutQueue2() { | ||
return new Queue("fanout.queue2"); | ||
} | ||
|
||
/** | ||
* 绑定队列和交换机 | ||
*/ | ||
@Bean | ||
public Binding bindingQueue2(Queue fanoutQueue2, FanoutExchange fanoutExchange) { | ||
return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
starter-amqp/src/main/java/com/zja/config/RabbitConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2022-12-14 17:54 | ||
* @Since: | ||
*/ | ||
package com.zja.config; | ||
|
||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; | ||
import org.springframework.amqp.support.converter.MessageConverter; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class RabbitConfig { | ||
|
||
/** | ||
* 配置 Json 消息转换器 | ||
*/ | ||
@Bean | ||
public MessageConverter jsonMessageConverter() { | ||
return new Jackson2JsonMessageConverter(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
starter-amqp/src/main/java/com/zja/config/Swagger3Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2021-10-22 15:17 | ||
* @Since: | ||
*/ | ||
package com.zja.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import springfox.documentation.builders.ApiInfoBuilder; | ||
import springfox.documentation.builders.PathSelectors; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.oas.annotations.EnableOpenApi; | ||
import springfox.documentation.service.ApiInfo; | ||
import springfox.documentation.service.Contact; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
|
||
/** | ||
* http://localhost:8080/swagger-ui/index.html#/ | ||
*/ | ||
@EnableOpenApi | ||
@Configuration | ||
public class Swagger3Config { | ||
|
||
@Bean | ||
public Docket createRestApi() { | ||
return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo()).select() | ||
.apis(RequestHandlerSelectors.basePackage("com.zja")).paths(PathSelectors.any()) | ||
.build(); | ||
} | ||
|
||
private ApiInfo apiInfo() { | ||
return new ApiInfoBuilder().title("提供rest服务").description("我是描述").contact(new Contact("联系人", "www.baidu.com", "[email protected]")) | ||
.version("1.0").build(); | ||
} | ||
} |
Oops, something went wrong.