Skip to content

Commit

Permalink
Step1: add simple HornetQ demo
Browse files Browse the repository at this point in the history
Demonstrate a simple use of the HornetQ auto-configuration. An external
broker running on localhost is required.
  • Loading branch information
snicoll committed Nov 13, 2015
1 parent 6fffa8d commit fccd82e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hornetq-sample-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hornetq</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
43 changes: 43 additions & 0 deletions hornetq-sample-app/src/main/java/demo/DemoApplication.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@SpringBootApplication
public class DemoApplication {
Expand All @@ -10,4 +19,38 @@ public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}

@Service
static class MessageProducer implements CommandLineRunner {

private static final Logger logger = LoggerFactory.getLogger(MessageProducer.class);

private final JmsTemplate jmsTemplate;

@Autowired
public MessageProducer(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}

@Override
public void run(String... strings) throws Exception {
process("Hello World");
}

public void process(String msg) {
logger.info("============= Sending " + msg);
this.jmsTemplate.convertAndSend("testQueue", msg);
}
}

@Component
static class MessageHandler {

private static final Logger logger = LoggerFactory.getLogger(MessageHandler.class);

@JmsListener(destination = "testQueue")
public void processMsg(String msg) {
logger.info("============= Received " + msg);
}
}

}

0 comments on commit fccd82e

Please sign in to comment.