第12章 消息服务
- 12.1 JMS
- 1. 简介
- 2. ActiveMQ安装
- Linux安装命令
- 3. 整合SpringBoot
- ******************************************************
12.1 JMS
1. 简介
2. ActiveMQ安装
Linux安装命令
//下载
wget http://mirrors.hust.edu.cn/apache/activemq/5.15.16/apache-activemg-5.15.16-bin.tar.gz
//解压
Tar -zxvf apache-activemg-5.15.16-bin.tar.gz
//启动
cd apache-activemq-5.15.16
cd bin/
./activemq start
3. 整合SpringBoot
Spring Boot为ActiveMQ配置提供了相关的“Starter”,因此整合非常容易。首先创建SpringBoot项目,添加ActiveMQ依赖,代码如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
然后在 application.properties 中进行连接配置,代码如下:
spring.activemq.broker-url=tcp://192.168.66.129:61616
spring.activemq.packages.trust-all=true
spring.activemq.user=admin
spring.activemq.password=admin
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import javax.jms.Queue;
/**
* 启动程序
*
* @author ruoyi
*/
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class RuoYiApplication {
public static void main(String[] args) {
// System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(RuoYiApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" +
" .-------. ____ __ \n" +
" | _ _ \\ \\ \\ / / \n" +
" | ( ' ) | \\ _. / ' \n" +
" |(_ o _) / _( )_ .' \n" +
" | (_,_).' __ ___(_ o _)' \n" +
" | |\\ \\ | || |(_,_)' \n" +
" | | \\ `' /| `-' / \n" +
" | | \\ / \\ / \n" +
" ''-' `'-' `-..-' ");
}
/**
* amq消息对列
*
* @return
*/
@Bean
Queue queue() {
return new ActiveMQQueue("amq");
}
}