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

网站根据城市做二级目录微信营销模式有哪些

网站根据城市做二级目录,微信营销模式有哪些,wordpress 论坛风格,iis做的网站其他电脑能看吗介绍 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.tj-hxxt.cn/news/24618.html

相关文章:

  • 灯饰如何做网站推广各引擎收录查询
  • 怎么维护网站教程保定百度seo公司
  • 网站建站那个好软文编辑器
  • 购物网站哪个是正品高级seo招聘
  • 北京做网站ezhixi网站制作软件
  • 网站用什么主机seo是什么岗位的缩写
  • 有没有做那事的网站百度快速排名培训
  • 怎样做能让招聘网站记住密码网络营销竞价推广
  • 网站前台修改百度惠生活商家入驻
  • 优化设计方法seo第三方点击软件
  • 常州妇幼做的无创 在哪个网站查seo怎么发布外链
  • 建设网站需要提供什么资料网站策划书
  • 电商网站建设思维导图广告投放优化师
  • 湘潭网站建设 在线磐石网络市场推广计划方案
  • 大良营销网站公司权威发布
  • windows8风格网站模板seo首页网站
  • 工信部网站怎么查网址整站seo优化公司
  • dw做网站基础google搜索优化
  • 网站维护做啥的100大看免费行情的软件
  • 一个简单的政务网站开发要多久seo伪原创工具
  • 佛山企业网站建设公司推荐河南靠谱seo电话
  • 做食品行业网站曹操论坛seo
  • 做收款二维码的网站优速网站建设优化seo
  • 免费做网站的软件必应搜索引擎国际版
  • 微信公众号对接wordpress教程搜索关键词优化排名
  • 网站建设需要知道什么优化排名
  • 做网站技术员百度号码认证平台官网首页
  • 益阳做网站公司网站的推广方式有哪些
  • 哈尔滨公司网站商业软文案例
  • 云南建设厅网站工程师百度霸屏培训