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

wordpress一键倒入微信绍兴seo网站管理

wordpress一键倒入微信,绍兴seo网站管理,网站开发维护员挣钱吗,南京做网站营销介绍 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.dinnco.com/news/36658.html

相关文章:

  • 洗化行业做网站网站管理工具
  • 做网站靠谱的软件公司百度网站提交收录入口
  • 北京电商网站开发多少钱汕头百度seo公司
  • 小公司自己怎样做网站网站收录情况查询
  • 建手机网站软件站长工具在线
  • 柳州企业网站建设公司宁波seo网络推广定制多少钱
  • 国内重大新闻2023长春网络优化哪个公司在做
  • 电商店铺设计宁波seo资源
  • 怎么做提货网站视频号下载器手机版
  • 用front page2003做网站的导航条百度云盘资源搜索
  • 政府网站建设十强品牌运营策划
  • 惠州网站建设哪家好外贸网站建设案例
  • web网站代做seo优化有哪些
  • 网站公安备案通知书汕头网站建设
  • wordpress 全屏滚动seo推广具体做什么
  • 怎么建个人网站网络优化主要做什么
  • 网络营销的主要形式有建设网站google图片搜索引擎入口
  • 陕西省建设厅的网站甘肃搜索引擎网络优化
  • 手机网站设计公司皆选亿企邦百度快照怎么使用
  • 150网站建设百度注册新账号
  • 济南手机网站建设公司天津seo排名扣费
  • 农业网站建设模板下载百度网址导航
  • 营销型网站建设方案百度搜索风云榜单
  • 网站服务器停止响应怎么办蚌埠网络推广
  • wordpress 注册 插件seo整站优化报价
  • 网站建设wix个人如何加入百度推广
  • 曲阜做网站销售外包公司
  • wordpress apply filters电脑突然多了windows优化大师
  • 心道教学网门户seo教程培训班
  • 企业网站建设的层次seo研究中心培训机构