SpringBoot整合阿里云RocketMQ对接,商业版

1.需要阿里云开通商业版RocketMQ

普通消息新建普通主题,普通组,延迟消息新建延迟消息主题,延迟消息组

2.结构目录

在这里插入图片描述

3.引入依赖

<!--阿里云RocketMq整合--><dependency><groupId>com.aliyun.openservices</groupId><artifactId>ons-client</artifactId><version>1.8.8.5.Final</version></dependency>

4.延迟消息配置

import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.aliyun.openservices.ons.api.batch.BatchMessageListener;
import com.aliyun.openservices.ons.api.bean.BatchConsumerBean;
import com.aliyun.openservices.ons.api.bean.Subscription;
import com.atkj.devicewx.config.MqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import java.util.HashMap;
import java.util.Map;
import java.util.Properties;/*** 延迟消息配置类*/
@Configuration
public class BatchConsumerClient {@Autowiredprivate MqConfig mqConfig;@Autowiredprivate BatchDemoMessageListener messageListener;@Bean(initMethod = "start", destroyMethod = "shutdown")public BatchConsumerBean buildBatchConsumer() {BatchConsumerBean batchConsumerBean = new BatchConsumerBean();//配置文件Properties properties = mqConfig.getMqPropertie();properties.setProperty(PropertyKeyConst.GROUP_ID, mqConfig.getDelayGroupId());//将消费者线程数固定为20个 20为默认值properties.setProperty(PropertyKeyConst.ConsumeThreadNums, "20");batchConsumerBean.setProperties(properties);//订阅关系Map<Subscription, BatchMessageListener> subscriptionTable = new HashMap<Subscription, BatchMessageListener>();Subscription subscription = new Subscription();subscription.setTopic(mqConfig.getDelayTopic());subscription.setExpression(mqConfig.getDelayTag());subscriptionTable.put(subscription, messageListener);//订阅多个topic如上面设置batchConsumerBean.setSubscriptionTable(subscriptionTable);return batchConsumerBean;}}
import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.batch.BatchMessageListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;/*** 延迟消息消费者*/
@Slf4j
@Component
public class BatchDemoMessageListener implements BatchMessageListener {@Overridepublic Action consume(final List<Message> messages, final ConsumeContext context) {log.info("消费者收到消息大小:"+messages.size());for (Message message : messages) {byte[] body = message.getBody();String s = new String(body);Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String formatTime = sdf.format(date);System.out.println("接收到消息时间:"+formatTime);log.info("接收到消息内容:"+s);}try {//do something..return Action.CommitMessage;} catch (Exception e) {//消费失败return Action.ReconsumeLater;}}
}

5.MQ配置类


import com.aliyun.openservices.ons.api.PropertyKeyConst;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;import java.util.Properties;@Data
@Configuration
@ConfigurationProperties(prefix = "rocketmq")
public class MqConfig {private String accessKey;private String secretKey;private String nameSrvAddr;private String topic;private String groupId;private String tag;private String orderTopic;private String orderGroupId;private String orderTag;private String delayTopic;private String delayGroupId;private String delayTag;public Properties getMqPropertie() {Properties properties = new Properties();properties.setProperty(PropertyKeyConst.AccessKey, this.accessKey);properties.setProperty(PropertyKeyConst.SecretKey, this.secretKey);properties.setProperty(PropertyKeyConst.NAMESRV_ADDR, this.nameSrvAddr);return properties;}}

6.YML配置

## 阿里云RocketMQ配置
rocketmq:accessKey: laskdfjlaksdjflaksjdflaksdjflakdjfsecretKey: asdfasdlfkasjdlfkasjdlfkajsdlkfjkalksdfjnameSrvAddr: rmq..rmq.acs.com:8080topic: topic_lsdjf_testgroupId: Glskdfjalsdkfjalksdjflaksdfj_pushtag: "*"orderTopic: XXXorderGroupId: XXXorderTag: "*"delayTopic: topic_alskdjfalksdjflksdjfkla_delaydelayGroupId: GIlaskdjflkasdjflkajsdkf_delaydelayTag: "*"

7.普通消息配置

import com.aliyun.openservices.ons.api.MessageListener;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.aliyun.openservices.ons.api.bean.ConsumerBean;
import com.aliyun.openservices.ons.api.bean.Subscription;
import com.atkj.devicewx.config.MqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import java.util.HashMap;
import java.util.Map;
import java.util.Properties;/*** 普通消息配置类*/
@Configuration
public class ConsumerClient {@Autowiredprivate MqConfig mqConfig;@Autowiredprivate DemoMessageListener messageListener;@Bean(initMethod = "start", destroyMethod = "shutdown")public ConsumerBean buildConsumer() {ConsumerBean consumerBean = new ConsumerBean();//配置文件Properties properties = mqConfig.getMqPropertie();properties.setProperty(PropertyKeyConst.GROUP_ID, mqConfig.getGroupId());//将消费者线程数固定为20个 20为默认值properties.setProperty(PropertyKeyConst.ConsumeThreadNums, "20");consumerBean.setProperties(properties);//订阅关系Map<Subscription, MessageListener> subscriptionTable = new HashMap<Subscription, MessageListener>();Subscription subscription = new Subscription();subscription.setTopic(mqConfig.getTopic());subscription.setExpression(mqConfig.getTag());subscriptionTable.put(subscription, messageListener);//订阅多个topic如上面设置consumerBean.setSubscriptionTable(subscriptionTable);return consumerBean;}}

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;/*** 普通主题消费者*/
@Component
@Slf4j
public class DemoMessageListener implements MessageListener {@Overridepublic Action consume(Message message, ConsumeContext context) {log.info("接收到消息: " + message);try {byte[] body = message.getBody();String s = new String(body);log.info("接收到消息字符串:"+s);//Action.CommitMessag 进行消息的确认return Action.CommitMessage;} catch (Exception e) {//消费失败return Action.ReconsumeLater;}}
}
import com.aliyun.openservices.ons.api.bean.ProducerBean;
import com.atkj.devicewx.config.MqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** 普通消息生产者配置类*/
@Configuration
public class ProducerClient {@Autowiredprivate MqConfig mqConfig;@Bean(initMethod = "start", destroyMethod = "shutdown")public ProducerBean buildProducer() {ProducerBean producer = new ProducerBean();producer.setProperties(mqConfig.getMqPropertie());return producer;}}
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.SendResult;
import com.aliyun.openservices.ons.api.bean.ProducerBean;
import com.aliyun.openservices.ons.api.exception.ONSClientException;
import com.atkj.devicewx.config.MqConfig;
import org.springframework.stereotype.Component;/*** 普通消息生产者***/
@Component
public class RocketMessageProducer {private static ProducerBean producer;private static MqConfig mqConfig;public RocketMessageProducer(ProducerBean producer, MqConfig mqConfig) {this.producer = producer;this.mqConfig = mqConfig;}/*** @Description: <h2>生产 普通 消息</h2>* @author: LiRen*/public  static void producerMsg(String tag, String key, String body) {Message msg = new Message(mqConfig.getTopic(), tag, key, body.getBytes());long time = System.currentTimeMillis();try {SendResult sendResult = producer.send(msg);assert sendResult != null;System.out.println(time+ " Send mq message success.Topic is:" + msg.getTopic()+ " Tag is:" + msg.getTag() + " Key is:" + msg.getKey()+ " msgId is:" + sendResult.getMessageId());} catch (ONSClientException e) {e.printStackTrace();System.out.println(time + " Send mq message failed. Topic is:" + msg.getTopic());}}}
import com.aliyun.openservices.ons.api.*;
import com.atkj.devicewx.config.MqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;import java.util.Properties;/*** 普通消息消费者*/
//效果和 DemoMessageListener 一致
//@Component
public class RocketMQConsumer {@Autowiredprivate MqConfig rocketMQConfig;/*** 1、普通订阅** @param*/@Bean //不加@Bean Spring启动时没有注册该方法,就无法被调用public void normalSubscribe( ) {Properties properties = rocketMQConfig.getMqPropertie();properties.put(PropertyKeyConst.GROUP_ID,rocketMQConfig.getGroupId());Consumer consumer = ONSFactory.createConsumer(properties);consumer.subscribe(rocketMQConfig.getTopic(), rocketMQConfig.getTag(), new MessageListener() {@Overridepublic Action consume(Message message, ConsumeContext context) {System.out.println("Receive: " + new String(message.getBody()));//把消息转化为java对象//JSONObject jsonObject=JSONObject.parseObject(jsonString);//Book book= jsonObject.toJavaObject(Book.class);return Action.CommitMessage;}});consumer.start();}
}

7.order没用到


import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.aliyun.openservices.ons.api.bean.OrderConsumerBean;
import com.aliyun.openservices.ons.api.bean.Subscription;
import com.aliyun.openservices.ons.api.order.MessageOrderListener;
import com.atkj.devicewx.config.MqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;import java.util.HashMap;
import java.util.Map;
import java.util.Properties;//项目中加上 @Configuration 注解,这样服务启动时consumer也启动了
public class OrderConsumerClient {@Autowiredprivate MqConfig mqConfig;@Autowiredprivate OrderDemoMessageListener messageListener;@Bean(initMethod = "start", destroyMethod = "shutdown")public OrderConsumerBean buildOrderConsumer() {OrderConsumerBean orderConsumerBean = new OrderConsumerBean();//配置文件Properties properties = mqConfig.getMqPropertie();properties.setProperty(PropertyKeyConst.GROUP_ID, mqConfig.getOrderGroupId());orderConsumerBean.setProperties(properties);//订阅关系Map<Subscription, MessageOrderListener> subscriptionTable = new HashMap<Subscription, MessageOrderListener>();Subscription subscription = new Subscription();subscription.setTopic(mqConfig.getOrderTopic());subscription.setExpression(mqConfig.getOrderTag());subscriptionTable.put(subscription, messageListener);//订阅多个topic如上面设置orderConsumerBean.setSubscriptionTable(subscriptionTable);return orderConsumerBean;}}

import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.order.ConsumeOrderContext;
import com.aliyun.openservices.ons.api.order.MessageOrderListener;
import com.aliyun.openservices.ons.api.order.OrderAction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;@Slf4j
@Component
public class OrderDemoMessageListener implements MessageOrderListener {@Overridepublic OrderAction consume(final Message message, final ConsumeOrderContext context) {log.info("接收到消息: " + message);try {//do something..return OrderAction.Success;} catch (Exception e) {//消费失败,挂起当前队列return OrderAction.Suspend;}}
}
import com.aliyun.openservices.ons.api.bean.OrderProducerBean;
import com.atkj.devicewx.config.MqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** 生产者配置类*/
@Configuration
public class OrderProducerClient {@Autowiredprivate MqConfig mqConfig;@Bean(initMethod = "start", destroyMethod = "shutdown")public OrderProducerBean buildOrderProducer() {OrderProducerBean orderProducerBean = new OrderProducerBean();orderProducerBean.setProperties(mqConfig.getMqPropertie());return orderProducerBean;}}

8.事务消息没用到

import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.transaction.LocalTransactionChecker;
import com.aliyun.openservices.ons.api.transaction.TransactionStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;/*** 事务消息*/
@Slf4j
@Component
public class DemoLocalTransactionChecker implements LocalTransactionChecker {@Overridepublic TransactionStatus check(Message msg) {log.info("开始回查本地事务状态");return TransactionStatus.CommitTransaction; //根据本地事务状态检查结果返回不同的TransactionStatus}
}
import com.aliyun.openservices.ons.api.bean.TransactionProducerBean;
import com.atkj.devicewx.config.MqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** 事务消息配置类*/
@Configuration
public class TransactionProducerClient {@Autowiredprivate MqConfig mqConfig;@Autowiredprivate DemoLocalTransactionChecker localTransactionChecker;@Bean(initMethod = "start", destroyMethod = "shutdown")public TransactionProducerBean buildTransactionProducer() {TransactionProducerBean producer = new TransactionProducerBean();producer.setProperties(mqConfig.getMqPropertie());producer.setLocalTransactionChecker(localTransactionChecker);return producer;}}

9.测试类


import com.aliyun.openservices.ons.api.*;
import com.aliyun.openservices.ons.api.exception.ONSClientException;
import com.aliyun.openservices.shade.com.alibaba.fastjson.JSON;
import com.atkj.devicewx.config.MqConfig;
import com.atkj.devicewx.normal.RocketMessageProducer;
import com.atkj.devicewx.service.TestService;
import com.atkj.devicewx.vo.MetabolicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;/*** @Author: albc* @Date: 2024/07/12/10:22* @Description: good good study,day day up*/
@RequestMapping("/api/v1/mq/test")
@RestController
public class TestController {@Autowiredprivate TestService testService;@Autowiredprivate MqConfig mqConfig;@RequestMapping("/one")public String testOne(){Integer count = testService.testOne();return "发送成功:"+count;}/*** 普通消息测试* @return*/@RequestMapping("/useRocketMQ")public String useRocketMQ() {MetabolicVo metabolicVo = new MetabolicVo();metabolicVo.setAge(123);metabolicVo.setName("测试名字");metabolicVo.setWeight(75);RocketMessageProducer.producerMsg("123","666", JSON.toJSONString(metabolicVo));return "请求成功!";}/*** 发送延迟消息测试* @return*/@RequestMapping("/delayMqMsg")public String delayMqMsg() {Properties producerProperties = new Properties();producerProperties.setProperty(PropertyKeyConst.AccessKey, mqConfig.getAccessKey());producerProperties.setProperty(PropertyKeyConst.SecretKey, mqConfig.getSecretKey());producerProperties.setProperty(PropertyKeyConst.NAMESRV_ADDR, mqConfig.getNameSrvAddr());//注意!!!如果访问阿里云RocketMQ 5.0系列实例,不要设置PropertyKeyConst.INSTANCE_ID,否则会导致收发失败Producer producer = ONSFactory.createProducer(producerProperties);producer.start();System.out.println("生产者启动..........");Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String formatTime = sdf.format(date);String meg = formatTime + "发送延迟消息测试";Message message = new Message(mqConfig.getDelayTopic(), mqConfig.getDelayTag(), meg.getBytes());// 延时时间单位为毫秒(ms),指定一个时刻,在这个时刻之后才能被消费,这个例子表示 3秒 后才能被消费long delayTime = 3000;message.setStartDeliverTime(System.currentTimeMillis() + delayTime);try {SendResult sendResult = producer.send(message);assert sendResult != null;System.out.println(new Date() + "发送mq消息主题:" + mqConfig.getDelayTopic() + "消息id: " + sendResult.getMessageId());} catch (ONSClientException e) {// 消息发送失败,需要进行重试处理,可重新发送这条消息或持久化这条数据进行补偿处理System.out.println(new Date() + "重试发送mq消息主题:" + mqConfig.getDelayTopic());e.printStackTrace();}return "请求成功!";}}

优化部分

每次发送消息都要创建生产者,效率低下
使用单例优化

import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;import java.util.Properties;/*** 生产者单例* @Author: albc* @Date: 2024/07/15/15:49* @Description: good good study,day day up*/
@Component
@Slf4j
public class ProducerSingleton {private volatile static Producer producer;private static String accessKey;private static String secretKey;private static String nameSrvAddr;private ProducerSingleton() {}@Value("${rocketmq.accessKey}")private void setAccessKey(String accessKey) {ProducerSingleton.accessKey = accessKey;}@Value("${rocketmq.secretKey}")private void setSecretKey(String secretKey) {ProducerSingleton.secretKey = secretKey;}@Value("${rocketmq.nameSrvAddr}")private void setNameSrvAddr(String nameSrvAddr) {ProducerSingleton.nameSrvAddr = nameSrvAddr;}/*** 创建生产者* @return*/public static Producer getProducer(){if (producer == null){synchronized(ProducerSingleton.class){if (producer == null){Properties producerProperties = new Properties();producerProperties.setProperty(PropertyKeyConst.AccessKey, accessKey);producerProperties.setProperty(PropertyKeyConst.SecretKey, secretKey);producerProperties.setProperty(PropertyKeyConst.NAMESRV_ADDR, nameSrvAddr);//注意!!!如果访问阿里云RocketMQ 5.0系列实例,不要设置PropertyKeyConst.INSTANCE_ID,否则会导致收发失败producer = ONSFactory.createProducer(producerProperties);producer.start();log.info("生产者启动........");}}}return producer;}}

import com.aliyun.openservices.ons.api.*;
import com.aliyun.openservices.ons.api.exception.ONSClientException;
import com.atkj.devicewx.level.config.MqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;/*** 延迟消息生产者** @Author: albc* @Date: 2024/07/15/14:11* @Description: good good study,day day up*/
@Slf4j
@Component
public class BatchMessageProducer {@Autowiredprivate MqConfig mqConfig;/*** 发送消息* @param msg 发送消息内容* @param delayTime 延迟时间,毫秒*/public void sendDelayMeg(String msg,Long delayTime) {Producer producer = ProducerSingleton.getProducer();Message message = new Message(mqConfig.getDelayTopic(), mqConfig.getDelayTag(), msg.getBytes());message.setStartDeliverTime(System.currentTimeMillis() + delayTime);try {SendResult sendResult = producer.send(message);assert sendResult != null;log.info( "发送mq消息主题:" + mqConfig.getDelayTopic() + "消息id: " + sendResult.getMessageId());} catch (ONSClientException e) {// 消息发送失败,需要进行重试处理,可重新发送这条消息或持久化这条数据进行补偿处理log.error("重试发送mq消息主题:" + mqConfig.getDelayTopic());e.printStackTrace();}finally {message = null;}}}

其他不变

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/47508.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Qt类 | QLabel类详解

文章目录 一、QLabel类介绍二、Properties&#xff08;属性&#xff09;三、Public Functions&#xff08;公共函数&#xff09;1.构造函数2.alignment与setAlignment函数 -- 标签内容的对齐方式3.buddy与setBuddy函数 -- QLabel关联的伙伴控件4.hasScaledContents与setScaledC…

基于YOLOv8深度学习的水果智能检测系统【python源码+Pyqt5界面+数据集+训练代码】深度学习实战、目标检测、卷积神经网络

《博主简介》 小伙伴们好&#xff0c;我是阿旭。专注于人工智能、AIGC、python、计算机视觉相关分享研究。 ✌更多学习资源&#xff0c;可关注公-仲-hao:【阿旭算法与机器学习】&#xff0c;共同学习交流~ &#x1f44d;感谢小伙伴们点赞、关注&#xff01; 《------往期经典推…

C#字符串基本操作

1、代码 //1、创建字符串&#xff08;获取长度&#xff09;string str "Hello, World!";Console.WriteLine($"string:{str},length:{str.Length}");//2、字符串连接string str1 "Hello, ";string str2 "World!";Console.WriteLine…

在 Windows 11/10/8 上恢复误删除文件的最佳方法

如果您刚刚在计算机上重新安装了 Windows 操作系统&#xff0c;结果硬盘上的所有文件都消失了&#xff0c;有没有办法从 Windows 11/10 中恢复误删除的文件&#xff1f; 许多因素都可能导致 PC 上的文件被删除。除了重新安装操作系统外&#xff0c;其他常见原因还包括意外删除…

Vue.js 生命周期详解:从创建到销毁的全过程

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 非常期待和您一起在这个小…

【BUG】已解决:java.lang.reflect.InvocationTargetException

已解决&#xff1a;java.lang.reflect.InvocationTargetException 欢迎来到英杰社区https://bbs.csdn.net/topics/617804998 欢迎来到我的主页&#xff0c;我是博主英杰&#xff0c;211科班出身&#xff0c;就职于医疗科技公司&#xff0c;热衷分享知识&#xff0c;武汉城市开发…

STM32 IAP 需要关注的一些事

1、首先要知道STM32的程序是如何分布在FLASH中的。 2、升级的时候涉及到两个程序&#xff0c;一个是bootloader&#xff0c;一个是user程序&#xff0c;这两个程序的功能分别的什么作用的&#xff1f; 3、编译的固件是怎么分布的&#xff1f;通过那个配置文件去指导编译器去排布…

Spring Boot集成kudu快速入门Demo

1.什么是kudu 在Kudu出现前&#xff0c;由于传统存储系统的局限性&#xff0c;对于数据的快速输入和分析还没有一个完美的解决方案&#xff0c;要么以缓慢的数据输入为代价实现快速分析&#xff0c;要么以缓慢的分析为代价实现数据快速输入。随着快速输入和分析场景越来越多&a…

十五、【机器学习】【监督学习】- 神经网络回归

系列文章目录 第一章 【机器学习】初识机器学习 第二章 【机器学习】【监督学习】- 逻辑回归算法 (Logistic Regression) 第三章 【机器学习】【监督学习】- 支持向量机 (SVM) 第四章【机器学习】【监督学习】- K-近邻算法 (K-NN) 第五章【机器学习】【监督学习】- 决策树…

Django Q()函数

Q() 函数的作用 在Django中&#xff0c;Q()函数是一个非常有用的工具&#xff0c;主要用于构建复杂的查询。它允许你创建复杂的查询语句&#xff0c;包括AND、OR和NOT逻辑操作。这对于处理复杂的数据库查询特别有用&#xff0c;特别是在你需要组合多个条件或处理复杂的过滤逻辑…

HLS加密技术:保障流媒体内容安全的利器

随着网络视频内容的爆炸性增长&#xff0c;如何有效保护视频内容的版权和安全成为了一个亟待解决的问题。HLS&#xff08;HTTP Live Streaming&#xff09;加密技术作为一种先进的流媒体加密手段&#xff0c;凭借其高效性和安全性&#xff0c;在直播、点播等场景中得到了广泛应…

【C语言】联合体(union)

文章目录 1.联合体的含义2. 联合体的声明3. 联合体大小的计算4. 联合体的特点 1.联合体的含义 联合体也叫做共用体&#xff0c;是指联合体的所有成员共用同一块内存空间。这也就说明了&#xff0c;联合体的大小至少是其成员所占空间的最大值。 2. 联合体的声明 #include<…

【整体介绍】HTML和JS编写多用户VR应用程序的框架

一、Networked-Aframe是什么&#xff1f; 简称NAF&#xff0c;底层基于Mozilla的AFrame框架&#xff0c;用HTML和JS编写多用户VR应用程序的框架。 二、特性 支持 WebRTC 和/或 WebSocket 连接。 语音聊天。音频流让您的用户在应用程序内交谈&#xff08;仅限 WebRTC&#xff…

2024全球和国内最常用的弱密码,有没有你的?

密码管理器NordPass分析了来自公开来源的超过4.3TB 的密码数据&#xff0c;找出了当前为止&#xff08;2024年&#xff09;最常用&#xff08;最脆弱&#xff09;的密码。 这些密码主要有下面这些特征&#xff1a; 简单且常用&#xff0c;万年弱密码&#xff0c;比如123456、a…

智慧消防建设方案(完整方案参考PPT)

智慧消防系统建设方案旨在通过物联网、大数据与云计算技术&#xff0c;集成火灾自动报警、智能监控、应急指挥等功能于一体。方案部署智能传感器监测火情&#xff0c;实时数据分析预警&#xff0c;实现火灾早发现、早处置。构建可视化指挥平台&#xff0c;优化应急预案&#xf…

Python中发送邮件的艺术:普通邮件、PDF附件与Markdown附件

用的是qq邮箱,具体获取smtp的password可以看这个文章 获取密码 Python中发送邮件的艺术:普通邮件、PDF附件与Markdown附件 在今天的博客中,我们将探讨如何使用Python的smtplib库来发送电子邮件,包括发送普通文本邮件、携带PDF文件的邮件和附带Markdown文件的邮件。这些功能…

视频号助手获取feedId

1.登陆视频号 2.内容管理-视频 3.视频后分享

Git 用法

基本介绍 版本控制工具用处&#xff1a; 备份代码还原协同开发追溯 版本控制工具 1、集中式版本控制工具 版本库是集中存放在中央服务器的&#xff0c;team 里每个人 work 时从中央服务器下载代码&#xff0c;是必须联网才能工作&#xff0c;局域网或互联网。个人修改后然后…

【BUG】已解决:WslRegisterDistribution failed with error: 0x800701bc

已解决&#xff1a;WslRegisterDistribution failed with error: 0x800701bc 欢迎来到英杰社区https://bbs.csdn.net/topics/617804998 欢迎来到我的主页&#xff0c;我是博主英杰&#xff0c;211科班出身&#xff0c;就职于医疗科技公司&#xff0c;热衷分享知识&#xff0c;武…

【北京迅为】《i.MX8MM嵌入式Linux开发指南》-第二篇 Linux系统编程篇-第三十一章 文件IO和标准IO

i.MX8MM处理器采用了先进的14LPCFinFET工艺&#xff0c;提供更快的速度和更高的电源效率;四核Cortex-A53&#xff0c;单核Cortex-M4&#xff0c;多达五个内核 &#xff0c;主频高达1.8GHz&#xff0c;2G DDR4内存、8G EMMC存储。千兆工业级以太网、MIPI-DSI、USB HOST、WIFI/BT…