Created
August 17, 2015 01:42
-
-
Save ShigeoTejima/7487b3e655254d7d2127 to your computer and use it in GitHub Desktop.
jms in spring boot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spring.hornetq.mode=embedded | |
spring.hornetq.embedded.enabled=true | |
spring.hornetq.embedded.queues=hello |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.test.demo.web; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.jms.annotation.JmsListener; | |
import org.springframework.jms.core.JmsMessagingTemplate; | |
import org.springframework.messaging.Message; | |
import org.springframework.messaging.support.MessageBuilder; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
@RestController | |
@RequestMapping("hello") | |
public class Hello { | |
private static final Logger log = LoggerFactory.getLogger(Hello.class); | |
@Autowired | |
JmsMessagingTemplate jmsMessagingTemplate; | |
@RequestMapping("jms") | |
public String jms() { | |
Message<String> message = MessageBuilder | |
.withPayload("Hello JMS !") | |
.build(); | |
jmsMessagingTemplate.send("hello", message); | |
return "jms!"; | |
} | |
@JmsListener(destination = "hello", concurrency = "1-5") | |
void handleHelloMessage(Message<String> message) { | |
log.info("received! {}", message); | |
try { | |
Thread.sleep(10*1000); | |
} catch (InterruptedException ex) { | |
log.error(ex.getMessage(), ex); | |
} | |
log.info("msg={}", message.getPayload()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- add --> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-hornetq</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.hornetq</groupId> | |
<artifactId>hornetq-jms-server</artifactId> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment