forked from jettify/aionsq
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
485 additions
and
763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,5 @@ | ||
__version__ = '0.4.5' | ||
__version__ = '1.0.0' | ||
from asyncnsq.tcp.writer import create_writer | ||
from asyncnsq.tcp.reader import create_reader | ||
|
||
import asyncio | ||
from .utils import get_host_and_port | ||
from .nsq import Nsq | ||
from .consumer import NsqConsumer | ||
|
||
|
||
async def create_nsq_producer(host='127.0.0.1', port=4150, loop=None, queue=None, | ||
heartbeat_interval=30000, feature_negotiation=True, | ||
tls_v1=False, snappy=False, deflate=False, deflate_level=6, | ||
consumer=False, sample_rate=0): | ||
"""" | ||
initial function to get producer | ||
param: host: host addr with no protocol. 127.0.0.1 | ||
param: port: host port | ||
param: queue: queue where all the msg been put from the nsq | ||
param: heartbeat_interval: heartbeat interval with nsq, set -1 to disable nsq heartbeat check | ||
params: snappy: snappy compress | ||
params: deflate: deflate compress can't set True both with snappy | ||
""" | ||
# TODO: add parameters type and value validation | ||
host, tmp_port = get_host_and_port(host) | ||
if not port: | ||
port = tmp_port | ||
loop = loop or asyncio.get_event_loop() | ||
queue = queue or asyncio.Queue(loop=loop) | ||
conn = Nsq(host=host, port=port, queue=queue, | ||
heartbeat_interval=heartbeat_interval, | ||
feature_negotiation=feature_negotiation, | ||
tls_v1=tls_v1, snappy=snappy, deflate=deflate, | ||
deflate_level=deflate_level, | ||
sample_rate=sample_rate, consumer=consumer, loop=loop) | ||
await conn.connect() | ||
return conn | ||
|
||
|
||
async def create_nsq_consumer(host=None, loop=None, | ||
max_in_flight=42, lookupd_http_addresses=None): | ||
"""" | ||
initial function to get consumer | ||
param: host: host addr with no protocol. 127.0.0.1 | ||
param: port: host port | ||
param: max_in_flight: number of messages get but not finish or req | ||
param: lookupd_http_addresses: heartbeat interval with nsq, set -1 to disable nsq heartbeat check | ||
""" | ||
# TODO: add parameters type and value validation | ||
if host is None: | ||
host = ['tcp://127.0.0.1:4150'] | ||
hosts = [get_host_and_port(i) for i in host] | ||
loop = loop or asyncio.get_event_loop() | ||
if lookupd_http_addresses: | ||
conn = NsqConsumer(lookupd_http_addresses=lookupd_http_addresses, | ||
max_in_flight=max_in_flight, loop=loop) | ||
else: | ||
conn = NsqConsumer(nsqd_tcp_addresses=hosts, | ||
max_in_flight=max_in_flight, loop=loop) | ||
await conn.connect() | ||
return conn | ||
__all__ = ['create_writer', 'create_reader', 'tcp', 'http'] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
from .lookupd import NsqLookupd | ||
from .nsqd import Nsqd | ||
from .writer import NsqdHttpWriter | ||
|
||
(NsqLookupd, Nsqd) | ||
|
||
__all__ = ['NsqLookupd', 'Nsqd'] | ||
__all__ = ['NsqLookupd', 'NsqdHttpWriter'] |
Oops, something went wrong.