当前位置: 首页>>代码示例>>Python>>正文


Python Nsqd.publish_http方法代码示例

本文整理汇总了Python中gnsq.Nsqd.publish_http方法的典型用法代码示例。如果您正苦于以下问题:Python Nsqd.publish_http方法的具体用法?Python Nsqd.publish_http怎么用?Python Nsqd.publish_http使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gnsq.Nsqd的用法示例。


在下文中一共展示了Nsqd.publish_http方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_backoff

# 需要导入模块: from gnsq import Nsqd [as 别名]
# 或者: from gnsq.Nsqd import publish_http [as 别名]
def test_backoff():
    with NsqdIntegrationServer() as server:
        conn = Nsqd(
            address=server.address,
            tcp_port=server.tcp_port,
            http_port=server.http_port,
        )

        for _ in range(500):
            conn.publish_http('test', 'danger zone!')

        reader = Reader(
            topic='test',
            channel='test',
            nsqd_tcp_addresses=[server.tcp_address],
            max_in_flight=100,
            message_handler=lambda reader, message: None
        )

        reader.start(block=False)
        reader.start_backoff()

        assert reader.state == states.THROTTLED
        assert reader.total_in_flight_or_ready <= 1

        reader.complete_backoff()
        assert reader.state == states.RUNNING
开发者ID:caseymacphee,项目名称:gnsq,代码行数:29,代码来源:test_reader.py

示例2: _

# 需要导入模块: from gnsq import Nsqd [as 别名]
# 或者: from gnsq.Nsqd import publish_http [as 别名]
    def _(server1, server2):
        class Accounting(object):
            count = 0
            total = 100
            concurrency = 0
            error = None

        for server in (server1, server2):
            conn = Nsqd(
                address=server.address,
                tcp_port=server.tcp_port,
                http_port=server.http_port,
            )

            for _ in xrange(Accounting.total / 2):
                conn.publish_http('test', 'danger zone!')

        reader = Reader(
            topic='test',
            channel='test',
            nsqd_tcp_addresses=[
                server1.tcp_address,
                server2.tcp_address,
            ],
            max_in_flight=5,
            max_concurrency=1,
        )

        @reader.on_exception.connect
        def error_handler(reader, message, error):
            if isinstance(error, NSQSocketError):
                return
            Accounting.error = error
            reader.close()

        @reader.on_message.connect
        def handler(reader, message):
            assert message.body == 'danger zone!'
            assert Accounting.concurrency == 0

            Accounting.concurrency += 1
            gevent.sleep()
            Accounting.concurrency -= 1

            Accounting.count += 1
            if Accounting.count == Accounting.total:
                reader.close()

        try:
            reader.start()
        except NSQSocketError:
            pass

        if Accounting.error:
            raise Accounting.error

        assert Accounting.count == Accounting.total
开发者ID:godber,项目名称:gnsq,代码行数:59,代码来源:test_reader.py

示例3: test_messages

# 需要导入模块: from gnsq import Nsqd [as 别名]
# 或者: from gnsq.Nsqd import publish_http [as 别名]
def test_messages():
    with NsqdIntegrationServer() as server:

        class Accounting(object):
            count = 0
            total = 500
            error = None

        conn = Nsqd(
            address=server.address,
            tcp_port=server.tcp_port,
            http_port=server.http_port,
        )

        for _ in xrange(Accounting.total):
            conn.publish_http('test', 'danger zone!')

        reader = Reader(
            topic='test',
            channel='test',
            nsqd_tcp_addresses=[server.tcp_address],
            max_in_flight=100,
        )

        @reader.on_exception.connect
        def error_handler(reader, message, error):
            if isinstance(error, NSQSocketError):
                return
            Accounting.error = error
            reader.close()

        @reader.on_message.connect
        def handler(reader, message):
            assert message.body == 'danger zone!'

            Accounting.count += 1
            if Accounting.count == Accounting.total:
                assert not reader.is_starved
                reader.close()

        try:
            reader.start()
        except NSQSocketError:
            pass

        if Accounting.error:
            raise Accounting.error

        assert Accounting.count == Accounting.total
开发者ID:godber,项目名称:gnsq,代码行数:51,代码来源:test_reader.py

示例4: _

# 需要导入模块: from gnsq import Nsqd [as 别名]
# 或者: from gnsq.Nsqd import publish_http [as 别名]
        def _(server1, server2):
            class Accounting(object):
                count = 0
                total = 500
                concurrency = 0
                error = None

            for server in (server1, server2):
                conn = Nsqd(
                    address=server.address,
                    tcp_port=server.tcp_port,
                    http_port=server.http_port,
                )

                for _ in range(Accounting.total // 2):
                    conn.publish_http('test', b'danger zone!')

            reader = Reader(
                topic='test',
                channel='test',
                lookupd_http_addresses=lookupd_server.http_address,
                max_in_flight=32,
            )

            @reader.on_exception.connect
            def error_handler(reader, message, error):
                if isinstance(error, NSQSocketError):
                    return
                Accounting.error = error
                reader.close()

            @reader.on_message.connect
            def handler(reader, message):
                assert message.body == b'danger zone!'

                Accounting.count += 1
                if Accounting.count == Accounting.total:
                    reader.close()

            gevent.sleep(0.1)
            reader.start()

            if Accounting.error:
                raise Accounting.error

            assert Accounting.count == Accounting.total
开发者ID:caseymacphee,项目名称:gnsq,代码行数:48,代码来源:test_reader.py


注:本文中的gnsq.Nsqd.publish_http方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。