spring boot 配置Rabbit
单独安装Rabbit服务并设置启动,可以通过浏览器访问,一般访问地址是http://localhost:15672/ ,用户名密码看配置文件的用户名密码
1 实例化配置类注解
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.amqp.core.Queue;;
@Configuration
public class RabbitConfig {
@Bean
public Queue OrdersQueue() {
return new Queue("队列名");
}
}
2 service 类注册监控队列,注意传递的参数类型,允许字符串,实体类等。注意异步操作延迟及回调
@Component
@RabbitListener(queues = "队列名")
public class RabbitmqOrder {
@RabbitHandler
@RabbitListener(queues = "队列名")
public void process(OrderModel od,Channel channel) throws IOException, InterruptedException {
//具体业务
//注意异步操作延迟及回调
Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
String message = new String(body, "UTF-8");
System.out.println(message);
channel.basicAck(envelope.getDeliveryTag(), true);
}
};
channel.basicConsume("sendOrder", true, consumer);
Thread.sleep(1000);
}
3 属性配置
#spring.rabbitmq.host=localhost
#spring.rabbitmq.port: 5672
#spring.rabbitmq.username=guest
#spring.rabbitmq.password=guest
#spring.rabbitmq.publisher-confirms=true
#spring.rabbitmq.virtual-host=/
#spring.rabbitmq.listener.direct.default-requeue-rejected = true
#spring.rabbitmq.listener.simple.retry.max-attempts= 3
#spring.rabbitmq.listener.simple.retry.enabled= true
#spring.rabbitmq.listener.simple.retry.initial-interval = 2000
4调用方式
@Autowired
private AmqpTemplate rabbitTemplate;
rabbitTemplate.convertAndSend("队列名", “参数”);
spring boot 配置Rabbit的更多相关文章
- Spring boot集成Rabbit MQ使用初体验
Spring boot集成Rabbit MQ使用初体验 1.rabbit mq基本特性 首先介绍一下rabbitMQ的几个特性 Asynchronous Messaging Supports mult ...
- Spring Boot -- 配置切换指南
一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一 ...
- Spring Boot 配置优先级顺序
一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一 ...
- spring boot 配置注入
spring boot配置注入有变量方式和类方式(参见:<spring boot 自定义配置属性的各种方式>),变量中又要注意静态变量的注入(参见:spring boot 给静态变量注入值 ...
- Spring boot配置多个Redis数据源操作实例
原文:https://www.jianshu.com/p/c79b65b253fa Spring boot配置多个Redis数据源操作实例 在SpringBoot是项目中整合了两个Redis的操作实例 ...
- spring boot配置springMVC拦截器
spring boot通过配置springMVC拦截器 配置拦截器比较简单, spring boot配置拦截器, 重写preHandle方法. 1.配置拦截器: 2重写方法 这样就实现了拦截器. 其中 ...
- spring boot配置mybatis和事务管理
spring boot配置mybatis和事务管理 一.spring boot与mybatis的配置 1.首先,spring boot 配置mybatis需要的全部依赖如下: <!-- Spri ...
- [转] Spring Boot配置多个DataSource
[From] https://www.liaoxuefeng.com/article/001484212576147b1f07dc0ab9147a1a97662a0bd270c20000 Sprin ...
- Spring boot 配置异步处理执行器
示例如下: 1. 新建Maven 项目 async-executor 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0 ...
随机推荐
- [SCOI2016]背单词——trie树相关
题目描述 Lweb 面对如山的英语单词,陷入了深深的沉思,”我怎么样才能快点学完,然后去玩三国杀呢?“.这时候睿智的凤老师从远处飘来,他送给了 Lweb 一本计划册和一大缸泡椒,他的计划册是长这样的: ...
- BZOJ4516: [Sdoi2016]生成魔咒(后缀数组 set RMQ)
题意 题目链接 Sol 毒瘤SDOI 终于有一道我会做的题啦qwq 首先,本质不同的子串的个数 $ = \frac{n(n + 1)}{2} - \sum height[i]$ 把原串翻转过来,每次就 ...
- JavaScript中的__proto__
实例中的__proto__ 箭头函数的__proto__ 需要注意的是箭头函数的__proto__并没有指向Function构造函数的的原型对象 MDN上的资料显示,箭头函数不绑定Arguments ...
- 使用PermissionsDispatcher轻松解决Android权限问题
之前也处理过6.0后的权限问题,直接处理很是麻烦.这次在github上搜到了关于权限星数最多的PermissionsDispatcher这个库,几个注释完美解决权限问题. 第一步 添加各种注释 1.@ ...
- centos django+Nginx+uwsgi部署
第五天 部署python3+uwsgi+nginx的博客系统 ================================ mysql基本命令 mysql mysql -p mysqladmin ...
- HTML 的 style 属性
style 属性用于改变 HTML 元素的样式. This text is in Verdana and red This text is in Times and blue This text is ...
- JDBC连接数据库反射实现O/R映射
测试preparedStatement public void testPreparedStatement(){ Connection connection=null; PreparedStateme ...
- winfrom 实现窗体圆角
在窗体中加入一下代码 #region 窗体圆角的实现 private void ComFrmBase_Resize(object sender, EventArgs e) { if (this.Win ...
- 五、python小功能记录——打包程序
使用pyinstaller打包Python程序 安装工具 :pip3 install pyinstaller 在Python程序文件夹上(不点进去)按住shift并且右键,在弹出的选项中点击" ...
- [翻译] SVProgressHUD
SVProgressHUD https://github.com/TransitApp/SVProgressHUD SVProgressHUD is a clean and easy-to-use H ...