File: send.py

package info (click to toggle)
python-pika 0.9.14-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,048 kB
  • ctags: 2,110
  • sloc: python: 10,046; makefile: 134
file content (41 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import pika
import time
import logging

logging.basicConfig(level=logging.DEBUG)

ITERATIONS = 100

connection = pika.BlockingConnection(pika.URLParameters('amqp://guest:guest@localhost:5672/%2F?heartbeat_interval=1'))
channel = connection.channel()

def closeit():
    print('Close it')
    connection.close()

connection.add_timeout(5, closeit)

connection.sleep(100)

"""
channel.confirm_delivery()
start_time = time.time()

for x in range(0, ITERATIONS):
    if not channel.basic_publish(exchange='test',
                                 routing_key='',
                                 body='Test 123',
                                 properties=pika.BasicProperties(content_type='text/plain',
                                                                 app_id='test',
                                                                 delivery_mode=1)):
        print 'Delivery not confirmed'
    else:
        print 'Confirmed delivery'

channel.close()
connection.close()

duration = time.time() - start_time
print "Published %i messages in %.4f seconds (%.2f messages per second)" % (ITERATIONS, duration, (ITERATIONS/duration))

"""