Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7356233

Browse files
committed
Spring Boot ActiveMQ JMS
1 parent 714affe commit 7356233

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

‎Part-7 Spring Boot TEST/5.SpringBoot-JMS-ActiveMQ-Logback/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
<artifactId>spring-boot-starter-test</artifactId>
3939
<scope>test</scope>
4040
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-web</artifactId>
44+
<version>RELEASE</version>
45+
<scope>compile</scope>
46+
</dependency>
4147
</dependencies>
4248

4349
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.urunov.jmsactivemq.config;
2+
3+
import org.apache.activemq.ActiveMQConnectionFactory;
4+
import org.apache.activemq.command.ActiveMQQueue;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.jms.core.JmsTemplate;
9+
10+
import java.util.Queue;
11+
12+
@Configuration
13+
public class Config {
14+
//
15+
@Value("${activemq.broker-url}")
16+
private String brokerUrl;
17+
@Bean
18+
public Queue queue() {
19+
return (Queue) new ActiveMQQueue("standalone.queue");
20+
}
21+
22+
@Bean
23+
public ActiveMQConnectionFactory activeMQConnectionFactory() {
24+
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
25+
factory.setBrokerURL(brokerUrl);
26+
27+
return factory;
28+
}
29+
30+
@Bean
31+
public JmsTemplate jmsTemplate(){
32+
return new JmsTemplate(activeMQConnectionFactory());
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.urunov.jmsactivemq.listener;
2+
3+
import org.springframework.jms.annotation.JmsListener;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
public class Consumer {
8+
//
9+
@JmsListener(destination = "standalone.queue")
10+
public void consume(String message){
11+
System.out.println("Received Message" + message);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.urunov.jmsactivemq.resource;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.jms.core.JmsTemplate;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
import javax.jms.Destination;
11+
import java.util.Queue;
12+
13+
@RestController
14+
@RequestMapping("/rest/publish")
15+
public class ProducerResource {
16+
//
17+
@Autowired
18+
JmsTemplate jmsTemplate;
19+
20+
@Autowired
21+
Queue queue;
22+
23+
@GetMapping("/message")
24+
public String publish(@PathVariable("message") final String message){
25+
jmsTemplate.convertAndSend((Destination) queue, message);
26+
return "Published Successfully";
27+
}
28+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11

2+
spring.activemq.in-memory=false
3+
spring.activemq.pool.enabled=false
4+
server.port=8081
5+
spring.activemq.broker-url=tcp://localhost:61616

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /