Abp vNext(五)集成MQTTnet,可收发消息

一 前言

MQTT的相关理论内容这里不做过多介绍,请看下面两篇文章:

Introduction · MQTT协议中文版

MQTT协议-CSDN博客

这篇文章只做代码实现,文章中使用MQTTnet作为MQTT开发的组件。

MQTT分为服务端和客户端,一个服务端对应多个客户端。其中服务端相当于是一台服务器,它是MQTT消息传输的枢纽,负责将MQTT客户端发送来的消息传递给另一个客户端;MQTT服务端还负责管理客户端,确保客户端之间的通讯顺畅,保证MQTT消息得以正确接收和准确投递。

MQTT客户端可以向服务端发布信息,也可以从服务端接受信息,我们把客户端向服务端发送消息的行为称为“发布”消息,客户端也可以“订阅”消息。

二 服务端

服务端可以不用自己开发,有几个常用的第三方服务端,比如EMQ,EMQ怎么使用的,可以查看官网:物联网实时消息引擎 | EMQ

这里不介绍第三方服务,这里具体介绍如何自己动手开发服务端。

1、添加MQTTnet引用

新建一个控制台应用程序,打开NuGet程序包,添加MQTTnet,版本选择3.0.13,选择版本这里要注意一下,不同的版本实现方式不同,下面的实现代码中,如果选择高版本,可能会有异常。

2、代码实现

 不啰嗦,直接上代码

