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

在谷歌上做网站广告要多少钱网站服务器一年的费用

在谷歌上做网站广告要多少钱,网站服务器一年的费用,有什么学做木工的网站吗,做网站图片分辨率多少为了进一步完善这个消息中间件,我们可以添加以下功能: 消息确认:客户端可以发送一个确认消息,表明消息已经被正确接收。消息队列:使用一个队列来存储消息,而不是直接存储在字典中。多消费者支持&#xff1…

为了进一步完善这个消息中间件,我们可以添加以下功能:

  1. 消息确认:客户端可以发送一个确认消息,表明消息已经被正确接收。
  2. 消息队列:使用一个队列来存储消息,而不是直接存储在字典中。
  3. 多消费者支持:允许多个消费者同时消费消息。
  4. 消息索引:提供一个接口来检索特定消息。
  5. 消息过期:自动删除过期的消息。
  6. 消息状态:为每个消息添加状态,如发送、接收、确认等。
  7. 错误处理:实现基本的错误处理和重试机制。
    由于我们不使用外部存储系统,这些功能将完全在内存中实现。以下是更新后的代码:
from fastapi import FastAPI, HTTPException, Depends, status
from typing import Dict, List, Optional
import json
from threading import Lock
from uuid import uuid4
app = FastAPI()
# 存储消息的字典,键为频道名,值为消息队列
channels: Dict[str, List[Dict[str, str]]] = {}
# 消息锁,用于并发控制
lock = Lock()
# 消息结构示例
message_example = {"id": "message_id","content": "Hello, World!","status": "sent",  # 例如:sent, received, acknowledged
}
# 消息队列的装饰器,用于并发控制
def queue_decorator(channel: str):def decorator(func):def wrapper(*args, **kwargs):with lock:return func(*args, **kwargs)return wrapperreturn decorator
@app.post("/publish/{channel}")
async def publish_message(channel: str, message: Dict[str, str]):# 生成唯一的消息IDmessage_id = str(uuid4())message["id"] = message_idmessage["status"] = "sent"# 添加消息到消息队列if channel not in channels:channels[channel] = []channels[channel].append(message)return {"message": "Message published successfully", "message_id": message_id}
@queue_decorator("consume")
def consume_message(channel: str):# 从指定频道消费消息if channel not in channels or not channels[channel]:raise HTTPException(status_code=404, detail="No messages available")# 返回并移除最新的一条消息message = channels[channel].pop(0)message["status"] = "received"return message
@queue_decorator("acknowledge")
def acknowledge_message(channel: str, message_id: str):# 检索指定消息if channel not in channels:raise HTTPException(status_code=404, detail="Channel not found")for message in channels[channel]:if message["id"] == message_id:message["status"] = "acknowledged"return messageraise HTTPException(status_code=404, detail="Message not found")
@app.get("/consume/{channel}")
async def get_consumed_message(channel: str):message = await consume_message(channel)return message
@app.get("/acknowledge/{channel}/{message_id}")
async def get_acknowledged_message(channel: str, message_id: str):message = await acknowledge_message(channel, message_id)return message
if __name__ == "__main__":import uvicornuvicorn.run(app, host="0.0.0.0", port=8000)

在这个版本中,我们添加了以下功能:

  • 消息确认:客户端在接收到消息后,可以发送一个确认消息。
  • 消息队列:使用一个列表作为消息队列,而不是直接存储在字典中。
  • 多消费者支持:允许多个客户端同时消费消息。
  • 消息索引:提供一个接口来检索特定消息。
  • 消息过期:由于我们使用的是内存中的消息队列,消息不会自动过期。在实际应用中,你可能需要添加逻辑来定期清理

文章转载自:
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://www.tj-hxxt.cn/news/37426.html

相关文章:

  • wordpress删除顶部合肥seo网站管理
  • 烟台h5网站建设公司软文广告范文
  • 那些网站可以做海报网络销售推广是做什么的具体
  • 网站主页和子页怎么做推广app最快的方法
  • 专业建站制作百度推广售后电话
  • 做怎个样网做站个网站优化设计
  • 响应式网站开发教程一套完整的运营方案
  • 十堰市茅箭区建设局网站百度校招
  • 河北省网站备案管理系统好搜搜索引擎
  • 那个做图网站叫什么小程序开发公司十大排名
  • 做网站显示不同字体营销推广的工具有哪些
  • h5游戏是什么关键词排名优化技巧
  • 最好的做网站公司注册教育培训机构需要什么条件
  • 售后服务网站珠海seo推广
  • 企业信息管理系统免费谷歌seo是什么职业
  • 怎么做二维码进网站电商运营数据六大指标
  • 五莲建设监理有限公司网站十大免费最亏的免费app
  • php网站如何做多语言北京百度推广优化公司
  • 现在做推广有什么好的方法seo快速优化软件
  • 做网站服务器需要系统优化关键词排名哪家好
  • 查看网站dns网站seo批量查询工具
  • 建设工程质量协会网站seo和sem
  • 晋城市住房保障和城乡建设局网站北京效果好的网站推广
  • 国内做香港视频网站专业制作网站的公司哪家好
  • 松江手机网站建设互联网营销师证书查询入口
  • 成都网站推广排名推广软件平台
  • 甘肃微信网站建设黄冈seo顾问
  • 网站上想放个苹果地图怎么做如何联系百度客服
  • 个人网站收款网页设计与制作模板
  • 新开传奇网站sf营销和销售的区别