C#使用MQTT(一):MQTT服务端

news2024/9/28 7:28:29

MQTT(Message Queuing Telemetry Transport)

即时通讯协议,

开发商 IBM

MQTT(消息队列遥测传输)是ISO 标准(ISO/IEC PRF 20922)下基于发布/订阅范式的消息协议。它工作在 TCP/IP协议族上,是为硬件性能低下的远程设备以及网络状况糟糕的情况下而设计的发布/订阅型消息协议,为此,它需要一个消息中间件 。

MQTT是一个基于客户端-服务器的消息发布/订阅传输协议。MQTT协议是轻量、简单、开放和易于实现的,这些特点使它适用范围非常广泛。在很多情况下,包括受限的环境中,如:机器与机器(M2M)通信和物联网(IoT)。其在,通过卫星链路通信传感器、偶尔拨号的医疗设备、智能家居、及一些小型化设备中已广泛使用。

新建Winform应用程序,将默认的Form1重命名为FormMqttServer

管理Nuget包,输入关键字Mqtt

点击安装

安装完成后示例如图

我们使用MQTTnet.dll,程序集 MQTTnet, Version=4.3.6.1152。应用程序.net framework版本需要4.6.1或者以上

窗体 FormMqttServer 设计如下:

窗体 FormMqttServer设计器代码如下:

文件 FormMqttServer.Designer.cs 


