Skip to content

Commit a4105ec

Browse files
committed
add rabbitmq
1 parent effaf3f commit a4105ec

29 files changed

+472
-30
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Spring boot使用的各种示例,以最简单、最实用为标准
1212

1313
- [spring-boot-mybaits-xml](https://github.com/ityouknow/spring-boot-starter/tree/master/spring-boot-mybatis-xml):xml配置版本
1414

15-
- [spring-boot-rabbitmq-simple](https://github.com/ityouknow/spring-boot-starter/tree/master/spring-boot-rabbitmq-simple):spring boot和rabbitmq简单应用
15+
- [spring-boot-rabbitmq](https://github.com/ityouknow/spring-boot-starter/tree/master/spring-boot-rabbitmq):spring boot和rabbitmq简单应用
1616

1717

1818

spring-boot-rabbitmq-simple/pom.xml renamed to spring-boot-rabbitmq/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
<modelVersion>4.0.0</modelVersion>
55

66
<groupId>com.neo</groupId>
7-
<artifactId>spring-boot-rabbitmq-simple</artifactId>
7+
<artifactId>spring-boot-rabbitmq</artifactId>
88
<version>1.0.0</version>
99
<packaging>jar</packaging>
1010

11-
<name>spring-boot-rabbitmq-simple</name>
11+
<name>spring-boot-rabbitmq</name>
1212
<description>Demo project for Spring Boot and rabbitmq</description>
1313

1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>1.4.1.RELEASE</version>
17+
<version>1.4.2.RELEASE</version>
1818
<relativePath/> <!-- lookup parent from repository -->
1919
</parent>
2020

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.neo.model;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* Created by summer on 2016/11/29.
7+
*/
8+
public class User implements Serializable{
9+
10+
private String name;
11+
12+
private String pass;
13+
14+
public String getName() {
15+
return name;
16+
}
17+
18+
public void setName(String name) {
19+
this.name = name;
20+
}
21+
22+
public String getPass() {
23+
return pass;
24+
}
25+
26+
public void setPass(String pass) {
27+
this.pass = pass;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
return "User{" +
33+
"name='" + name + '\'' +
34+
", pass='" + pass + '\'' +
35+
'}';
36+
}
37+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.neo.rabbit;
2+
3+
import org.springframework.amqp.core.Binding;
4+
import org.springframework.amqp.core.BindingBuilder;
5+
import org.springframework.amqp.core.FanoutExchange;
6+
import org.springframework.amqp.core.Queue;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.Configuration;
9+
10+
11+
@Configuration
12+
public class FanoutRabbitConfig {
13+
14+
@Bean
15+
public Queue AMessage() {
16+
return new Queue("fanout.A");
17+
}
18+
19+
@Bean
20+
public Queue BMessage() {
21+
return new Queue("fanout.B");
22+
}
23+
24+
@Bean
25+
public Queue CMessage() {
26+
return new Queue("fanout.C");
27+
}
28+
29+
@Bean
30+
FanoutExchange fanoutExchange() {
31+
return new FanoutExchange("fanoutExchange");
32+
}
33+
34+
@Bean
35+
Binding bindingExchangeA(Queue AMessage,FanoutExchange fanoutExchange) {
36+
return BindingBuilder.bind(AMessage).to(fanoutExchange);
37+
}
38+
39+
@Bean
40+
Binding bindingExchangeB(Queue BMessage, FanoutExchange fanoutExchange) {
41+
return BindingBuilder.bind(BMessage).to(fanoutExchange);
42+
}
43+
44+
@Bean
45+
Binding bindingExchangeC(Queue CMessage, FanoutExchange fanoutExchange) {
46+
return BindingBuilder.bind(CMessage).to(fanoutExchange);
47+
}
48+
49+
}

spring-boot-rabbitmq-simple/src/main/java/com/neo/rabbit/RabbitConfig.java renamed to spring-boot-rabbitmq/src/main/java/com/neo/rabbit/RabbitConfig.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ public Queue helloQueue() {
1313
return new Queue("hello");
1414
}
1515

16-
1716
@Bean
1817
public Queue neoQueue() {
1918
return new Queue("neo");
2019
}
2120

21+
@Bean
22+
public Queue objectQueue() {
23+
return new Queue("object");
24+
}
25+
2226

2327
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.neo.rabbit;
2+
3+
import org.springframework.amqp.core.Binding;
4+
import org.springframework.amqp.core.BindingBuilder;
5+
import org.springframework.amqp.core.Queue;
6+
import org.springframework.amqp.core.TopicExchange;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.Configuration;
9+
10+
11+
@Configuration
12+
public class TopicRabbitConfig {
13+
14+
final static String message = "topic.message";
15+
final static String messages = "topic.messages";
16+
17+
@Bean
18+
public Queue queueMessage() {
19+
return new Queue(TopicRabbitConfig.message);
20+
}
21+
22+
@Bean
23+
public Queue queueMessages() {
24+
return new Queue(TopicRabbitConfig.messages);
25+
}
26+
27+
@Bean
28+
TopicExchange exchange() {
29+
return new TopicExchange("topicExchange");
30+
}
31+
32+
@Bean
33+
Binding bindingExchangeMessage(Queue queueMessage, TopicExchange exchange) {
34+
return BindingBuilder.bind(queueMessage).to(exchange).with("topic.message");
35+
}
36+
37+
@Bean
38+
Binding bindingExchangeMessages(Queue queueMessages, TopicExchange exchange) {
39+
return BindingBuilder.bind(queueMessages).to(exchange).with("topic.#");
40+
}
41+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.neo.rabbit.fanout;
2+
3+
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
4+
import org.springframework.amqp.rabbit.annotation.RabbitListener;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
@RabbitListener(queues = "fanout.A")
9+
public class FanoutReceiverA {
10+
11+
@RabbitHandler
12+
public void process(String message) {
13+
System.out.println("fanout Receiver A : " + message);
14+
}
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.neo.rabbit.fanout;
2+
3+
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
4+
import org.springframework.amqp.rabbit.annotation.RabbitListener;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
@RabbitListener(queues = "fanout.B")
9+
public class FanoutReceiverB {
10+
11+
@RabbitHandler
12+
public void process(String message) {
13+
System.out.println("fanout Receiver B: " + message);
14+
}
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.neo.rabbit.fanout;
2+
3+
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
4+
import org.springframework.amqp.rabbit.annotation.RabbitListener;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
@RabbitListener(queues = "fanout.C")
9+
public class FanoutReceiverC {
10+
11+
@RabbitHandler
12+
public void process(String message) {
13+
System.out.println("fanout Receiver C: " + message);
14+
}
15+
16+
}

0 commit comments

Comments
 (0)