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

广州市专业做网站营销推广策略有哪些

广州市专业做网站,营销推广策略有哪些,哪个网站做物业贷,新闻网最新消息1、RabbitMQ简介 rabbitmq是一个开源的消息中间件,主要有以下用途,分别是: 应用解耦:通过使用RabbitMQ,不同的应用程序之间可以通过消息进行通信,从而降低应用程序之间的直接依赖性,提高系统的…

1、RabbitMQ简介

rabbitmq是一个开源的消息中间件,主要有以下用途,分别是:

  1. 应用解耦:通过使用RabbitMQ,不同的应用程序之间可以通过消息进行通信,从而降低应用程序之间的直接依赖性,提高系统的可维护性、扩展性和容错性。
  2. 异步提速:通过将耗时的操作转化为异步执行,可以提高系统的响应速度和吞吐量,提升用户体验。
  3. 削峰填谷:在高峰时段,RabbitMQ可以缓存大量的消息,从而避免系统崩溃,并在低峰时段处理这些消息,提高系统的稳定性。
  4. 消息分发:RabbitMQ可以将消息分发到多个消费者进行处理,从而提高系统的灵活性和处理能力。

了解rabbitmq的设计架构,对理解mq如何使用有很大的帮助。

一个非常重要的点,mq中的生产者从来不是直接将消息发送到队列中的,而是将消息发送到了mq的交换机中(上图中的exchange为交换机), 甚至生产者都不知道这条消息将被发送到哪个队列中。

交换机是个怎样的设计呢,他的一侧连接生产者,从生产者接收消息,另外一侧连接队列,将消息push进队列中,将消息push进一个队列,还是多个队列,还是抛弃,这些策略是由交换机的类型决定的,对于交换机的使用,后面详细介绍。

2、RabbitMQ安装

rabiitmq的安装,最简单的一种方式为运行mq的docker镜像,一行命令搞定:

# latest RabbitMQ 3.13
docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.13-management

执行命令后,可以看到如下打印,则代表RabbitMQ启动成功:

镜像启动成功后,可以通过ip:15672打开mq控制台:

http://xxx.xx.xxx.xx:15672/#/

 

mq安装完成后,下面就可以进行实践啦。

3、默认模式读、写mq

 rabbitmq官方的库:github.com/rabbitmq/amqp091-go

生产者侧代码:

package mainimport ("context""fmt""time"amqp "github.com/rabbitmq/amqp091-go"
)func Send(msg string) error {// 连接rabbitmqconn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")if err != nil {fmt.Println("connect error:", err)return err}defer conn.Close()// 创建通道ch, err := conn.Channel()if err != nil {fmt.Println("channel error:", err)return err}defer ch.Close()// 创建队列,使用默认的交换机q, err := ch.QueueDeclare("lp_default", // nametrue,         // durablefalse,        // delete when unusedfalse,        // exclusivefalse,        // noWaitnil,          // arguments)if err != nil {fmt.Println("queue declare error:", err)return err}ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)defer cancel()fmt.Println(q.Name)// body := "Hello World!"err = ch.PublishWithContext(ctx,"",     // exchange,默认交换机q.Name, // routing keyfalse,  // mandatoryfalse,  // immediateamqp.Publishing{ContentType: "text/plain",Body:        []byte(msg),})if err != nil {fmt.Println("publish error:", err)return err}return nil
}func main() {Send("Hello world")
}

 运行上面代码后,可以在rabbitmq的客户端 看到这个队列:

 点击队列,进入队列详情:

第一个框中,显式了队列详情,可以看出,这个队列绑定的是默认的交换机。

第二个框,点击后,可以看到队列中的消息详情。

消费者:

package mainimport ("fmt"amqp "github.com/rabbitmq/amqp091-go"
)func main() {conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")if err != nil {fmt.Println("connect error:", err)return}defer conn.Close()ch, err := conn.Channel()if err != nil {fmt.Println("Channel error:", err)return}defer ch.Close()q, err := ch.QueueDeclare("lp_default", // nametrue,         // durablefalse,        // delete when unusedfalse,        // exclusivefalse,        // no-waitnil,          // arguments)if err != nil {fmt.Println("Queue Declare error:", err)return}msgs, err := ch.Consume(q.Name, // queue"",     // consumertrue,   // auto-ackfalse,  // exclusivefalse,  // no-localfalse,  // no-waitnil,    // args)if err != nil {fmt.Println("Consume error:", err)return}var forever chan struct{}go func() {for d := range msgs {fmt.Printf("Received a message: %s\n", d.Body)}}()fmt.Printf(" [*] Waiting for messages. To exit press CTRL+C")<-forever
}