namespace CultureDemo
{
    partial class FormMqttServer
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.lvTopic = new System.Windows.Forms.ListBox();
            this.lbClients = new System.Windows.Forms.ListBox();
            this.rtxtMessage = new System.Windows.Forms.RichTextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.btnStop = new System.Windows.Forms.Button();
            this.btnStart = new System.Windows.Forms.Button();
            this.txtPassword = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.txtUsername = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtPort = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.txtIP = new System.Windows.Forms.TextBox();
            this.lb = new System.Windows.Forms.Label();
            this.dgvTopic = new System.Windows.Forms.DataGridView();
            this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            ((System.ComponentModel.ISupportInitialize)(this.dgvTopic)).BeginInit();
            this.SuspendLayout();
            // 
            // lvTopic
            // 
            this.lvTopic.FormattingEnabled = true;
            this.lvTopic.ItemHeight = 12;
            this.lvTopic.Location = new System.Drawing.Point(686, 35);
            this.lvTopic.Name = "lvTopic";
            this.lvTopic.Size = new System.Drawing.Size(300, 136);
            this.lvTopic.TabIndex = 31;
            // 
            // lbClients
            // 
            this.lbClients.FormattingEnabled = true;
            this.lbClients.ItemHeight = 12;
            this.lbClients.Location = new System.Drawing.Point(343, 35);
            this.lbClients.Name = "lbClients";
            this.lbClients.Size = new System.Drawing.Size(300, 136);
            this.lbClients.TabIndex = 30;
            // 
            // rtxtMessage
            // 
            this.rtxtMessage.Location = new System.Drawing.Point(24, 188);
            this.rtxtMessage.Name = "rtxtMessage";
            this.rtxtMessage.Size = new System.Drawing.Size(467, 338);
            this.rtxtMessage.TabIndex = 29;
            this.rtxtMessage.Text = "";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(684, 17);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(53, 12);
            this.label5.TabIndex = 28;
            this.label5.Text = "主题列表";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(341, 17);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(65, 12);
            this.label4.TabIndex = 27;
            this.label4.Text = "连接客户端";
            // 
            // btnStop
            // 
            this.btnStop.Location = new System.Drawing.Point(129, 148);
            this.btnStop.Name = "btnStop";
            this.btnStop.Size = new System.Drawing.Size(75, 23);
            this.btnStop.TabIndex = 26;
            this.btnStop.Text = "停止";
            this.btnStop.UseVisualStyleBackColor = true;
            this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
            // 
            // btnStart
            // 
            this.btnStart.Location = new System.Drawing.Point(32, 148);
            this.btnStart.Name = "btnStart";
            this.btnStart.Size = new System.Drawing.Size(75, 23);
            this.btnStart.TabIndex = 25;
            this.btnStart.Text = "启动";
            this.btnStart.UseVisualStyleBackColor = true;
            this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
            // 
            // txtPassword
            // 
            this.txtPassword.Location = new System.Drawing.Point(91, 121);
            this.txtPassword.Name = "txtPassword";
            this.txtPassword.Size = new System.Drawing.Size(211, 21);
            this.txtPassword.TabIndex = 24;
            this.txtPassword.Text = "1";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(44, 124);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(29, 12);
            this.label3.TabIndex = 23;
            this.label3.Text = "密码";
            // 
            // txtUsername
            // 
            this.txtUsername.Location = new System.Drawing.Point(91, 94);
            this.txtUsername.Name = "txtUsername";
            this.txtUsername.Size = new System.Drawing.Size(211, 21);
            this.txtUsername.TabIndex = 22;
            this.txtUsername.Text = "a";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(44, 97);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(29, 12);
            this.label2.TabIndex = 21;
            this.label2.Text = "账号";
            // 
            // txtPort
            // 
            this.txtPort.Location = new System.Drawing.Point(91, 58);
            this.txtPort.Name = "txtPort";
            this.txtPort.Size = new System.Drawing.Size(211, 21);
            this.txtPort.TabIndex = 20;
            this.txtPort.Text = "12345";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(44, 61);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(29, 12);
            this.label1.TabIndex = 19;
            this.label1.Text = "端口";
            // 
            // txtIP
            // 
            this.txtIP.Location = new System.Drawing.Point(91, 16);
            this.txtIP.Name = "txtIP";
            this.txtIP.Size = new System.Drawing.Size(211, 21);
            this.txtIP.TabIndex = 18;
            this.txtIP.Text = "127.0.0.1";
            // 
            // lb
            // 
            this.lb.AutoSize = true;
            this.lb.Location = new System.Drawing.Point(32, 19);
            this.lb.Name = "lb";
            this.lb.Size = new System.Drawing.Size(41, 12);
            this.lb.TabIndex = 17;
            this.lb.Text = "IP地址";
            // 
            // dgvTopic
            // 
            this.dgvTopic.AllowUserToAddRows = false;
            this.dgvTopic.AllowUserToDeleteRows = false;
            this.dgvTopic.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvTopic.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column1,
            this.Column2,
            this.Column3,
            this.Column4});
            this.dgvTopic.Location = new System.Drawing.Point(522, 188);
            this.dgvTopic.Name = "dgvTopic";
            this.dgvTopic.ReadOnly = true;
            this.dgvTopic.RowTemplate.Height = 23;
            this.dgvTopic.Size = new System.Drawing.Size(464, 338);
            this.dgvTopic.TabIndex = 32;
            // 
            // Column1
            // 
            this.Column1.HeaderText = "Topic";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            // 
            // Column2
            // 
            this.Column2.HeaderText = "ClientId";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            // 
            // Column3
            // 
            this.Column3.HeaderText = "Qos";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            // 
            // Column4
            // 
            this.Column4.HeaderText = "SessionItems";
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            // 
            // FormMqttServer
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(1013, 538);
            this.Controls.Add(this.dgvTopic);
            this.Controls.Add(this.lvTopic);
            this.Controls.Add(this.lbClients);
            this.Controls.Add(this.rtxtMessage);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.btnStop);
            this.Controls.Add(this.btnStart);
            this.Controls.Add(this.txtPassword);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.txtUsername);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.txtPort);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtIP);
            this.Controls.Add(this.lb);
            this.Name = "FormMqttServer";
            this.Text = "FormMqttServer";
            this.Load += new System.EventHandler(this.FormMqttServer_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dgvTopic)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.ListBox lvTopic;
        private System.Windows.Forms.ListBox lbClients;
        private System.Windows.Forms.RichTextBox rtxtMessage;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Button btnStop;
        private System.Windows.Forms.Button btnStart;
        private System.Windows.Forms.TextBox txtPassword;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox txtUsername;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox txtPort;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox txtIP;
        private System.Windows.Forms.Label lb;
        private System.Windows.Forms.DataGridView dgvTopic;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column4;
    }
}

