Skip to content

Commit 190c8ef

Browse files
committed
新增jmsdemo
1 parent 05a2b1d commit 190c8ef

File tree

8 files changed

+194
-1
lines changed

8 files changed

+194
-1
lines changed

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ hs_err_pid*
3434
.sts4-cache
3535

3636
### IntelliJ IDEA ###
37-
.idea
37+
*.idea
3838
*.iws
3939
*.iml
4040
*.ipr

Diff for: jms_demo/pom.xml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.fxb</groupId>
7+
<artifactId>jms_demo</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>jms_demo</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>2.0.3.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-activemq</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-web</artifactId>
35+
</dependency>
36+
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+
</plugin>
50+
</plugins>
51+
</build>
52+
53+
54+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.fxb.jms_demo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class JmsDemoApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(JmsDemoApplication.class, args);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.fxb.jms_demo.consumer;
2+
3+
import org.springframework.jms.annotation.JmsListener;
4+
import org.springframework.stereotype.Component;
5+
6+
/**
7+
* Created with IntelliJ IDEA.
8+
* Description: 模拟消息队列接受者
9+
* User: ${fxb}
10+
11+
* Date: 2018-07-20
12+
*/
13+
@Component
14+
public class Comsumer {
15+
//接受消息队列1消息
16+
@JmsListener(destination = "active.queue1")
17+
public void readActiveQueue11(String message){
18+
System.out.println(1+message);
19+
}
20+
21+
//接受消息队列1消息
22+
@JmsListener(destination = "active.queue1")
23+
public void readActiveQueue12(String message){
24+
System.out.println(2+message);
25+
}
26+
27+
//接受消息队列2消息
28+
@JmsListener(destination = "active.queue2")
29+
public void readActiveQueue21(String message){
30+
System.out.println(1+message);
31+
}
32+
33+
//接受消息队列2消息
34+
@JmsListener(destination = "active.queue2")
35+
public void readActiveQueue22(String message){
36+
System.out.println(2+message);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fxb.jms_demo.jmsConfig;
2+
3+
import org.apache.activemq.command.ActiveMQQueue;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
import javax.jms.Queue;
8+
9+
/**
10+
* Created with IntelliJ IDEA.
11+
* Description:
12+
* User: ${fxb}
13+
14+
* Date: 2018-07-20
15+
*/
16+
@Configuration
17+
public class Config {
18+
@Bean(name = "queue2")
19+
public Queue queue2(){
20+
return new ActiveMQQueue("active.queue2");
21+
}
22+
23+
@Bean(name = "queue1")
24+
public Queue queue1(){
25+
return new ActiveMQQueue("active.queue1");
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fxb.jms_demo.publisher;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.beans.factory.annotation.Qualifier;
5+
import org.springframework.jms.core.JmsMessagingTemplate;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import javax.jms.Queue;
10+
11+
12+
/**
13+
* Created with IntelliJ IDEA.
14+
* Description:
15+
* User: ${fxb}
16+
17+
* Date: 2018-07-20
18+
*/
19+
@RestController
20+
public class Producer {
21+
@Autowired
22+
private JmsMessagingTemplate jmsMessagingTemplate;
23+
@Autowired()
24+
@Qualifier("queue2")
25+
private Queue queue2;
26+
27+
@Autowired()
28+
@Qualifier("queue1")
29+
private Queue queue1;
30+
31+
@GetMapping("/queue2")
32+
public void sendMessage1(String message){
33+
jmsMessagingTemplate.convertAndSend(queue2,"I'm from queue2:"+message);
34+
}
35+
36+
@GetMapping("/queue1")
37+
public void sendMessage2(String message){
38+
jmsMessagingTemplate.convertAndSend(queue1,"I'm from queue1:"+message);
39+
}
40+
}

Diff for: jms_demo/src/main/resources/application.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring:
2+
activemq:
3+
broker-url: tcp://localhost:61616
4+
in-memory: true
5+
pool:
6+
enabled: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.fxb.jms_demo;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
@RunWith(SpringRunner.class)
9+
@SpringBootTest
10+
public class JmsDemoApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}

0 commit comments

Comments
 (0)