Exemple #1
0
# -*- coding: utf-8 -*-
"""
Created on Tue Oct  1 09:21:05 2019
main_amqp.py
@author: martidav
"""
import argparse
import simple_queue_publish
import simple_queue_read

#Choix d'envoyer un message ou de recevoir
parser = argparse.ArgumentParser(
    description='Envoyer un message (s) ou recevoir un message (r)')
parser.add_argument('commande')
parser.add_argument('msg')
args = parser.parse_args()

#Envoyer appeler la function send() dans simple_queue_publish
if args.commande == 's':
    simple_queue_publish.send(args.msg)
    print('envoyer', args.msg)
#Recevoir appeller la fonction read() dans simple_queue_read
if args.commande == 'r':
    simple_queue_read.read()
    print('recevoir')
Exemple #2
0
# -*- coding: utf-8 -*-
"""
@author : Emilien Leroy, LP DIM
@brief : Choose to read or send message
"""
#import library
import argparse
import simple_queue_publish as write
import simple_queue_read as read

#Add argument
parser = argparse.ArgumentParser(description='s_r')
parser.add_argument('-read', action='store_true')
parser.add_argument('-write', action='store_true')
args = parser.parse_args()

#Choose argument
if args.read:
    #read message
    read.read()
    
if args.write:
    #send message
    write.write()
    


    
import os
import simple_queue_publish as  sqp
import simple_queue_read as  sqr

# Configure a connexion to a remote RabbitMQ instance:
amqp_url='amqp://*****:*****@lark.rmq.cloudamqp.com/mywwnzeu'
url = os.environ.get('CLOUDAMQP_URL',amqp_url)
params = pika.URLParameters(url)
params.socket_timeout = 5
#initiate the connexion
connection = pika.BlockingConnection(params) # Connect to CloudAMQP
channel = connection.channel()

# Use of argparse library to switch between publish or read mode
parser = argparse.ArgumentParser(description='Test')
# Argument write
parser.add_argument('-write', action='store_true')
# Argument read
parser.add_argument('-read',  action='store_true')

args = parser.parse_args()

if args.write:
    sqp.write()
if args.read:
    sqr.read()



    
# Creae arguments
parser = argparse.ArgumentParser(
    'Publish/Consume data from queue (CloudAMQP).')
parser.add_argument('-r', '--read', help='Read mode',
                    action='store_true')  # Create argument to choose read mode
parser.add_argument('-n',
                    '--number',
                    type=int,
                    default=1,
                    help='Define number of message to send (Default: 1)'
                    )  # Create argument to count number of message publish
parser.add_argument('-c',
                    '--concurrency',
                    help='Concurency mode (Default false)',
                    action='store_true'
                    )  # Create argument to set concurrency mode when publish
parser.add_argument(
    '-s', '--sleep', help='Add sleep time during reading',
    action='store_true')  # Create argument to set delay on response receiving

# Get args
args = parser.parse_args()
concurrency = args.concurrency
sleep = bool(args.sleep)
if args.read:
    import simple_queue_read as sqr
    sqr.read(amqp_url, queueName, concurrency, sleep)
else:
    import simple_queue_publish as sqp
    sqp.publish(amqp_url, queueName, user, args.number, concurrency)
Exemple #5
0
import simple_queue_publish as qp
import simple_queue_read as qr
import time

parser = argparse.ArgumentParser()
parser.add_argument("-read", action="store_true")
parser.add_argument("-concurrency", action="store_true")
parser.add_argument("-msg")

args = parser.parse_args()

if not args.read:
    nb_msg = int(input("number of message to send : "))
else:
    nb_reader = int(input("number of readers : "))
    if nb_reader > 1:
        slow_reader = input("Make reader 1 slow ? (y/n) : ")
        if slow_reader == 'y':
            slow_reader = True
        else:
            slow_reader = False

if args.read:
    qr.read(args.concurrency, nb_reader, slow_reader)
else:
    if args.msg:
        msg = args.msg
    else:
        msg = "default msg"
    qp.publish(msg, args.concurrency, nb_msg)
Exemple #6
0
                    help="add delay to the concurrent queue readers",
                    action="store_true")
args = parser.parse_args()

url = os.environ.get('CLOUDAMQP_URL', config.amqp_url)
params = pika.URLParameters(url)
params.socket_timeout = 5
connection = pika.BlockingConnection(params)

channel = connection.channel()  # start a channel

if args.concurrency:
    queue = channel.queue_declare("task_queue", durable=True)
    channel.basic_qos(prefetch_count=1)
else:
    queue = channel.queue_declare(queue='hello')

if args.read:
    delay = 0
    if args.delay:
        delay = 0.5
        print("/!\\ 0.5 second of delay /!\\ ")
    simple_queue_read.read(channel, queue.method.queue, delay)

else:
    #  simple_queue_publish.publish(channel, queue.method.queue)
    simple_queue_publish.publish_thounsand_messages(channel,
                                                    queue.method.queue)

connection.close()