窗体FormMqttServer代码如下【MQTT服务端相关代码】

文件FormMqttServer.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using MQTTnet.Server;
using MQTTnet;
using MQTTnet.Protocol;
using System.Collections;

namespace CultureDemo
{
    public partial class FormMqttServer : Form
    {
        private MqttServer server;//mqtt服务器对象
        public FormMqttServer()
        {
            InitializeComponent();
            rtxtMessage.ReadOnly = true;
            /*
             * 在MQTT协议中,一个MQTT数据包由:固定头(Fixed header)、可变头(Variable header)、消息体(payload)三部分构成。
固定头(Fixed header):存在于所有MQTT数据包中,表示数据包类型及数据包的分组类标识。
可变头(Variable header):存在于部分MQTT数据包中,数据包类型决定了可变头是否存在及其具体内容。
消息体(Payload):存在于部分MQTT数据包中,表示客户端收到的具体内容。
            */
        }

        /// <summary>
        /// 打印相关消息
        /// </summary>
        /// <param name="contents"></param>
        private void DisplayMessage(string contents) 
        {
            if (!this.IsHandleCreated) 
            {
                return;
            }
            this.BeginInvoke(new Action(() => 
            {
                if (rtxtMessage.TextLength >= 40960) 
                {
                    rtxtMessage.Clear();
                }
                rtxtMessage.AppendText($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}->{contents}\n");
                rtxtMessage.ScrollToCaret();
            }));
        }

        /// <summary>
        /// 初始化Mqtt服务并启动服务
        /// </summary>
        /// <param name="ip">IPV4地址</param>
        /// <param name="port">端口:0~65535之间</param>
        private Task StartMqttServer(string ip, int port)
        {
            MqttServerOptions mqttServerOptions =
                    new MqttServerOptionsBuilder()
                    .WithDefaultEndpoint()
                    .WithDefaultEndpointBoundIPAddress(System.Net.IPAddress.Parse(ip))
                    .WithDefaultEndpointPort(port)   
                    .WithDefaultCommunicationTimeout(TimeSpan.FromMilliseconds(5000))
                    .Build();
            server = new MqttFactory().CreateMqttServer(mqttServerOptions); // create MQTT service object
            server.ValidatingConnectionAsync += Server_ValidatingConnectionAsync;//验证用户名和密码
            server.ClientConnectedAsync += Server_ClientConnectedAsync;//绑定客户端连接事件
            server.ClientDisconnectedAsync += Server_ClientDisconnectedAsync;//绑定客户端断开事件
            server.ClientSubscribedTopicAsync += Server_ClientSubscribedTopicAsync;//绑定客户端订阅主题事件
            server.ClientUnsubscribedTopicAsync += Server_ClientUnsubscribedTopicAsync;//绑定客户端退订主题事件
            server.InterceptingPublishAsync += Server_InterceptingPublishAsync;//消息接收事件
            server.ClientAcknowledgedPublishPacketAsync += Server_ClientAcknowledgedPublishPacketAsync;
            server.InterceptingClientEnqueueAsync += Server_InterceptingClientEnqueueAsync;
            server.ApplicationMessageNotConsumedAsync += Server_ApplicationMessageNotConsumedAsync;

            server.StartedAsync += Server_StartedAsync;//绑定服务端启动事件
            server.StoppedAsync += Server_StoppedAsync;//绑定服务端停止事件

            return server.StartAsync();
        }

        private Task Server_ApplicationMessageNotConsumedAsync(ApplicationMessageNotConsumedEventArgs e)
        {
            try
            {
                DisplayMessage($"【MessageNotConsumed】-SenderId:{e.SenderId}-Message:{e.ApplicationMessage.ConvertPayloadToString()}");
            }
            catch (Exception ex)
            {
                DisplayMessage($"Server_ApplicationMessageNotConsumedAsync出现异常:{ex.Message}");
            }
            return Task.CompletedTask;
        }

        private Task Server_InterceptingClientEnqueueAsync(InterceptingClientApplicationMessageEnqueueEventArgs e)
        {
            try
            {
                DisplayMessage($"【InterceptingClientEnqueue】-SenderId:{e.SenderClientId}-Message:{e.ApplicationMessage.ConvertPayloadToString()}");
            }
            catch (Exception ex)
            {
                DisplayMessage($"Server_InterceptingClientEnqueueAsync出现异常:{ex.Message}");
            }
            return Task.CompletedTask;
        }

        private Task Server_ClientAcknowledgedPublishPacketAsync(ClientAcknowledgedPublishPacketEventArgs e)
        {
            try
            {
                DisplayMessage($"【ClientAcknowledgedPublishPacket】-SenderId:{e.ClientId}-Message:{Encoding.UTF8.GetString(e.PublishPacket.PayloadSegment.ToArray())}");
            }
            catch (Exception ex)
            {
                DisplayMessage($"Server_ClientAcknowledgedPublishPacketAsync出现异常:{ex.Message}");
            }
            return Task.CompletedTask;
        }

        /// <summary>
        /// 消息接收
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private Task Server_InterceptingPublishAsync(InterceptingPublishEventArgs e)
        {
            try
            {
                string client = e.ClientId;
                string topic = e.ApplicationMessage.Topic;
                string contents = e.ApplicationMessage.ConvertPayloadToString();//Encoding.UTF8.GetString(arg.ApplicationMessage.PayloadSegment.ToArray());
                DisplayMessage($"接收到消息:Client:【{client}】 Topic:【{topic}】 Message:【{contents}】");
            }
            catch (Exception ex)
            {
                DisplayMessage($"Server_InterceptingPublishAsync出现异常:{ex.Message}");
            }
            return Task.CompletedTask;
        }

        private void FormMqttServer_Load(object sender, EventArgs e)
        {
            rtxtMessage.Text = @"MQTT服务端关键事件说明:
ClientConnectedAsync-->绑定客户端连接事件
ValidatingConnectionAsync-->验证用户名和密码
ClientSubscribedTopicAsync-->绑定客户端订阅主题事件
InterceptingPublishAsync-->消息接收事件
";
        }

        private Task Server_StoppedAsync(EventArgs arg)
        {
            return Task.Run(new Action(() =>
            {
                DisplayMessage($"服务端【{txtIP.Text}:{txtPort.Text}】已停止MQTT");
            }));
        }

        private Task Server_StartedAsync(EventArgs e)
        {
            return Task.Run(new Action(() =>
            {
                DisplayMessage($"服务端【{txtIP.Text}:{txtPort.Text}】已启用MQTT");
            }));
        }

        private Task Server_ClientUnsubscribedTopicAsync(ClientUnsubscribedTopicEventArgs e)
        {
            return Task.Run(new Action(() =>
            {
                lvTopic.Invoke(new Action(() =>
                {
                    string itemContents = $"【{e.ClientId}】订阅主题【{e.TopicFilter}】";
                    if (lvTopic.Items.Contains(itemContents))
                    {
                        //如果存在该项,就移除
                        lvTopic.Items.Remove(itemContents);
                    }
                    IDictionary collection = e.SessionItems;
                    string[] sessionItemContents = new string[collection.Count];
                    int idx = 0;
                    foreach (object key in collection.Keys)
                    {
                        sessionItemContents[idx++] = $"[{key}:{collection[key]}]";
                    }
                }));
                DisplayMessage($"客户端【{e.ClientId}】退订主题【{e.TopicFilter}】");
            }));
        }

