springboot has been embedded support for activemq internal test demo
1. Add activemq
<dependency>
<group Id>org.springframework.boot</group Id>
<actifact Id>spring-boot-starter-activemq<actifact Id>
</dependency>
2. Create the Message Queuing objects
@Bean
public Queue queue() {
return new ActiveMQQueue("active.queue");
}
3. Create a message producer
@RestController
public class Queue Controller {
@Autowired // inject message queue template, if no bean [@Resource this comment to solve this problem]
private JmsMessagingTemplate jmsMessagingTemplate;
@Autowire
private Queue queue;
@RequestMapping("/send")
public void send() {
this.msMessagingTemplate.convertAndSend (this.queue, "new message!"); // specified destination convertAndSend sent to the current queue queue content for the new message!
}
}
4. Create a message listener
@RestController
public class CustomerController {
@JmsListener (destination = "active.queue") // jms monitor from spring4.1
public void read ActiveQueue(String message) {
System.out.println("receive:" + message);
}
}
5. Start projects to test
localhost:8080/send
Extended external activemq
1. Profile Configuration activemq port services [local or remote configuration yourself]
spring.activemq.broker-url=tcp://192.168.1.111:66666
2. Start remote management page 192.168.1 activemq enter 8161 enter the default username: admin password: admin;
Click Manager activeMQ broker = "Click Queues
3. Start project enter: localhost: 8080 / send to
(By 92.168.1. 8161 to third data message queue to view the case)