Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/env python2.7
A script to clear out nsq topics and channels. This is particularly useful in dev for when
topics naturally backup, or when launching a producer with some time before a consumer exists
import tornado.options
import tornado.httpclient
import logging
import json
import urllib
def clear(topic, channel=None):'clearing %s %s', topic, channel)
if channel:
endpoint = "/empty_channel?" + urllib.urlencode(dict(topic=topic, channel=channel))
endpoint = "/empty_topic?" + urllib.urlencode(dict(topic=topic))
client = tornado.httpclient.HTTPClient()
client.fetch('' + endpoint)
def run():
min_depth = tornado.options.options.min_depth
client = tornado.httpclient.HTTPClient()
data = json.loads(client.fetch('').body)
for topic in data['data']['topics']:
if tornado.options.options.topic and topic['topic_name'] not in tornado.options.options.topic:
if topic['depth'] > min_depth:
for channel in topic['channels']:
if channel['depth'] > min_depth:
clear(topic['topic_name'], channel['channel_name'])
if __name__ == "__main__":
tornado.options.define("min_depth", type=int, default=100, help="the depth after which things are zero'd")
tornado.options.define("topic", type=str, multiple=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.