        private Task Server_ClientSubscribedTopicAsync(ClientSubscribedTopicEventArgs e)
        {
            return Task.Run(new Action(() =>
            {
                lvTopic.Invoke(new Action(() =>
                {
                    string itemContents = $"【{e.ClientId}】订阅主题【{e.TopicFilter.Topic}】";
                    if (!lvTopic.Items.Contains(itemContents))
                    {
                        //如果不存在该项,就添加
                        lvTopic.Items.Add(itemContents);
                    }
                    IDictionary collection = e.SessionItems;
                    string[] sessionItemContents = new string[collection.Count];
                    int idx = 0;
                    foreach (object key in collection.Keys)
                    {
                        sessionItemContents[idx++] = $"[{key}:{collection[key]}]";
                    }
                    dgvTopic.Rows.Add(e.TopicFilter.Topic, e.ClientId, e.TopicFilter.QualityOfServiceLevel, string.Join(",", sessionItemContents));
                }));
                DisplayMessage($"客户端【{e.ClientId}】订阅主题【{e.TopicFilter.Topic}】");
            }));
        }

        private Task Server_ClientDisconnectedAsync(ClientDisconnectedEventArgs e)
        {
            return Task.Run(new Action(() =>
            {
                lbClients.BeginInvoke(new Action(() =>
                {
                    lbClients.Items.Remove(e.ClientId);
                }));
                DisplayMessage($"客户端已断开.ClientId:【{e.ClientId}】,Endpoint:【{e.Endpoint}】.ReasonCode:【{e.ReasonCode}】,DisconnectType:【{e.DisconnectType}】");
            }));
        }

        /// <summary>
        /// 绑定客户端连接事件
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private Task Server_ClientConnectedAsync(ClientConnectedEventArgs e)
        {
            return Task.Run(new Action(() =>
            {
                lbClients.BeginInvoke(new Action(() =>
                {
                    lbClients.Items.Add(e.ClientId);
                }));
                DisplayMessage($"客户端已连接.ClientId:【{e.ClientId}】,Endpoint:【{e.Endpoint}】");
            }));
        }

        private Task Server_ValidatingConnectionAsync(ValidatingConnectionEventArgs e)
        {
            return Task.Run(new Action(() =>
            {
                string UserName = txtUsername.Text;
                string Password = txtPassword.Text;
                if (e.UserName == UserName && e.Password == Password)
                {
                    e.ReasonCode = MqttConnectReasonCode.Success;
                    DisplayMessage($"客户端已验证成功.ClientId:【{e.ClientId}】,Endpoint:【{e.Endpoint}】");
                }
                else
                {
                    e.ReasonCode = MqttConnectReasonCode.BadUserNameOrPassword;
                    DisplayMessage($"客户端验证失败.ClientId:【{e.ClientId}】,Endpoint:【{e.Endpoint}】");
                }
            }));
        }

        private async void btnStart_Click(object sender, EventArgs e)
        {
            await StartMqttServer(txtIP.Text, int.Parse(txtPort.Text));
            btnStart.Enabled = false;
        }

        private async void btnStop_Click(object sender, EventArgs e)
        {
            await server.StopAsync();
            btnStart.Enabled = true;
        }
    }
}

程序运行如图:

 连接、订阅、发布消息如图

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

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

相关文章

将RK3588平台的TMC等USB function驱动挪出内核源码树

背景 前一段时间定位一个上位机通过USB-TMC连接下位机&#xff08;基于RK3588平台&#xff09;时界面发生卡顿的问题&#xff0c;发现USB-TMC驱动代码是放在内核源码树里跟内核一起编译的&#xff0c;觉着这样既不便于更换TMC 驱动版本&#xff08;每次修改代码都要重编内核&a…

2024年【广西安全员C证】考试题及广西安全员C证考试技巧

