赞
踩
- logging:
- pattern:
- dateformat: MM-dd HH:mm:ss:SSS
-
- spring:
- rabbitmq:
- virtual-host: /hamll
- port: 5672
- host: 192.168.92.136
- username: hmall
- password: 123
- listener:
- simple:
- prefetch: 1
- connection-timeout: 1s
- template:
- retry:
- enabled: true
- initial-interval: 1000ms
- multiplier: 1
- max-attempts: 3
引入日志依赖
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-logging</artifactId>
- </dependency>
发送100万条消息给队列,需要先在application.yml中取消生产者确认
- publisher-confirm-type: none
- publisher-returns: false
没有持久化的测试用例,会出行阻塞的状态:
改为持久化后的测试用例:
使用auto自动模式
注意:创建的simple.queue需要Add Dead letter exchange,其他都跟之前创建的操作差不多
监听
- @RabbitListener(queues = "dlx.queue")
- public void listenDlxQueue(String msg){
- log.info("dlx.queue消费者收到消息:"+msg);
- }
测试用例
- @Test
- void testSendTTLMessage(){
-
- rabbitTemplate.convertAndSend("simple.direct", "hi", "hello", new MessagePostProcessor() {
- @Override
- public Message postProcessMessage(Message message) throws AmqpException {
- message.getMessageProperties().setExpiration("10000");
- return message;
- }
- });
- log.info("消息发送成功!");
- }
(3)取消订单
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。