File tree 5 files changed +85
-0
lines changed
Part-7 Spring Boot TEST/5.SpringBoot-JMS-ActiveMQ-Logback
java/com/urunov/jmsactivemq
5 files changed +85
-0
lines changed Original file line number Diff line number Diff line change 38
38
<artifactId >spring-boot-starter-test</artifactId >
39
39
<scope >test</scope >
40
40
</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 >
41
47
</dependencies >
42
48
43
49
<build >
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
2
+ spring.activemq.in-memory =false
3
+ spring.activemq.pool.enabled =false
4
+ server.port =8081
5
+ spring.activemq.broker-url =tcp://localhost:61616
You can’t perform that action at this time.
0 commit comments