using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Client.Receiving;
using MQTTnet.Protocol;
using MQTTnet.Server;
using System.Text;namespace ConsoleApp2
{internal class Program{static void Main(string[] args){MqttServerClass serverClass = new MqttServerClass();serverClass.StartMqttServer().Wait();Console.ReadLine();}}public static class Config{public static int Port { get; set; } = 1883;public static string UserName { get; set; } = "Username";public static string Password { get; set; } = "Password";}public class UserInstance{public string ClientId { get; set; }public string UserName { get; set; }public string Password { get; set; }}public class MqttServerClass{private IMqttServer mqttServer;private List<MqttApplicationMessage> messages = new List<MqttApplicationMessage>();public async Task StartMqttServer(){try{if (mqttServer == null){var optionsBuilder = new MqttServerOptionsBuilder().WithDefaultEndpoint().WithDefaultEndpointPort(Config.Port)//连接拦截器.WithConnectionValidator(c =>{//var flag = c.Username == Config.UserName && c.Password == Config.Password;//if (!flag)//{//    c.ReasonCode = MqttConnectReasonCode.BadUserNameOrPassword;//    return;//}//设置代码为 Successc.ReasonCode = MqttConnectReasonCode.Success;//instances.Add(new UserInstance()  //缓存到内存的List集合当中//{//    ClientId = c.ClientId,//    UserName = c.Username,//    Password = c.Password//});})//订阅拦截器.WithSubscriptionInterceptor(c =>{if (c == null) return;c.AcceptSubscription = true;})//应用程序消息拦截器.WithApplicationMessageInterceptor(c =>{if (c == null) return;c.AcceptPublish = true;})//clean session是否生效.WithPersistentSessions();mqttServer = new MqttFactory().CreateMqttServer();//客户端断开连接拦截器//mqttServer.UseClientDisconnectedHandler(c =>//{//    //var user = instances.FirstOrDefault(t => t.ClientId == c.ClientId);//    //if (user != null)//    //{//    //    instances.Remove(user);//    //}//});//服务开始mqttServer.StartedHandler = new MqttServerStartedHandlerDelegate(OnMqttServerStarted);//服务停止mqttServer.StoppedHandler = new MqttServerStoppedHandlerDelegate(OnMqttServerStopped);//客户端连接mqttServer.ClientConnectedHandler = new MqttServerClientConnectedHandlerDelegate(OnMqttServerClientConnected);//客户端断开连接(此事件会覆盖拦截器)mqttServer.ClientDisconnectedHandler = new MqttServerClientDisconnectedHandlerDelegate(OnMqttServerClientDisconnected);//客户端订阅mqttServer.ClientSubscribedTopicHandler = new MqttServerClientSubscribedHandlerDelegate(OnMqttServerClientSubscribedTopic);//客户端取消订阅mqttServer.ClientUnsubscribedTopicHandler = new MqttServerClientUnsubscribedTopicHandlerDelegate(OnMqttServerClientUnsubscribedTopic);//服务端收到消息mqttServer.ApplicationMessageReceivedHandler = new MqttApplicationMessageReceivedHandlerDelegate(OnMqttServerApplicationMessageReceived);await mqttServer.StartAsync(optionsBuilder.Build());//主动发送消息到客户端//await mqttServer.PublishAsync(new//     MqttApplicationMessage//{//    Topic = "testtopic",//    Payload = Encoding.UTF8.GetBytes("dsdsd")//});//mqttServer.GetClientStatusAsync();//mqttServer.GetRetainedApplicationMessagesAsync();//mqttServer.GetSessionStatusAsync();}}catch (Exception ex){Console.WriteLine($"MQTT Server start fail.>{ex.Message}");}}private void OnMqttServerStarted(EventArgs e){if (mqttServer.IsStarted){Console.WriteLine("MQTT服务启动完成!");}}private void OnMqttServerStopped(EventArgs e){if (!mqttServer.IsStarted){Console.WriteLine("MQTT服务停止完成!");}}private void OnMqttServerClientConnected(MqttServerClientConnectedEventArgs e){Console.WriteLine($"客户端[{e.ClientId}]已连接");}private void OnMqttServerClientDisconnected(MqttServerClientDisconnectedEventArgs e){Console.WriteLine($"客户端[{e.ClientId}]已断开连接!");}private void OnMqttServerClientSubscribedTopic(MqttServerClientSubscribedTopicEventArgs e){Console.WriteLine($"客户端[{e.ClientId}]已成功订阅主题[{e.TopicFilter}]!");}private void OnMqttServerClientUnsubscribedTopic(MqttServerClientUnsubscribedTopicEventArgs e){Console.WriteLine($"客户端[{e.ClientId}]已成功取消订阅主题[{e.TopicFilter}]!");}private void OnMqttServerApplicationMessageReceived(MqttApplicationMessageReceivedEventArgs e){messages.Add(e.ApplicationMessage);Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"));Console.WriteLine($"客户端[{e.ClientId}]>> Topic[{e.ApplicationMessage.Topic}] Payload[{Encoding.UTF8.GetString(e.ApplicationMessage.Payload ?? new byte[] { })}] Qos[{e.ApplicationMessage.QualityOfServiceLevel}] Retain[{e.ApplicationMessage.Retain}]");}}}

三 客户端

客户端可以做成一个独立的项目,如果有什么地方需要调用比如发送消息的方法,可以直接引用MQTT服务直接进行调用,当然这是其中一个思路,我目前把MQTT服务放在了Application项目中,具体的实现思路就不细聊了,看官方文档吧,我这里直接上代码,主打一个拿来就用。

注意:

1、先启动mqtt服务端,在启动客户端,同时客户端配置文件appsetting.json中MqttHost配置要加上,节点MqttHost中无值,MQTT客户端不启用,目前主题是固定的testTopic

2、项目即可发送消息,又可接收消息

先看项目结构

1、appsettings.json增加配置节点

HttpApi.Host项目中的appsettings.json增加MQTT相关配置节点

"MqttSettingsProvider": {"BrokerHostSettings": {"MqttHost": "", //localhost //服务端ip"MqttPort": 1883  //服务端端口},"ClientSettings": {"ClientId": "5eb020f043ba8930506acbdd2","UserName": "","Password": ""},"TopicName": "testTopic"
}

2、添加MQTTnet引用

在Application项目中通过NuGet包添加MQTTnet引用,版本与服务端保持一致3.0.13

3、代码示例

下面的代码示例不是按代码书写顺序来的,为了方便写文档,直接按文件顺序粘贴代码

Application→MqttServer→AspCoreMqttClientOptionBuilder.cs

using MQTTnet.Client.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WMSInterface.MqttServer
{public class AspCoreMqttClientOptionBuilder : MqttClientOptionsBuilder{public IServiceProvider ServiceProvider { get; }public AspCoreMqttClientOptionBuilder(IServiceProvider serviceProvider){ServiceProvider = serviceProvider;}}
}

Application→MqttServer→BrokerHostSettings.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WMSInterface.MqttServer
{public class BrokerHostSettings{public string MqttHost { get; set; }public int MqttPort { get; set; }}
}

Application→MqttServer→ClientSettings.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WMSInterface.MqttServer
{public class ClientSettings{public string ClientId { get; set; }public string UserName { get; set; }public string Password { get; set; }}
}

Application→MqttServer→IMessageSendService.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WMSInterface.MqttServer
{public interface IMessageSendService{int Order { get; }Task SendMessage(MessageContext context);}
}

Application→MqttServer→IMqttClientService.cs

using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MQTTnet.Client.Connecting;
using MQTTnet.Client.Disconnecting;
using MQTTnet.Client.Receiving;namespace WMSInterface.MqttServer
{public interface IMqttClientService : IHostedService, IMqttClientConnectedHandler, IMqttClientDisconnectedHandler, IMqttApplicationMessageReceivedHandler{Task Publish(string topicName, string message);}
}

Application→MqttServer→MessageContext.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WMSInterface.MqttServer
{public class MessageContext{public string TopicName { get; set; }public string Title { get; set; }public string Content { get; set; }//public IList<UserModel> UserList { get; set; } = new List<UserModel>();public string[] Users { get; set; }public string ObjId { get; set; }}
}

Application→MqttServer→MqttClientService.cs

using MQTTnet.Client;
using MQTTnet.Protocol;
using MQTTnet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Microsoft.Extensions.Options;
using MQTTnet.Server;
using System.Threading;
using Microsoft.Extensions.Hosting;
using MQTTnet.Client.Connecting;
using MQTTnet.Client.Disconnecting;
using MQTTnet.Client.Receiving;
using Microsoft.Extensions.DependencyInjection;
using MQTTnet.Client.Options;
using WMSInterface.Server;namespace WMSInterface.MqttServer
{public class MqttClientService : IMqttClientService, IHostedService, IMqttClientConnectedHandler, IMqttClientDisconnectedHandler, IMqttApplicationMessageReceivedHandler{private IMqttClient mqttClient;private IMqttClientOptions options;private readonly IServiceProvider _serviceProvider;public MqttClientService(IMqttClientOptions options, IServiceProvider serviceProvider){this.options = options;_serviceProvider = serviceProvider;mqttClient = new MqttFactory().CreateMqttClient();ConfigureMqttClient();}private void ConfigureMqttClient(){mqttClient.ConnectedHandler = this;mqttClient.DisconnectedHandler = this;mqttClient.ApplicationMessageReceivedHandler = this;}public async Task HandleApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs e){IEnumerable<IMqttMessageHandler> handlers = _serviceProvider.GetServices<IMqttMessageHandler>();foreach (IMqttMessageHandler handler in handlers){await handler.HandleMessage(e.ApplicationMessage.Topic, e.ApplicationMessage.Payload);}}public async Task Publish(string topicName, string message){string topic = topicName.Trim();string msg = message.Trim();if (string.IsNullOrEmpty(topic)){Console.Write("主题不能为空!");}else if (!mqttClient.IsConnected){Console.Write("MQTT客户端尚未连接!");}else{await MqttClientExtensions.PublishAsync(applicationMessage: new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(msg).WithAtMostOnceQoS().WithRetainFlag(value: false).Build(), client: mqttClient);}}/// <summary>/// 订阅连接成功事件/// </summary>/// <param name="eventArgs"></param>/// <returns></returns>public async Task HandleConnectedAsync(MqttClientConnectedEventArgs eventArgs){await mqttClient.SubscribeAsync("testTopic");//...可订阅多个主题}/// <summary>/// 订阅断开连接事件/// </summary>/// <param name="eventArgs"></param>/// <returns></returns>public async Task HandleDisconnectedAsync(MqttClientDisconnectedEventArgs eventArgs){await mqttClient.UnsubscribeAsync("testTopic");//尝试重新连接//await mqttClient.ConnectAsync(options);}public async Task StartAsync(CancellationToken cancellationToken){await mqttClient.ConnectAsync(options);if (!mqttClient.IsConnected){await mqttClient.ReconnectAsync();}}public async Task StopAsync(CancellationToken cancellationToken){if (cancellationToken.IsCancellationRequested){MqttClientDisconnectOptions disconnectOption = new MqttClientDisconnectOptions{ReasonCode = MqttClientDisconnectReason.NormalDisconnection,ReasonString = "NormalDiconnection"};await mqttClient.DisconnectAsync(disconnectOption, cancellationToken);}await mqttClient.DisconnectAsync();}}
}

Application→MqttServer→MqttClientServiceProvider.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WMSInterface.MqttServer
{public class MqttClientServiceProvider{public readonly IMqttClientService MqttClientService;public MqttClientServiceProvider(IMqttClientService mqttClientService){MqttClientService = mqttClientService;}}
}

Application→MqttServer→MqttMessageService.cs

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WMSInterface.MqttServer
{public class MqttMessageService : IMessageSendService{private string _topicName = string.Empty;private readonly IMqttClientService _mqttClientService;private readonly ILogger<MqttMessageService> _logger;private readonly IConfiguration _configuration;public int Order => 0;public MqttMessageService(MqttClientServiceProvider mqttClientServiceProvider, ILogger<MqttMessageService> logger, IConfiguration configuration){_mqttClientService = mqttClientServiceProvider.MqttClientService;_logger = logger;_configuration = configuration;_topicName = configuration["MqttSettingsProvider:TopicName"];}public Task SendMessage(MessageContext context){try{if (!string.IsNullOrEmpty(context.Content)){var content = new{content = context.Content,//users = context.UserList.Select((UserModel m) => m.Id.ToString()).ToList()};_mqttClientService.Publish(_topicName, JsonConvert.SerializeObject(content));}}catch (Exception e){_logger.LogError(e, "MQTT发送消息错误。");}return Task.CompletedTask;}}
}

Application→MqttServer→MqttServerModule.cs

注意:这里跟配置文件appsettings.json中的节点MqttHost有关联,MqttHost为空,不启动MQTT客户端服务,MqttHost不为空,会客户端会连接服务端。

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Modularity;namespace WMSInterface.MqttServer
{public class MqttServerModule : AbpModule{public override void ConfigureServices(ServiceConfigurationContext context){IConfiguration configuration = context.Services.GetConfiguration();MqttSettingsProvider mqttSettingsProvider = configuration.GetSection("MqttSettingsProvider").Get<MqttSettingsProvider>();if (!string.IsNullOrEmpty(mqttSettingsProvider.BrokerHostSettings?.MqttHost)){context.Services.AddMqttClientHostedService(mqttSettingsProvider);context.Services.TryAddEnumerable(ServiceDescriptor.Transient<IMessageSendService, MqttMessageService>());}}}
}

Application→MqttServer→MqttServiceCollectionExtension.cs

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WMSInterface.MqttServer
{public static class MqttServiceCollectionExtension{public static IServiceCollection AddMqttClientHostedService(this IServiceCollection services, MqttSettingsProvider mqttSettingsProvider){AddMqttClientServiceWithConfig(services, delegate (AspCoreMqttClientOptionBuilder aspOptionBuilder){IConfiguration configuration = services.GetConfiguration();aspOptionBuilder.WithCredentials(mqttSettingsProvider.ClientSettings.UserName, mqttSettingsProvider.ClientSettings.Password).WithClientId(mqttSettingsProvider.ClientSettings.ClientId).WithTcpServer(mqttSettingsProvider.BrokerHostSettings.MqttHost);});return services;}private static IServiceCollection AddMqttClientServiceWithConfig(this IServiceCollection services, Action<AspCoreMqttClientOptionBuilder> configure){services.AddSingleton(delegate (IServiceProvider serviceProvider){AspCoreMqttClientOptionBuilder aspCoreMqttClientOptionBuilder = new AspCoreMqttClientOptionBuilder(serviceProvider);configure(aspCoreMqttClientOptionBuilder);return aspCoreMqttClientOptionBuilder.Build();});services.AddSingleton<MqttClientService>();services.AddSingleton((Func<IServiceProvider, IHostedService>)((IServiceProvider serviceProvider) => serviceProvider.GetService<MqttClientService>()));services.AddSingleton(delegate (IServiceProvider serviceProvider){MqttClientService service = serviceProvider.GetService<MqttClientService>();return new MqttClientServiceProvider(service);});return services;}}
}

Application→MqttServer→MqttSettingsProvider.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WMSInterface.MqttServer
{public class MqttSettingsProvider{public BrokerHostSettings BrokerHostSettings { get; set; }public ClientSettings ClientSettings { get; set; }}
}

Application→Server→IMqttMessageHandler.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace WMSInterface.Server
{public interface IMqttMessageHandler{Task HandleMessage(string topic, byte[] data);}
}

Application→Server→MqttMessageHandler.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;namespace WMSInterface.Server
{public class MqttMessageHandler: IMqttMessageHandler,ITransientDependency{public async Task HandleMessage(string topic, byte[] data){if (!string.IsNullOrEmpty(topic) || data != null){Console.WriteLine($"接收到的主题:{topic},消息:{Encoding.UTF8.GetString(data)}");}}}
}

xx.HttpApi.Host→xxHttpApiHostModule.cs

typeof(MqttServerModule)

MQTT客户端发送消息代码示例

xx.HttpApi→Controllers→MqttController.cs

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using WMSInterface.MqttServer;namespace WMSInterface.Controllers
{/// <summary>/// mqtt/// </summary>[ApiController][Route("api/[controller]/[action]")]public class MqttController : AbpController{private readonly IConfiguration _configuration;private readonly IMessageSendService _messageSendService;public MqttController(IConfiguration configuration, IMessageSendService messageSendService){_configuration = configuration;_messageSendService = messageSendService;}#region 发送消息/// <summary>/// 发送消息/// </summary>/// <param name="body"></param>/// <returns></returns>[HttpPost]public async Task<IActionResult> SendAsync(MessageContext body){await _messageSendService.SendMessage(body);return Ok("ok");}#endregion}
}

四  MQTT收发消息测试

下载MQTTX工具进行MQTT消息的测试,使用方法就不具体介绍了,基本上是拿来就用

MQTTX:全功能 MQTT 客户端工具

发送消息入口

接收消息示例

五 结尾

本文章不做MQTT科普,默认具有一定的MQTT认知,主要目的是让大家可以直接在abp框架中快速集成MQTT

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

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

Python和C++及R相关系数数学统计学可视化和神经模型及评估指标

&#x1f3af;要点 较少统计样本显著性评估和变量关系梳理功能磁共振成像一致性分析检测非单调关联性结构随机变量动力学相关性热图和矩阵图基因疫苗非线性变量相关性 Python相关矩阵 相关矩阵 n n n 个随机变量 X 1 , … , X n X_1, \ldots, X_n X1​,…,Xn​ 的相关矩阵…

视频去噪技术分享

视频去噪是一种视频处理技术&#xff0c;旨在从视频帧中移除噪声和干扰&#xff0c;提高视频质量。噪声可能由多种因素引起&#xff0c;包括低光照条件、高ISO设置、传感器缺陷等。视频去噪对于提升视频内容的可视性和可用性至关重要&#xff0c;特别是在安全监控、医疗成像和视…

迅为3A6000_7A2000开发板龙芯全国产处理器LoongArch架构核心主板

龙芯 3A6000 处理器完全自主设计、性能优异&#xff0c;代表了我国自主桌面 CPU 设计领域的最新里程碑成果。龙芯 3A6000 处理器的推出&#xff0c;说明国产 CPU 在自主可控程度和产品性能上已双双达到新高度&#xff0c;也证明了国内有能力在自研 CPU 架构上做出一流的产品。 …

聊聊AUTOSAR:基于Vector MICROSAR的TC8测试开发方案

技术背景 车载以太网技术作为汽车智能化和网联化的重要组成部分&#xff0c;正逐步成为现代汽车网络架构的核心&#xff0c;已广泛应用于汽车诊断&#xff08;如OBD&#xff09;、ECU软件更新、智能座舱系统、高清摄像头环视泊车系统等多个领域。 在这个过程中&#xff0c;ET…

SpringCloud 基于 web 的只会养老平台

摘要 首先,论文一开始便是清楚的论述了系统的研究内容。其次,剖析系统需求分析,弄明白“做什么”,分析包括业务分析和业务流程的分析以及用例分析,更进一步明确系统的需求。然后在明白了系统的需求基础上需要进一步地设计系统,主要包罗软件架构模式、整体功能模块、数据库设计…

Django SQL注入-漏洞分析

1.进入项目界面 图1 项目主界面 2.访问任意不存在的目录路径报错&#xff0c;提示存在demo接口 图2 提示存在接口 3.访问/demo/&#xff0c;提示有一个name参数 图3 发现隐藏参数 4.对接口参数进行fuzz&#xff08;实战思路&#xff09;&#xff0c;vulfocus已经给出了/demo?…

Cypress安装与启动(开始学习记录)

一 Cypress安装 使用npm安装 1.查看node.js npm的版本&#xff0c;输入 npm --version 和 node --version&#xff0c;node.js没安装的可以去中文网下载最新稳定版安装&#xff0c;npm不建议升级到最新版本&#xff0c;会导致安装Cypress时Error: Cannot find module ansi-st…

一篇文章解决ComfyUI常见的故障报错!

前言 学习和使用ComfyUI最痛苦的是什么&#xff1f;就是这满屏的红色方框和和[报错信息] “报错信息”)&#xff0c;处理完一批又一批&#xff0c;很多人玩了一两个流程就搞不下去了&#xff0c;很多初学者因此就放弃了。 有道是&#xff1a;配置流程大半天&#xff0c;跑通出…

C++速通LeetCode中等第9题-合并区间

排序后迭代&#xff0c;遇到符合条件的就删除前一项&#xff0c;合并到后一项。 class Solution { public:vector<vector<int>> merge(vector<vector<int>>& intervals) {int left 0,right 0;sort(intervals.begin(), intervals.end());vector&…

YOLOv5模型部署教程

一、介绍 YOLOv5模型是一种以实时物体检测闻名的计算机视觉模型&#xff0c;由Ultralytics开发&#xff0c;并于2020年年中发布。它是YOLO系列的升级版&#xff0c;继承了YOLO系列以实时物体检测能力而著称的特点。 二、基础环境 系统&#xff1a;Ubuntu系统&#xff0c;显卡…

妙笔生花,扩散模型技术探索与分享

一、引言 扩散模型因其强大的图像生成能力引发了巨大的关注,一度达到取代人类插画师的地步。在这个创意无界、视觉为王的时代,扩散模型正悄然带来一场前所未有的视觉盛宴,受到业界广泛关注。OpenAI轰动一时的“Sora”、淘宝AI制图工具“绘蛙”、京东内容创作平台“京点点”…

ATE自动化测试系统集成:软件与硬件的技术结合

ate测试系统集成通常是指将测试软件、测试硬件(如示波器、数字万用表、矢网等)与通信技术组合起来&#xff0c;从而满足产品的测试需求。ATE测试系统集成已经成为提高电子产品测试效率和精度的必要手段。它将多种测试工具与自动化技术相结合&#xff0c;以满足不断升级的测试标…

坦白了,因为这个我直接爱上了 FreeBuds 6i

上个月&#xff0c;华为发布的 FreeBuds 6i 联名了泡泡玛特真的超级惊艳&#xff0c;不少宝子被这款耳机的颜值所吸引&#xff0c;而它的实力更是不容小觑的。FreeBuds 6i 是一款性能强大的降噪耳机&#xff0c;它一直在强调平均降噪深度&#xff0c;但是应该很多人对这个概念很…

从“治理”到“智理”,看大模型如何赋能智慧政务

一、从治理到智理的飞跃 在智慧城市的建设蓝图中&#xff0c;智慧政务如同一股不可忽视的力量&#xff0c;正悄然改变着城市的治理面貌。传统意义上&#xff0c;“治理”往往意味着对复杂社会现象的被动应对&#xff0c;而“智理”则预示着通过智能化手段主动预见、解决问题的…

notepad++的json查看

json文件查看 因为接触到3dtile模型&#xff0c;所以经常需要和json打交道&#xff0c;但是很多模型是下面这种情况&#xff0c;不好阅读&#xff0c;所以可以使用notepad的插件查看 正常打开是这样的 加载notepad插件 搜索json下载安装就可以了 如果网络抽象&#xff0c;下载…

性价比头戴式无线耳机推荐哪款好?四款宝藏性价比机型测评盘点

当消费者在寻找性价比高的头戴式无线耳机时&#xff0c;他们往往希望找到既经济实惠又具备出色性能的产品&#xff0c;市场上有许多品牌和型号可供选择&#xff0c;它们在音质、舒适度、续航能力以及附加功能等方面各有特色&#xff0c;性价比头戴式无线耳机推荐哪款好&#xf…

厂家解读:全钢pvc防静电架空地板的优缺点

为了防止静电带来的危害&#xff0c;数据中心、监控室、多媒体教室等这些电子设备较多、对静电敏感的场所都会安装防静电地板。其中全钢pvc防静电架空地板颇受欢迎&#xff0c;那么什么是全钢pvc防静电架空地板&#xff1f; 全钢pvc防静电架空地板是由优质合金冷轧钢板经过拉伸…

Java双端队列ArrayDeque

概述 双端队列ArrayDeque是Java集合框架中的一种数据结构&#xff0c;它实现了Deque接口&#xff0c;因此支持在两端进行添加和移除元素。通过名称也能看出&#xff0c;ArrayDeque是基于数组实现的&#xff0c;ArrayDeque内部使用一个可动态调整大小的环形数组来存储元素。当Ar…

印尼有几百种语言,初学者要怎么开始学习?《印尼语翻译通》app或许可以帮助你!印尼语零基础入门学习。

快速翻译&#xff0c;准确高效 采用最新技术&#xff0c;提供精准翻译。翻译结果符合中国人习惯。 体验印尼文化 学习地道印尼语&#xff0c;贴近当地文化。 旅游和工作的好帮手 提供旅游和商务用语&#xff0c;沟通无障碍。 学习印尼语的良师 文本和语音翻译&#xff0c;…

C#使用实体类Entity Framework Core操作mysql入门:从数据库反向生成模型

初级代码游戏的专栏介绍与文章目录-CSDN博客 我的github&#xff1a;codetoys&#xff0c;所有代码都将会位于ctfc库中。已经放入库中我会指出在库中的位置。 这些代码大部分以Linux为目标但部分代码是纯C的&#xff0c;可以在任何平台上使用。 源码指引&#xff1a;github源…