题库来源&#xff1a;安全生产模拟考试一点通公众号小程序 广西安全员C证考试题是安全生产模拟考试一点通生成的&#xff0c;广西安全员C证证模拟考试题库是根据广西安全员C证最新版教材汇编出广西安全员C证仿真模拟考试。2024年【广西安全员C证】考试题及广西安全员C证考试技…

AI电商产品一键换高清背景,就是这么简单(comfyui)

comfyui电商产品换背景工作流 工作流作者&#xff1a;Aki Hung c 工作流我放在了文末&#xff0c;需要的朋友自取&#xff01; 这里给大家准备好了一份详细的ComfyUI资料和安装包&#xff0c;扫描下方二维码即可获取&#xff01; 大家好&#xff0c;我是你们的老朋友&#xf…

10.4 网际层协议

网际层协议 真题

YashanDB产品调优实战:分享日常调优技巧及提升系统性能的实战经验

本文旨在提供一系列关于YashanDB产品的调优技巧和实战经验&#xff0c;帮助读者更好地理解和应用这些技术来优化数据库性能。内容将涵盖索引优化、查询优化、内存管理、参数配置&#xff0c;以及性能监控等多个方面&#xff0c;通过实际案例和详细的分析&#xff0c;展示如何有…

程序员学python的七大就业方向!

Python作为一种多功能的编程语言&#xff0c;其就业方向广泛且前景乐观。以下是Python的七大就业方向&#xff1a; Web开发&#xff1a; Python在Web开发领域具有重要地位&#xff0c;拥有Flask、Django等优秀的Web开发框架&#xff0c;可以快速搭建网站和Web应用。这些框架不仅…

【Redis】缓存击穿、缓存穿透、缓存雪崩原理以及多种解决方案

一、前言 在 Spring Cloud 微服务集群项目中&#xff0c;客户端的请求首先会经过 Nginx&#xff0c;Nginx 会将请求反向代理到 Gateway 网关层&#xff0c;接着才会将请求发送到具体的服务 service。 在 service 中如果要查询数据&#xff0c;则会到缓存中查询&#xff0c;如…

COT思维链,TOT思维树,GOT思维图,这些都是什么?

1. 导入 hallucinations 1. 什么是幻觉&#xff1f; 大模型出现幻觉&#xff0c;简而言之就是“胡说八道”。 用《A Survey on Hallucination in Large Language Models》文中的话来讲&#xff0c;是指模型生成的内容与现实世界事实或用户输入不一致的现象。 研究人员将大模型…

基于精益六西格玛管理方法进行生产线综合改善

生产线精益六西格玛改善是一个系统工程&#xff0c;只有对其进行系统的策划与组织&#xff0c;才能收到良好的改善效果。一般来说&#xff0c;需要成立一个专门的精益六西格玛推进组织&#xff0c;由其完成一系列的组织、准备工作。具体如下&#xff1a; &#xff08;1&#xf…

AutosarMCAL开发——基于EB FlsLoader驱动

目录 1.FlsLoader原理2.EB配置以及接口应用3.总结 1.FlsLoader原理 FlsLoader模块提供对Dflash bank0以及整个Pflash的操作。Dflash数据存储器Pflash程序储存器&#xff0c;因此在实际运用中 2.EB配置以及接口应用 EB配置步骤 1.取消安全检查&#xff0c;其他所有配置保持默…

《物流工程与管理》是什么级别的期刊?是正规期刊吗?能评职称吗?

​问题解答 问&#xff1a;《物流工程与管理》是不是核心期刊&#xff1f; 答&#xff1a;不是&#xff0c;是知网收录的第一批认定学术期刊。 问&#xff1a;《物流工程与管理》级别&#xff1f; 答&#xff1a;国家级。主管单位&#xff1a; 全国商品养护科技情报中心站 …

mongodb在Java中条件分组聚合查询并且分页(时间戳,按日期分组,年月日...)