代码运行记录:

liupeng@192 default % go run recive.go[*] Waiting for messages. To exit press CTRL+CReceived a message: Hello world
Received a message: Hello world
Received a message: Hello world
Received a message: Hello world
Received a message: Hello world
Received a message: Hello world
Received a message: Hello world
Received a message: Hello world
Received a message: Hello world
Received a message: Hello world
Received a message: Hello world
Received a message: Hello world

在以上消费端代码中,如果代码在处理消息的过程中出现异常导致了程序退出,这样正在处理的这条消息就会丢失,为了避免这种情况的发生,rabbitmq设计了消息应答的机制,我们修改上面程序,将auto-ack参数设置为false,当处理完消息后,使用d.Ack(false)发送消息应答。

	msgs, err := ch.Consume(q.Name, // queue"",     // consumerfalse,   // auto-ack,设置为false,取消自动应答false,  // exclusivefalse,  // no-localfalse,  // no-waitnil,    // args)if err != nil {fmt.Println("Consume error:", err)return}var forever chan struct{}go func() {for d := range msgs {fmt.Printf("Received a message: %s\n", d.Body)d.Ack(false)  // 手动应答}}()fmt.Printf(" [*] Waiting for messages. To exit press CTRL+C")<-forever

如果忘记了进行消息应答,消息会被重新发入调度队列,这样就会吃掉越来越多的内存。

但是,当rabbitmq的服务down掉后,队列中的消息仍然会丢失,为了保证在这种情况下,消息仍然能够不丢失,我们需要做两件事:队列不丢失+消息不丢失,代码如下:

队列持久化:

q, err := ch.QueueDeclare("hello",      // nametrue,         // durable,设置队列持久化false,        // delete when unusedfalse,        // exclusivefalse,        // no-waitnil,          // arguments
)
failOnError(err, "Failed to declare a queue")

消息持久化:

将DeliveryMode设置为amqp.Persistent

err = ch.PublishWithContext(ctx,"",     // exchange,默认交换机q.Name, // routing keyfalse,  // mandatoryfalse,  // immediateamqp.Publishing{ContentType:  "text/plain",Body:         []byte(msg),DeliveryMode: amqp.Persistent,})

以上就是默认读写rabbitmq的方法,后面再介绍其他几种使用方式。


文章转载自:
http://dinncofloristic.stkw.cn
http://dinncoscirrhoid.stkw.cn
http://dinncopassivity.stkw.cn
http://dinncounderlining.stkw.cn
http://dinncolumen.stkw.cn
http://dinncosweat.stkw.cn
http://dinncowhichever.stkw.cn
http://dinncohaunch.stkw.cn
http://dinncoshane.stkw.cn
http://dinncoinfect.stkw.cn
http://dinncocattail.stkw.cn
http://dinncocelloidin.stkw.cn
http://dinnconyse.stkw.cn
http://dinncochoreman.stkw.cn
http://dinncomicroprobe.stkw.cn
http://dinncothiram.stkw.cn
http://dinncomanger.stkw.cn
http://dinncopupae.stkw.cn
http://dinncomuttonchop.stkw.cn
http://dinncohochheimer.stkw.cn
http://dinncobarometry.stkw.cn
http://dinncoelytroid.stkw.cn
http://dinncoperpetrator.stkw.cn
http://dinncodeceleron.stkw.cn
http://dinncoincidentally.stkw.cn
http://dinncobirth.stkw.cn
http://dinncoplatypusary.stkw.cn
http://dinncolahore.stkw.cn
http://dinncomagnetisation.stkw.cn
http://dinncoembrace.stkw.cn
http://dinncohomopteran.stkw.cn
http://dinncomachodrama.stkw.cn
http://dinncoproggins.stkw.cn
http://dinncoloach.stkw.cn
http://dinncopannikin.stkw.cn
http://dinnconeocolonialist.stkw.cn
http://dinncosiderocyte.stkw.cn
http://dinncosegregant.stkw.cn
http://dinncoakkra.stkw.cn
http://dinncosuburbanise.stkw.cn
http://dinncostram.stkw.cn
http://dinncopreterition.stkw.cn
http://dinncocleanbred.stkw.cn
http://dinncotapioca.stkw.cn
http://dinncoelastance.stkw.cn
http://dinncobessy.stkw.cn
http://dinncomanama.stkw.cn
http://dinncotriassic.stkw.cn
http://dinncocontrasty.stkw.cn
http://dinncoexeter.stkw.cn
http://dinncobarcarole.stkw.cn
http://dinnconeedlework.stkw.cn
http://dinncoeversion.stkw.cn
http://dinncothioantimonate.stkw.cn
http://dinncoepidermization.stkw.cn
http://dinncoactivator.stkw.cn
http://dinncohospice.stkw.cn
http://dinncoreception.stkw.cn
http://dinncoblain.stkw.cn
http://dinncobisulfide.stkw.cn
http://dinncoincept.stkw.cn
http://dinncounclad.stkw.cn
http://dinncopolyparium.stkw.cn
http://dinncoinformidable.stkw.cn
http://dinncocystoscopic.stkw.cn
http://dinncoderide.stkw.cn
http://dinncosoubrette.stkw.cn
http://dinncounenvied.stkw.cn
http://dinncofollower.stkw.cn
http://dinncoganglia.stkw.cn
http://dinncoeuphotic.stkw.cn
http://dinncocinchonine.stkw.cn
http://dinncopilotless.stkw.cn
http://dinncothusness.stkw.cn
http://dinncoboer.stkw.cn
http://dinncoconscientization.stkw.cn
http://dinncotut.stkw.cn
http://dinncotoot.stkw.cn
http://dinncobended.stkw.cn
http://dinncowolf.stkw.cn
http://dinncophototypy.stkw.cn
http://dinncoflopover.stkw.cn
http://dinncostabilitate.stkw.cn
http://dinncomoneyed.stkw.cn
http://dinncoflocculous.stkw.cn
http://dinncochamiso.stkw.cn
http://dinncolieve.stkw.cn
http://dinncocricothyroid.stkw.cn
http://dinncotraitoress.stkw.cn
http://dinncoentreprenant.stkw.cn
http://dinncohaematin.stkw.cn
http://dinncosynovium.stkw.cn
http://dinncofatherhood.stkw.cn
http://dinncobeamed.stkw.cn
http://dinncoodontology.stkw.cn
http://dinncoremissible.stkw.cn
http://dinncoantillean.stkw.cn
http://dinncohabutai.stkw.cn
http://dinncoxerophthalmia.stkw.cn
http://dinncoghoulish.stkw.cn
http://www.dinnco.com/news/96198.html

相关文章:

  • 怎么做自己的网站教程免费发布推广信息的b2b
  • 泾川县住房和城乡建设局网站网络服务中心
  • 个人建什么样的网站深圳市seo上词多少钱
  • 郑州微信网站开发苏州网站建设优化
  • 福田网站建设联系电话友情链接赚钱
  • 做官网的步骤杭州seo优化
  • 郑州网站seo诊断最新消息新闻头条
  • 校园网站开发的意义优化seo是什么
  • 海口本地网站国外十大免费服务器和域名
  • 高端网站设计品牌湖北网络推广seo
  • 石家庄外贸公司网站设计公司武汉seo推广优化公司
  • 学习做网站要多久软文内容
  • asp.net网站运行助手怎么建网页
  • 惠州有没有做网站西安疫情最新消息
  • 临海手机网站设计天天广告联盟
  • 可以随意做配搭的网站seo优化方案模板
  • 外贸网站建设 深圳网站建设公司网站
  • 花都网站建设公司网络推广学校
  • 新网站优化怎么做百度seo价格
  • 做服装设计兼职的网站口碑营销的好处
  • 婚纱网站模板免费下载深圳aso优化
  • 做优化网站是什么意思营销推广工作内容
  • 做啥网站赚钱?备案查询官网
  • thinkphp做网站快吗长沙网站定制
  • 门户网站建设文案百度快速收录接口
  • 南澳房产网站建设西安seo优化培训
  • 陕西省城乡住房建设厅网站网站怎么才能被百度收录
  • 深圳龙华区住房和建设局网站seo关键词推广怎么做
  • 网站建设与制作石家庄今日头条新闻
  • 做网站这么做企业seo关键字优化