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

如何建立自己网站教程百度主页面

如何建立自己网站教程,百度主页面,阿里云建站后台,淮南网上办事大厅官网文章目录 一、RabbitMq 下载安装二、开发步骤:1.MAVEN 配置2. RabbitMqConfig 配置3. RabbitMqUtil 工具类4. DailyDelaySendConsumer 消费者监听5. 测试延迟发送 一、RabbitMq 下载安装 官网:https://www.rabbitmq.com/docs 二、开发步骤:…

文章目录

  • 一、RabbitMq 下载安装
  • 二、开发步骤:
    • 1.MAVEN 配置
    • 2. RabbitMqConfig 配置
    • 3. RabbitMqUtil 工具类
    • 4. DailyDelaySendConsumer 消费者监听
    • 5. 测试延迟发送

一、RabbitMq 下载安装

官网:https://www.rabbitmq.com/docs

二、开发步骤:

1.MAVEN 配置

   		<!--RabbitMQ--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId><version>2.7.7</version></dependency>

2. RabbitMqConfig 配置

package com.lq.common.config;import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import java.util.HashMap;
import java.util.Map;@Configuration
public class RabbitMqConfig {/**延迟交换机名称*/public static final String  DELAY_EXCHANGE="DelayExchange";/**延迟队列名称*/public static final String  DELAY_QUEUE="DelayQueue";public static final String ROUTING_KEY="delay";@Beanpublic CustomExchange customExchange(){Map<String, Object> map = new HashMap<>();//设置交换机支持延迟消息推送map.put("x-delayed-type","direct");return new CustomExchange(DELAY_EXCHANGE,"x-delayed-message",true,false,map);}@Beanpublic Queue delayQueue(){return new Queue(DELAY_QUEUE,true);}@Beanpublic Binding DelayBinding(){return BindingBuilder.bind(delayQueue()).to(customExchange()).with(ROUTING_KEY).noargs();}}

3. RabbitMqUtil 工具类

package com.lq.common.util;import com.lq.common.config.RabbitMqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;@Service
@Slf4j
public class RabbitMqUtil {@Autowiredprivate RabbitTemplate rabbitTemplate;private DateTimeFormatter formatterDateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");@PostConstructpublic void init(){/*** 消息发送到交换机成功回调函数*/rabbitTemplate.setConfirmCallback(new RabbitTemplate.ConfirmCallback(){@Overridepublic void confirm(CorrelationData correlationData, boolean ack, String cause) {if (ack){log.info("消息投递到交换机成功");}else {log.error("消息投递到交换机失败,原因->{}",cause);}}});/**交换机投递到队列失败回调函数**/rabbitTemplate.setReturnsCallback(new RabbitTemplate.ReturnsCallback() {@Overridepublic void returnedMessage(ReturnedMessage returned) {log.error("投递到队列失败,错误原因->{}",returned);}});}/*** @Description 发送延迟消息* @param content 延迟内容* @param delayTime 延迟时间 ,单位ms;  例如 5000 代表 5 秒* @Author hqd* @Date 2024-10-21*/public Boolean sendDelayMessage(String content,Integer delayTime){log.info("消息发送时间->{}",LocalDateTime.now().format(formatterDateTime));rabbitTemplate.convertAndSend(RabbitMqConfig.DELAY_EXCHANGE, RabbitMqConfig.ROUTING_KEY, content, new MessagePostProcessor() {@Overridepublic Message postProcessMessage(Message message) throws AmqpException {log.info("延迟时间->{}",delayTime);//这个底层就是setHeader("x-delay",i);是一样的 设置延时时间message.getMessageProperties().setDelay(delayTime);//单位毫秒return message;}});return true;}}

4. DailyDelaySendConsumer 消费者监听

package com.lq.daily.mq.consumer;import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.lq.common.config.RabbitMqConfig;
import com.lq.daily.dto.DailyDelaySendDTO;
import com.lq.daily.service.ILqDailyService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;/*** @Description 日报延迟发送消费者* @Author hqd* @Date 2024-10-21 16:04*/
@Slf4j
@Component
public class DailyDelaySendConsumer {@Autowiredprivate ILqDailyService lqDailyService;private DateTimeFormatter formatterDateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");@RabbitListener(queues = RabbitMqConfig.DELAY_QUEUE)public void dailyDelaySendListener(String content, Channel channel, Message message) throws IOException, InterruptedException{log.info("消息接收时间->{}", LocalDateTime.now().format(formatterDateTime));log.info("接收消息内容是->{}",content);log.info("{}",message.getMessageProperties().getDeliveryTag());channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);//处理日报发送业务逻辑if (StrUtil.isNotBlank(content)&& content.startsWith("{")){DailyDelaySendDTO dto = JSONObject.parseObject(content, DailyDelaySendDTO.class);if (ObjectUtil.isNotEmpty(dto)){lqDailyService.updateDailyDelaySend(dto.getDailyCode(), LocalDateTime.parse(dto.getDelaySendTime(),DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));}}}
}

5. 测试延迟发送

   @PassToken@GetMapping("/testDelayMq")@ApiOperation("测试Mq 延迟消息发送")public void testDelayMq(){DailyDelaySendDTO dto = new DailyDelaySendDTO();dto.setDailyCode("DC2024101015135400001");dto.setDelaySendTime("2024-10-22 10:58");LocalDateTime sendTime = LocalDateTime.parse(dto.getDelaySendTime()+":00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));long between = ChronoUnit.MILLIS.between(LocalDateTime.now(), sendTime);rabbitMqUtil.sendDelayMessage(JSON.toJSONString(dto),new Long(between).intValue());}

在这里插入图片描述

http://www.dt0577.cn/news/22711.html

相关文章:

  • 免费wap自助建站火星建站优化网站找哪家
  • 福州网站建设方案书一句话让客户主动找你
  • 盐城专业做网站的公司做网络推广的公司
  • 福田小货车优化网站标题和描述的方法
  • 宿州网站建设网站怎么做推广和宣传
  • 巴彦淖尔 网站建设seo创业
  • 网站功能建设免费网站制作
  • 网站界面切片做程序本周国内新闻
  • 网站备案经验微信小程序开发工具
  • 淮南网站优化策划公司
  • 帝国cms做电影网站上海关键词排名优化怎样
  • 制作网站软件用什么语言seo快速排名软件网址
  • 南昌旅游网站建设方案河南品牌网络推广外包
  • 凡科网建站怎么样2021百度模拟点击工具
  • 阿里巴巴上面可以做网站西安seo诊断
  • 哪个网站做ppt赚钱营销软文范例500
  • 做包装盒子的厂家哪个网站公司企业网站开发
  • 做网站要学什么软件好百度推广非企代理
  • 巩义网站公司公司网络推广方法
  • 做外贸上阿里巴巴什么网站厦门seo总部电话
  • 山西营销网站建设那个公司好网站排名查询alexa
  • 高端大气的网络公司名称seo排名优化代理
  • 有了域名搭建网站详细步骤手机如何制作网页链接
  • 白云商城型网站建设网络公关公司收费
  • 自动化东莞网站建设免费com网站域名注册
  • 做网站一般费用多少百度网站下载安装
  • 用台电脑做网站seo小白入门
  • 义乌开锁做网站哪个好关键词在线下载
  • 如何做百度推广的网站seo 优化技术难度大吗
  • 网站 设计 案例 简单广告开户