废话不多说&#xff0c;先看效果图&#xff1a; SQL查询结果示例&#xff1a; 多种查询结果示例&#xff1a; 原SQL&#xff1a; db.getCollection("hbdd_order").aggregate([{// 把时间戳格式化$addFields: {orderDate: {"$dateToString": {"for…

分类预测|基于蜣螂优化极限梯度提升决策树的数据分类预测Matlab程序DBO-Xgboost 多特征输入单输出 含基础模型

分类预测|基于蜣螂优化极限梯度提升决策树的数据分类预测Matlab程序DBO-Xgboost 多特征输入单输出 含基础模型 文章目录 一、基本原理1. 数据准备2. XGBoost模型建立3. DBO优化XGBoost参数4. 模型训练5. 模型评估6. 结果分析与应用原理总结 二、实验结果三、核心代码四、代码获…

龙兴物联5G物联网主机:开启电力智能化新篇章

在当今时代&#xff0c;电力行业的智能化已成为不可阻挡的趋势。随着社会对电力需求的持续增长以及对供电质量和可靠性要求的不断提高&#xff0c;传统的电力系统管理模式逐渐难以满足需求。 智能化技术的融入为电力系统带来了革命性的变革。通过先进的传感器、通信网络和数据分…

ELK系列之一---探索ELK奇妙世界:初识日志界大名鼎鼎的ES集群!

目录 一、为什么要使用ELK 二、ELK简介 三、Elaticsearch入门 3.1、什么是elaticsearch 3.2、elaticsearch的底层优点 3.2.1、全文检索 3.2.2、倒排索引 3.3、elaticsearch集群原理 一、为什么要使用ELK 一般我们需要进行日志分析场景&#xff1a;直接在日志文件中 gre…

Linux -文件I/O操作

文章目录 C语言文件I/O相关函数操作fopen/fcolsefwritefseekfprintf/fscanffgets/fputs 系统调用相关接口open/closewrite/read C语言文件I/O相关函数操作 fopen/fcolse fopen 函数用于打开一个文件&#xff0c;并根据指定的模式&#xff08;如只读、只写、读写等&#xff09…

SaaS行业渠道管理的深度探索:两种增长模式哪个更强?

在当今数字化时代&#xff0c;SaaS&#xff08;Software-as-a-Service&#xff09;行业正以前所未有的速度重塑企业运营模式。随着市场的日益成熟与竞争的加剧&#xff0c;渠道管理不再仅仅是产品销售的通道&#xff0c;而是成为了SaaS企业构建生态体系、实现业务飞跃的重要策略…

分类预测|基于粒子群优化轻量级梯度提升机算法数据预测Matlab程序PSO-LightGBM 多特征输入多类别输出

分类预测|基于粒子群优化轻量级梯度提升机算法数据预测Matlab程序PSO-LightGBM 多特征输入多类别输出 文章目录 一、基本原理二、实验结果三、核心代码四、代码获取五、总结 分类预测|基于粒子群优化轻量级梯度提升机算法数据预测Matlab程序PSO-LightGBM 多特征输入多类别输出 …

电脑录屏软件哪家强?这6款高效免费工具让你轻松捕捉电脑屏幕

在数字化浪潮的推动下&#xff0c;电脑录屏软件的选择变得琳琅满目&#xff0c;本文旨在帮助您挑选出最适合您需求的录屏工具。 电脑录屏软件在我们的日常工作、学习乃至娱乐活动中扮演着越来越重要的角色。无论是为了记录PPT的演示过程、捕捉QQ、微信、腾讯会议等设计软件的对…

C8T6超绝模块--按键检测点亮LED

C8T6超绝模块–按键检测点亮LED 大纲 按键原理初始化LED初始化按键编写main 具体案例 按键原理 (这里针对的是我的板子的原理图&#xff0c;具体的查看自己的板子)注意看&#xff0c;这里按键一端接到的是地&#xff0c;当我们没按下按键时&#xff0c;其默认是低电压&…