Skip to main content

python使用MQ的场景

Project description

本代码是有关消息中间件组件的一些使用

##rabbimq

import zz_spider
from zz_spider.rabbit_mq.MqDeal import DealRabbitMQ

使用

# -*- coding: utf-8 -*-
# @Time    : 10/14/21 5:38 PM
# @Author  : ZZK
# @File : test_spider.py
# @describe :
from zz_spider.RabbitMq import DealRabbitMQ

host = xxx
port = xxx
user = xxx
password = xxx
queue_name = xxx
url_port = xxx


def spider(res):
    """
    :param res:
    :return:
    """

    for i in res:
        data =i
        #mongo(data)
        print(i)

mqobeject = DealRabbitMQ(host,user=user,passwd=password,port=port,url_port=url_port)

#spider_main 放置抓取的主要函数
mqobeject.consumer_mq(spider_main=spider,queue_name=queue_name)

#将错误数据写入失败队列中,后缀名必须为_error
mqobeject.send_mq(queue_name='123_error',msg={'1':1})

##kafka

# 发送
producer = KkProducer(
    bootstrap_servers=bootstrap_servers,
    options_name=options_name,
    try_max_times=try_max_times
    )

params:
    bootstrap_servers 创建连接域名:端口; (例:127.0.0.1:9092)
    options_name 话题名称:topics (例:topic_{flow_id}_{execute_id}_{data_time})
    try_max_times 失败重试最大次数, 默认为 3

test:测试连接 test_send.py

# 接收

如需帮助请联系 zzk_python@163.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zz_spider-1.0.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

zz_spider-1.0.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file zz_spider-1.0.0.tar.gz.

File metadata

  • Download URL: zz_spider-1.0.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for zz_spider-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2c365347f8743398b371478593d20deebe0d6afd07eeed874181823a4b0f52bd
MD5 e35e087d5bb015674b7b150e9c1b8977
BLAKE2b-256 53ab9ac9bf76ec770516cb2f22388342b1b46879dc49abcc4f696531e31edbcc

See more details on using hashes here.

File details

Details for the file zz_spider-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: zz_spider-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for zz_spider-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a9763666db60cbe2ec7563955bd9f1cea2b9bf6d77c50f66716c1ac05f67c08a
MD5 0e0fbc85b5afd260e6f150e9b40a4a02
BLAKE2b-256 ec2f389dd1c1f7b40d406112ffdba8a5571783ee2c94f0f90fdaa04b3ffe50e6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page