Skip to content

Commit

Permalink
feat(root) 新增 starter-amqp模块
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhengjiaao committed Dec 16, 2022
1 parent 85ca97a commit 621b73b
Show file tree
Hide file tree
Showing 9 changed files with 533 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<modules>
<module>starter-actuator</module>
<module>starter-amqp</module>
<module>starter-aop</module>
<!-- <module>starter-batch</module>-->
<module>starter-cache</module>
Expand Down
24 changes: 24 additions & 0 deletions starter-amqp/README.md
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>
```
48 changes: 48 additions & 0 deletions starter-amqp/pom.xml
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>
24 changes: 24 additions & 0 deletions starter-amqp/src/main/java/com/zja/AmqpApplication.java
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 starter-amqp/src/main/java/com/zja/config/FanoutConfig.java
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 starter-amqp/src/main/java/com/zja/config/RabbitConfig.java
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 starter-amqp/src/main/java/com/zja/config/Swagger3Config.java
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();
}
}
Loading

0 comments on commit 621b73b

Please sign in to comment.