File tree Expand file tree Collapse file tree 7 files changed +153
-0
lines changed Expand file tree Collapse file tree 7 files changed +153
-0
lines changed Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" 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 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
4+ <modelVersion >4.0.0</modelVersion >
5+
6+ <groupId >com.didispace</groupId >
7+ <artifactId >rabbitmq-hello</artifactId >
8+ <version >0.0.1-SNAPSHOT</version >
9+ <packaging >jar</packaging >
10+
11+ <name >rabbitmq-hello</name >
12+ <description >Demo project for Spring Boot</description >
13+
14+ <parent >
15+ <groupId >org.springframework.boot</groupId >
16+ <artifactId >spring-boot-starter-parent</artifactId >
17+ <version >1.3.7.RELEASE</version >
18+ <relativePath /> <!-- lookup parent from repository -->
19+ </parent >
20+
21+ <properties >
22+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
23+ <project .reporting.outputEncoding>UTF-8</project .reporting.outputEncoding>
24+ <java .version>1.8</java .version>
25+ </properties >
26+
27+ <dependencies >
28+ <dependency >
29+ <groupId >org.springframework.boot</groupId >
30+ <artifactId >spring-boot-starter-amqp</artifactId >
31+ </dependency >
32+ <dependency >
33+ <groupId >org.springframework.boot</groupId >
34+ <artifactId >spring-boot-starter-test</artifactId >
35+ <scope >test</scope >
36+ </dependency >
37+ </dependencies >
38+ <build >
39+ <plugins >
40+ <plugin >
41+ <groupId >org.springframework.boot</groupId >
42+ <artifactId >spring-boot-maven-plugin</artifactId >
43+ </plugin >
44+ </plugins >
45+ </build >
46+ </project >
Original file line number Diff line number Diff line change 1+ package com .didispace ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+
6+ @ SpringBootApplication
7+ public class HelloApplication {
8+
9+ public static void main (String [] args ) {
10+ SpringApplication .run (HelloApplication .class , args );
11+ }
12+
13+ }
Original file line number Diff line number Diff line change 1+ package com .didispace .rabbit ;
2+
3+ import org .springframework .amqp .core .Queue ;
4+ import org .springframework .context .annotation .Bean ;
5+ import org .springframework .context .annotation .Configuration ;
6+
7+ /**
8+ * @author 翟永超
9+ * @create 2016/9/25.
10+ * @blog http://blog.didispace.com
11+ */
12+ @ Configuration
13+ public class RabbitConfig {
14+
15+ @ Bean
16+ public Queue helloQueue () {
17+ return new Queue ("hello" );
18+ }
19+
20+ }
Original file line number Diff line number Diff line change 1+ package com .didispace .rabbit ;
2+
3+ import org .springframework .amqp .rabbit .annotation .RabbitHandler ;
4+ import org .springframework .amqp .rabbit .annotation .RabbitListener ;
5+ import org .springframework .cache .annotation .Cacheable ;
6+ import org .springframework .stereotype .Component ;
7+
8+ import java .util .Date ;
9+
10+ /**
11+ * @author 翟永超
12+ * @create 2016/9/25.
13+ * @blog http://blog.didispace.com
14+ */
15+ @ Component
16+ @ RabbitListener (queues = "hello" )
17+ public class Receiver {
18+
19+ @ RabbitHandler
20+ public void process (String hello ) {
21+ System .out .println ("Receiver : " + hello );
22+ }
23+
24+ }
Original file line number Diff line number Diff line change 1+ package com .didispace .rabbit ;
2+
3+ import org .springframework .amqp .core .AmqpTemplate ;
4+ import org .springframework .amqp .rabbit .core .RabbitTemplate ;
5+ import org .springframework .beans .factory .annotation .Autowired ;
6+ import org .springframework .stereotype .Component ;
7+
8+ import java .util .Date ;
9+
10+ @ Component
11+ public class Sender {
12+
13+ @ Autowired
14+ private AmqpTemplate rabbitTemplate ;
15+
16+ public void send () {
17+ String context = "hello " + new Date ();
18+ System .out .println ("Sender : " + context );
19+ this .rabbitTemplate .convertAndSend ("hello" , context );
20+ }
21+
22+ }
Original file line number Diff line number Diff line change 1+ spring.application.name =rabbitmq-hello
2+
3+ spring.rabbitmq.host =localhost
4+ spring.rabbitmq.port =5672
5+ spring.rabbitmq.username =springcloud
6+ spring.rabbitmq.password =123456
Original file line number Diff line number Diff line change 1+ package com .didispace ;
2+
3+ import com .didispace .rabbit .Sender ;
4+ import org .junit .Test ;
5+ import org .junit .runner .RunWith ;
6+ import org .springframework .beans .factory .annotation .Autowired ;
7+ import org .springframework .boot .test .SpringApplicationConfiguration ;
8+ import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
9+
10+ @ RunWith (SpringJUnit4ClassRunner .class )
11+ @ SpringApplicationConfiguration (classes = HelloApplication .class )
12+ public class HelloApplicationTests {
13+
14+ @ Autowired
15+ private Sender sender ;
16+
17+ @ Test
18+ public void hello () throws Exception {
19+ sender .send ();
20+ }
21+
22+ }
You can’t perform that action at this time.
0 commit comments