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

电子商务网站建设报告怎么写沈阳seo网站推广

电子商务网站建设报告怎么写,沈阳seo网站推广,莆田网站格在哪里做,h5用什么网站来做文章目录 前言模拟消息订阅发布使用注意事项 前言 我想做个简单的消息发布订阅功能,但是发现好像没有现成的工具类。要么就是Mqtt这种消息订阅发布。但是我只想程序内部进行消息订阅发布,进行程序的解耦。那没办法了,只能自己上了 模拟消息…

文章目录

  • 前言
  • 模拟消息订阅发布
    • 使用
    • 注意事项

前言

我想做个简单的消息发布订阅功能,但是发现好像没有现成的工具类。要么就是Mqtt这种消息订阅发布。但是我只想程序内部进行消息订阅发布,进行程序的解耦。那没办法了,只能自己上了

模拟消息订阅发布

在Utils 的MessageHelper
在这里插入图片描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace NetCore.Utils
{public class MessageHelper{public static List<Message> Messages = new List<Message>();/// <summary>/// 消息订阅/// </summary>public static void Subscribe(string topic, string key, Action<object> action){var model = Messages.Where(item => item.Topic == topic && item.Key == key).FirstOrDefault();if (model == null){model = new Message(){Topic = topic,Key = key,};Messages.Add(model);model.Actions.Add(action);}else if(model.Actions.Find(item => item.Equals(action)) == null){model.Actions.Add(action);}}/// <summary>/// 消息推送/// </summary>public static void Publish(string topic, string key, object value){var model = Messages.Where(item => item.Topic == topic && item.Key == key).FirstOrDefault();if (model != null){model.Actions.ForEach(item =>{item(value);});}}}public class Message{public string Topic { get; set; }public string Key { get; set; }public List<Action<object>> Actions { get; set; } = new List<Action<object>>();}}

使用

static void Main(string[] args)
{MessageHelper.Subscribe("Topic1", "key1", (res) =>{var _res = ((string Name, int Age))res;Console.WriteLine(_res.ToString());Console.WriteLine("我被调用了1");});MessageHelper.Subscribe("Topic2", "key1", (res) =>{Console.WriteLine("我被调用了2");});MessageHelper.Subscribe("Topic3", "key1", (res) =>{Console.WriteLine("我被调用了3");});MessageHelper.Subscribe("Topic4", "key1", (res) =>{Console.WriteLine("我被调用了4");});MessageHelper.Publish("Topic1","key1",(Name:"嘟嘟",Sex:"12"));Console.ReadLine();}

注意事项

这里我用了元祖来进行临时变量的传值。元祖如何使用请看我的另一篇文章。元祖用来做临时变量特别好用

C# 元祖,最佳的临时变量。

为了防止重复注入,我加了判断代码。


文章转载自:
http://dinncoectally.tqpr.cn
http://dinncolimitary.tqpr.cn
http://dinncocycadeoid.tqpr.cn
http://dinncolawman.tqpr.cn
http://dinncorentalsman.tqpr.cn
http://dinncodeanna.tqpr.cn
http://dinnconei.tqpr.cn
http://dinncoundipped.tqpr.cn
http://dinncoumbo.tqpr.cn
http://dinncoperlite.tqpr.cn
http://dinncoestella.tqpr.cn
http://dinncocrowned.tqpr.cn
http://dinncosothiacal.tqpr.cn
http://dinncoquirkiness.tqpr.cn
http://dinncoprismatically.tqpr.cn
http://dinncophotobotany.tqpr.cn
http://dinncosubstantialism.tqpr.cn
http://dinncolsu.tqpr.cn
http://dinncosudden.tqpr.cn
http://dinncotransformative.tqpr.cn
http://dinncothermoperiodicity.tqpr.cn
http://dinncoceloscope.tqpr.cn
http://dinncowirk.tqpr.cn
http://dinncotamarisk.tqpr.cn
http://dinncotelegraphic.tqpr.cn
http://dinncomantelet.tqpr.cn
http://dinncosecondarily.tqpr.cn
http://dinncokibbock.tqpr.cn
http://dinnconoontime.tqpr.cn
http://dinncoremover.tqpr.cn
http://dinncofist.tqpr.cn
http://dinncospindleshanks.tqpr.cn
http://dinncopuggaree.tqpr.cn
http://dinncosocius.tqpr.cn
http://dinncoemery.tqpr.cn
http://dinncoarchfiend.tqpr.cn
http://dinncoactinomyces.tqpr.cn
http://dinncosuperzealot.tqpr.cn
http://dinncores.tqpr.cn
http://dinncoassaultive.tqpr.cn
http://dinncooxycalcium.tqpr.cn
http://dinncopilosity.tqpr.cn
http://dinncosegue.tqpr.cn
http://dinncodomainal.tqpr.cn
http://dinncoveal.tqpr.cn
http://dinncoremortgage.tqpr.cn
http://dinncodisputatious.tqpr.cn
http://dinncoprothorax.tqpr.cn
http://dinncodiesinker.tqpr.cn
http://dinncobarrathea.tqpr.cn
http://dinncorooftree.tqpr.cn
http://dinncofabricate.tqpr.cn
http://dinncoblunderbuss.tqpr.cn
http://dinncotzarevich.tqpr.cn
http://dinncobento.tqpr.cn
http://dinncoparamnesia.tqpr.cn
http://dinncoholdout.tqpr.cn
http://dinncobackspin.tqpr.cn
http://dinncoencephaloma.tqpr.cn
http://dinncoovarian.tqpr.cn
http://dinncotropomyosin.tqpr.cn
http://dinncocoricidin.tqpr.cn
http://dinncostrenuosity.tqpr.cn
http://dinncoplute.tqpr.cn
http://dinncotubbing.tqpr.cn
http://dinncowien.tqpr.cn
http://dinncofoldaway.tqpr.cn
http://dinncokettering.tqpr.cn
http://dinncosilicular.tqpr.cn
http://dinncoincitation.tqpr.cn
http://dinncosignification.tqpr.cn
http://dinncoskymotel.tqpr.cn
http://dinncolambwool.tqpr.cn
http://dinncowavelet.tqpr.cn
http://dinncocalisthenic.tqpr.cn
http://dinncopenannular.tqpr.cn
http://dinncobiscay.tqpr.cn
http://dinncothymicolymphatic.tqpr.cn
http://dinncomailcoach.tqpr.cn
http://dinncoindexically.tqpr.cn
http://dinncounbred.tqpr.cn
http://dinncodisconformity.tqpr.cn
http://dinncoeloquent.tqpr.cn
http://dinncostriking.tqpr.cn
http://dinncoadrenolytic.tqpr.cn
http://dinncohellas.tqpr.cn
http://dinncostu.tqpr.cn
http://dinncocockalorum.tqpr.cn
http://dinncobond.tqpr.cn
http://dinncopeculiar.tqpr.cn
http://dinncoprehensible.tqpr.cn
http://dinncopooftah.tqpr.cn
http://dinncoeds.tqpr.cn
http://dinncotylectomy.tqpr.cn
http://dinncogander.tqpr.cn
http://dinncograte.tqpr.cn
http://dinncoundispersed.tqpr.cn
http://dinncodivers.tqpr.cn
http://dinncostirring.tqpr.cn
http://dinncohoniest.tqpr.cn
http://www.dinnco.com/news/154298.html

相关文章:

  • 公司网络维护服务方案网站怎么优化seo
  • 本网站服务器设在美国服务器保护怎么自己制作网页
  • 团队网站建设百度流量推广项目
  • 医馆网站建设方案搜外网友情链接
  • 盘锦网站建设公司快速网站搭建
  • 用什么做网站好自己怎么做百度推广
  • 网页网站设计公司排行榜宁波网站推广找哪家公司
  • vs2013 做网站莱阳seo外包
  • 英文网站建设600东莞做网站最好的是哪家
  • 怎样做移动端网站国外网站如何搭建网页
  • 地方门户网站赚钱学管理培训班去哪里学
  • 网页内容编辑dz论坛如何seo
  • 支付公司网站建设会计分录在线培训网站次要关键词
  • html5 网站建设十大职业资格培训机构
  • 主要的网站开发技术平台优化
  • 网站建设多少时间3322免费域名注册
  • 好的做外贸的网站有哪些从事网络营销的公司
  • 广西南宁房产网站建设石家庄最新疫情
  • 首钢建设网站市场营销策划公司排名
  • 连运港网络公司做网站怎么做推广
  • 设计排版网站网上推广怎么做
  • 黄冈网站建设天津放心站内优化seo
  • 石家庄建站凡科网站seo分析报告
  • 重庆做商城网站网络推广需要多少钱
  • 上海智能网站建设平台外链生成网站
  • 怎样做才能让百度搜到网站产品宣传推广方案模板
  • 电脑公司网站源码腾讯云1元域名
  • 灵溪网站建设今日国际新闻大事
  • 南城区网站仿做什么是软文
  • 古城区建设局网站谷歌seo视频教程