当前位置: 首页 > news >正文

网站怎么做能赚钱吗seo代理

网站怎么做能赚钱吗,seo代理,模板网站怎么样,外国黄冈网站推广软件MQ的一些常见问题 后面内容基于springboot 2.3.9.RELEASE 消息可靠性 生产者确认机制 在publisher微服务中application.yml中添加 spring:rabbitmq:publisher-confirm-type: correlatedpublisher-returns: truetemplate:mandatory: true每个RabbitTemplate只能配置一个Return…

MQ的一些常见问题


在这里插入图片描述
后面内容基于springboot 2.3.9.RELEASE

消息可靠性


在这里插入图片描述

生产者确认机制

在这里插入图片描述

  • 在publisher微服务中application.yml中添加
spring:rabbitmq:publisher-confirm-type: correlatedpublisher-returns: truetemplate:mandatory: true

在这里插入图片描述

  • 每个RabbitTemplate只能配置一个ReturnCallback, 因此需要在项目启动过程中配置
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;@Slf4j
@Configuration
public class CommonConfig implements ApplicationContextAware {@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {RabbitTemplate rabbitTemplate = applicationContext.getBean(RabbitTemplate.class);rabbitTemplate.setReturnCallback((message, replyCode, replyText, exchange, routingKey) -> {log.error("消息发送到队列失败, 响应码:{}, 失败原因: {}, 交换机: {}, 路由key: {}, 消息: {}",replyCode, replyText, exchange, routingKey, message);});}
}
  • 发送消息, 指定消息ID,消息ConfirmCallBack
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.util.UUID;@Slf4j
@SpringBootTest
public class PublishTest {@Autowiredprivate RabbitTemplate rabbitTemplate;@Testvoid name() throws InterruptedException {CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());correlationData.getFuture().addCallback(result -> {if(result.isAck()){// ACKlog.debug("消息成功投递到交换机! 消息ID: {}", correlationData.getId());}else {// NACKlog.error("消息投递到交换机失败! 消息ID: {}", correlationData.getId());}}, ex -> {log.error("消息发送失败!", ex);});rabbitTemplate.convertAndSend("high.topic", "high.#", "hello amqp", correlationData);}
}

在这里插入图片描述

消息持久化

声明队列和交换机时指定durabletrue,为持久化

spring amqp中交换机、队列、消息默认都是持久的

消费者消息确认

在这里插入图片描述
消费者业务添加配置

spring:rabbitmq:listener:simple:acknowledge-mode: auto 

失败重试机制

在这里插入图片描述

spring:rabbitmq:listener:simple:acknowledge-mode: autoprefetch: 1retry:enabled: true     # 开启消费者失败重试initial-interval: 1000  # 初始的失败等待时长1秒multiplier: 1  # 下次失败的等待时长倍数max-attempts: 3   # 最大重试次数stateless: true  # true无状态, false有状态, 如果业务中包含事务, 这里改为false

配置说明:

初始等待时长1秒,倍数为2, 则等待时长为 1秒 2秒 4秒 8秒 …

消费者失败消息处理策略

在这里插入图片描述

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class ErrorMessageConfig {@Beanpublic DirectExchange errorMessageExchange(){return new DirectExchange("error.direct");}@Beanpublic Queue errorQueue(){return new Queue("error.queue");}@Beanpublic Binding errorMessageBinding(){return BindingBuilder.bind(errorQueue()).to(errorMessageExchange()).with("error");}@Beanpublic MessageRecoverer republishMessageRecoverer(RabbitTemplate rabbitTemplate){return new RepublishMessageRecoverer(rabbitTemplate, "error.direct", "error");}
}

死信交换机


在这里插入图片描述
这个是由队列投递

TTL

在这里插入图片描述

  • 声明死信交换机
	@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "dl.queue", durable = "true"),exchange = @Exchange(name = "dl.direct"),key = "dl"))public void listenDlQueue(String msg){log.info("消费者接收到了dl.queue的延迟消息: {}", msg);}
  • 声明TTL交换机和队列
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class TTLMessageConfig {@Beanpublic DirectExchange ttlDirectExchange(){return new DirectExchange("ttl.direct");}@Beanpublic Queue ttlQueue(){return QueueBuilder.durable("ttl.queue").ttl(10000)   // 指定时间10秒.deadLetterExchange("dl.direct").deadLetterRoutingKey("dl").build();}@Beanpublic Binding ttlBinding(){return BindingBuilder.bind(ttlQueue()).to(ttlDirectExchange()).with("ttl");}
}
  • 发送消息
	@Testvoid name() {MessageBuilder.withBody("hello ttl".getBytes(StandardCharsets.UTF_8)).setDeliveryMode(MessageDeliveryMode.PERSISTENT).setExpiration("5000").build();rabbitTemplate.convertAndSend("ttl.direct", "ttl", "ttl message");}

也可以指定消息的过期时间, 两者都指定时, 以短的为准

在这里插入图片描述

http://www.mnyf.cn/news/15212.html

相关文章:

  • 北京做网站手机百度电脑版入口
  • 衡水网站建设在哪里奶茶店推广软文500字
  • 邦拓网站建设大连网络推广
  • 网站商务方案百度收录查询工具官网
  • 建筑网人才正版seo搜索引擎
  • 建筑公司网站页面图片线上销售渠道有哪几种
  • 网站独立模块是什么意思页面优化的方法
  • python 做网站开发优化大师 win10下载
  • 网站备案照片要求免费加客源
  • 网站设计公司排名知乎seo sem是指什么意思
  • 企业信用信息查询公示系统网址seo资源咨询
  • php怎样做网站十大最靠谱it培训机构
  • 网站建设要点拼多多代运营一般多少钱
  • html5源码网站排名优化公司哪家好
  • 搭建门户网站百度seo如何快速排名
  • 怎么做自己的网站教程都有什么推广平台
  • 网页编辑教程谷歌seo 优化
  • 上海徐汇网站建设公司crm网站
  • 网站空间是不是服务器客源软件哪个最好
  • 网站建设价格明细表天津百度seo排名优化
  • 大学网站建设排名许昌网络推广外包
  • 游戏网站建设的策划做网页的网站
  • wordpress源代码分析域名seo查询
  • 嵊州哪里可以做网站百度关键词排名点击
  • 哪些是 joomla做的网站全网投放广告的渠道有哪些
  • 邹城网站开发百度seo优化推广公司
  • 权威的建筑工程网站蜘蛛seo超级外链工具
  • 网站维护有多长时间360搜索引擎的特点
  • 东莞电商建站西安百度seo排名
  • 网站建设搜索代码邯郸seo