erlang压缩包:
https://share.weiyun.com/TGhfV8eZ
rabbitMq-server压缩包:
https://share.weiyun.com/ZXbUwWHD
(因为RabbitMQ采用 Erlang 实现的工业级的消息队列(MQ)服务器,所以在安装rabbitMQ之前,需要先安装Erlang;
先安装Erlang
)
rpm -ivh erlang-23.2.3-1.el7.x86_64.rpm
yum install -y socat
rpm -ivh rabbitmq-server-3.8.11-1.el7.noarch.rpm
ps - ef | grep rabbitmq
rabbitmq-server -detached
rabbitmqctl stop
rabbitmq-plugins list
rabbitmq-plugins enable rabbitmq_management
win使用ip+端口登录控制台
因为默认的guest账号只能本地登录 所以我们在创建一个管理员账号进行远程登录
rabbitmqctl add_user admin admin #添加 admin 用户并设置密码
rabbitmqctl set_user_tags admin administrator #添加 admin 用户为administrator角色
rabbitmqctl set_permissions -p "/" admin "." "." ".*" #设置 admin 用户的权限,指定允许访问的vhost以及write/read
rabbitmqctl list_permissions -p / #查看vhost(/)允许哪些用户访问
rabbitmqctl list_users #查看用户列表
安装结束
前期准备工作 创建工程
改jdk版本
改包名
选几个常用的pom
起个项目名字
上面是名字下面是路径
<!--添加AMQP的启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
server:
port: 7000
logging:
level:
root: info
com.joe: debug
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://44.113.77.149:3306/db1?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=GMT%2b8&serverTimezone=Asia/Shanghai
username: root
password: 123456
initialSize: 1
minIdle: 3
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 30000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 打开PSCache,并且指定每个连接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
filters: stat,wall,slf4j
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
hikari:
connection-test-query: select 1
connection-timeout: 60000
idle-timeout: 500000
max-lifetime: 540000
maximum-pool-size: 12
minimum-idle: 10
pool-name: GGLiliKariPool
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
thymeleaf:
check-template: false
check-template-location: false
rabbitmq:
host: 11.113.77.149
port: 5672
username: admin
password: admin
mybatis:
mapperLocations: classpath:com/joe/demo/mapper/*.xml
type-aliases-package: com.joe.demo.entity # 实体类所在的位置
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
/**
* 声明队列
*/
@Configuration
public class RabbitMQConfig {
@Bean
public Queue a(){
return new Queue("a") ;
}
@Bean
public Queue b(){
return new Queue("b") ;
}
@Bean
public Queue c(){
return new Queue("c") ;
}
@Bean
public Queue d(){
return new Queue("d") ;
}
}
@Autowired
private AmqpTemplate rabbitmqTemplate;
//生产者
@Override
public String consumer() {
String msg1 = "生产者1=============ccccccccccccccc";
System.out.println(msg1);
rabbitmqTemplate.convertAndSend("a",msg1);
rabbitmqTemplate.convertAndSend("b",msg1+"加1");
rabbitmqTemplate.convertAndSend("c",msg1+"加2");
rabbitmqTemplate.convertAndSend("d",msg1+"加3");
return null;
}
//消费
@RabbitListener(queues = "a")
public String producer(String mag) {
System.out.println("消费成功----------"+mag);
return null;
}
//消费
@RabbitListener(queues = "b")
public String producer1(String mag) {
System.out.println("消费成功----------"+mag);
return null;
}
//消费
@RabbitListener(queues = "c")
public String producer2(String mag) {
System.out.println("消费成功----------"+mag);
return null;
}
//消费
@RabbitListener(queues = "d")
public String producer3(String mag) {
System.out.println("消费成功----------"+mag);
return null;
}