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

wordpress小工具侧边栏网站推广优化平台

wordpress小工具侧边栏,网站推广优化平台,建设银行网站登录不了,名侦探柯南网页设计模板图片介绍 RabbitMQ 是一个消息中间件,它实现了 AMQP (Advanced Message Queuing Protocol) 协议。本教程将引导你通过几个简单的步骤来学习如何使用 RabbitMQ 发送和接收消息。 环境准备 1. 安装 RabbitMQ - 在你的系统上安装 RabbitMQ: https://www.rabbitmq.com/d…

介绍

RabbitMQ 是一个消息中间件,它实现了 AMQP (Advanced Message Queuing Protocol) 协议。本教程将引导你通过几个简单的步骤来学习如何使用 RabbitMQ 发送和接收消息。

环境准备

1. 安装 RabbitMQ

- 在你的系统上安装 RabbitMQ: https://www.rabbitmq.com/download.html

- 启动服务: `sudo rabbitmq-server`

2. 安装客户端库

- Python 示例将使用 `pika` 库: `pip install pika`

第一步: 创建生产者

创建一个简单的生产者,用于发送消息到 RabbitMQ 服务器。

```python

import pika

def main():

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))

channel = connection.channel()

channel.queue_declare(queue='hello')

message = "Hello World!"

channel.basic_publish(exchange='',

routing_key='hello',

body=message)

print(" [x] Sent %r" % message)

connection.close()

if __name__ == '__main__':

main()

```

第二步: 创建消费者

创建一个简单的消费者,用于接收来自 RabbitMQ 服务器的消息。

```python

import pika

def callback(ch, method, properties, body):

print(" [x] Received %r" % body)

def main():

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))

channel = connection.channel()

channel.queue_declare(queue='hello')

channel.basic_consume(queue='hello',

on_message_callback=callback,

auto_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')

channel.start_consuming()

if __name__ == '__main__':

main()

```

第三步: 使用持久化消息

确保消息在 RabbitMQ 重启后仍然存在。

生产者代码修改

```python

import pika

def main():

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))

channel = connection.channel()

channel.queue_declare(queue='hello', durable=True)

message = "Hello World!"

channel.basic_publish(exchange='',

routing_key='hello',

body=message,

properties=pika.BasicProperties(

delivery_mode=2, # make message persistent

))

print(" [x] Sent %r" % message)

connection.close()

if __name__ == '__main__':

main()

```

消费者代码修改

```python

import pika

def callback(ch, method, properties, body):

print(" [x] Received %r" % body)

def main():

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))

channel = connection.channel()

channel.queue_declare(queue='hello', durable=True)

channel.basic_qos(prefetch_count=1)

channel.basic_consume(queue='hello',

on_message_callback=callback,

auto_ack=False)

print(' [*] Waiting for messages. To exit press CTRL+C')

channel.start_consuming()

if __name__ == '__main__':

main()

```

第四步: 使用工作队列

实现一个简单的工作队列,可以分发任务给多个工作者。

生产者

```python

import pika

import sys

import random

def main():

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))

channel = connection.channel()

channel.queue_declare(queue='task_queue', durable=True)

message = ' '.join(sys.argv[1:]) or "Hello World!"

message += f" {random.randint(1, 10)}"

channel.basic_publish(

exchange='',

routing_key='task_queue',

body=message,

properties=pika.BasicProperties(delivery_mode=2)) # make message persistent

print(" [x] Sent %r" % message)

connection.close()

if __name__ == '__main__':

main()

```

工作者

```python

import pika

import time

def callback(ch, method, properties, body):

print(" [x] Received %r" % body)

time.sleep(body.count(b'.'))

print(" [x] Done")

ch.basic_ack(delivery_tag=method.delivery_tag)

def main():

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))

channel = connection.channel()

channel.queue_declare(queue='task_queue', durable=True)

print(' [*] Waiting for messages. To exit press CTRL+C')

channel.basic_qos(prefetch_count=1)

channel.basic_consume(queue='task_queue',

on_message_callback=callback)

channel.start_consuming()

if __name__ == '__main__':

main()

```

http://www.hengruixuexiao.com/news/56725.html

相关文章:

  • android studio中文怎么设置东莞seo建站优化工具
  • 运营商网站登录注册平台推广策略都有哪些
  • 杭州网站关键词排名刚刚发生 北京严重发生
  • 给政府做采购哪个网站平台网站底部友情链接
  • 湘潭做网站 m磐石网络网站域名费一年多少钱
  • wordpress新闻资讯主题windows优化大师和360哪个好
  • 上海专业网站建设百度指数的主要功能有
  • 怎么做自己的刷赞网站北京网站seo哪家公司好
  • 免费做电子书的网站有哪些网站推广优化怎么做最好
  • 我的电脑做网站服务器吗网络营销常见的工具
  • 微信搜一搜排名优化seo收索引擎优化
  • 深圳网站制作的公司哪家好免费b站推广网站下载
  • 佛山网站建设公司电话新网站seo外包
  • WordPress 分类 调用济南网站优化
  • 免费的外网服务器专业培训seo的机构
  • 深圳+服装+网站建设搜索量查询百度指数
  • 石家庄网站开发报价网站设计公司模板
  • 做网站的计划书seo自然排名优化
  • 潍坊企业自助建站系统谷歌paypal官网
  • 建设企业网站小微培训机构咨询
  • 介绍好的免费网站模板下载什么平台可以发广告引流
  • 免费建站模板网站谷歌平台推广外贸
  • wordpress是什么东西站长工具 seo查询
  • 寿光网站建设公司百度网
  • 石首seo排名网络优化大师
  • 东莞网络营销价格咨询草根seo视频大全
  • 自豪的使用wordpress找不到代码seo综合查询平台
  • 郑州建网站产品营销推广策略
  • 外贸可以什么网站做优化师是一份怎样的工作
  • 哪些网站上可以做租车站长查询工具