Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import pika
- def doQuery( conn, i ) :
- cur = conn.cursor()
- cur.execute("SELECT * FROM table OFFSET %s LIMIT 100000", (i,))
- return cur.fetchall()
- print "Using psycopg2"
- import psycopg2
- myConnection = psycopg2.connect( host=hostname, user=username,
- password=password, dbname=database )
- connection =
- pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
- channel = connection.channel()
- channel.queue_declare(queue='task_queue2')
- endloop = False
- i = 1
- while True:
- results = doQuery( myConnection, i )
- j = 0
- while j < 10000:
- try:
- results[j][-1]
- except:
- endloop = True
- break
- message = str(results[j][-1]).encode("hex")
- channel.basic_publish(exchange='',
- routing_key='task_queue2',
- body=message
- #properties=pika.BasicProperties(
- #delivery_mode = 2, # make message persistent
- )#)
- j = j + 1
- # if i % 10000 == 0:
- # print i
- if endloop == False:
- break
- i = i + 10000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement