示例#1
0
def msg_size_test(broker, url, psize):
    if( broker == 'mqtt' or broker == 'amqp' ):
        p_client = None
        s_client = None
        if( broker == 'mqtt' ):
            p_client = mqttClient(1, url)
            s_client = mqttClient(2, url)
            topic = {'topic': 'x', 'psize': psize, 'qos':0 }
            kwargs_p = {'nr':10, 'ival':1}
            msg_s = {'topic':'x', 'qos':0, 'cb':on_message}
            kwargs_s = {'timeout' : 20}
        else:
            p_client = amqpClient(1, url)
            s_client = amqpClient(2, url)
            topic = [ {'exchange': 'x', 'routing_key': '', 'psize': psize } ]
            kwargs_p = {'nr': 10, 'ival': 1}
            msg_s = {'exchange': 'x', 'cb': callback, 'no_ack': True}
            kwargs_s = {'timeout' : 20}
            
        p_client.connect()
        s_client.connect()

        s_client.subscribe(msg_s, kwargs_s)
        s_client.start_subscribe_timeout(topic, kwargs_s)
        
        time.sleep(1)
        
        p_client.publish(topic, kwargs_p)

        ## wait until they are terminated, make sure to disconnect so that connections at the host are freed
        p_client.waitForClient()
        s_client.waitForClient()
        
    return np.median(timevals), np.mean(timevals), np.var(timevals)
def pub_sub_test(url, nr_pub, queue_size, timeout):
    global timevals
    global recv_packets
    p_clients = []
    s_client = amqpClient(0, url)
    s_client.connect()
    kwargs_s = {
        'timeout': timeout,
        'arguments': {
            'x-max-length-bytes': queue_size
        }
    }
    msg_s = {'exchange': 'x', 'cb': callback, 'no_ack': True}
    s_client.subscribe(msg_s, kwargs_s)
    sent_pkt = []
    for c in range(0, nr_pub):
        client = None
        topic = None
        kwargs = None

        client = amqpClient(c, url)
        topic = [{'exchange': 'x', 'routing_key': '', 'psize': 1}]
        kwargs_p = {'nr': 1, 'ival': 1, 'sent_list': sent_pkt}

        p_clients.append(client)
        client.connect()

    time.sleep(1)  # wait for subscribers to be fully initialized

    for p in p_clients:
        p.publish(topic, kwargs_p)

    ## wait until they are terminated, make sure to disconnect so that connections at the host are freed
    s_client.waitForClient()

    for p in p_clients:
        p.waitForClient()

    timevals_median = np.median(timevals)
    timevals = []
    recv_pkt = copy.deepcopy(recv_packets)
    recv_packets = []
    return timevals_median, sent_pkt, recv_pkt
示例#3
0
def var_sub_test(broker, url, nr_pub, nr_con):
    if (broker == 'mqtt' or broker == 'amqp'):
        p_clients = []
        s_clients = []
        for c in range(0, nr_pub + nr_con):
            client = None
            topic = None
            kwargs = None

            if (broker == 'mqtt'):
                client = mqttClient(c, url)
                topic = {'topic': 'x', 'psize': 1, 'qos': 0}
                kwargs_p = {'nr': 1, 'ival': 1}
                msg_s = {'topic': 'x', 'qos': 0, 'cb': on_message}
                kwargs_s = {'timeout': 10}
            else:
                client = amqpClient(c, url)
                topic = [{'exchange': 'x', 'routing_key': '', 'psize': 1}]
                kwargs_p = {'nr': 1, 'ival': 1}
                msg_s = {'exchange': 'x', 'cb': callback, 'no_ack': True}
                kwargs_s = {'timeout': 10}

            if (c < nr_pub):
                p_clients.append(client)
            else:
                s_clients.append(client)
            client.connect()

        for s in s_clients:
            s.subscribe(msg_s, kwargs_s)

        for s in s_clients:
            s.start_subscribe_timeout(topic, kwargs_s)

        time.sleep(1)

        for p in p_clients:
            p.publish(topic, kwargs_p)

        ## wait until they are terminated, make sure to disconnect so that connections at the host are freed
        for p in p_clients:
            p.waitForClient()

        for s in s_clients:
            s.waitForClient()

    return np.median(timevals), np.mean(timevals), np.var(timevals), len(
        timevals)
    nr_con = 1

    if (broker == 'mqtt' or broker == 'amqp'):
        for c in range(0, nr_pub + nr_con):
            client = None
            topic = None
            kwargs = None

            if (broker == 'mqtt'):
                client = mqttClient(c, url)
                topic = {'topic': 'x', 'psize': 1, 'qos': 0}
                kwargs_p = {'nr': 1, 'ival': 1}
                msg_s = {'topic': 'x', 'qos': 0, 'cb': on_message}
                kwargs_s = {'timeout': timeout}
            else:
                client = amqpClient(c, url)
                topic = [{'exchange': 'x', 'routing_key': '', 'psize': 1}]
                kwargs_p = {'nr': 1, 'ival': 1}
                msg_s = {'exchange': 'x', 'cb': callback, 'no_ack': True}
                kwargs_s = {'timeout': timeout}

            if (c < nr_pub):
                p_clients.append(client)
                pubs += 1
            else:
                s_clients.append(client)
                subs += 1
            client.connect()

        print('Publishers: {0} Subscribers: {1}'.format(pubs, subs))
from amqpClient import amqpClient
from threading import Thread
import pika
import time


def callback(ch, method, properties, body):
    print(body.decode('utf-8'))


if __name__ == "__main__":

    #url = 'amqp://*****:*****@golden-kangaroo.rmq.cloudamqp.com/bbjpgbhk'
    url = 'amqp://*****:*****@192.168.43.104:5672'

    amqp = amqpClient(1, url)

    amqp.connect()
    topic = [{'exchange': 'y', 'routing_key': '', 'psize': 10}]
    amqp.publish(pubmsg=topic, kwargs={'nr': 3, 'ival': 0.3})
    #amqp.subscribe('temp')

    print("going to while loop")
    while (True):
        time.sleep(1)
    #    print('in script')
def pub_sub_run(broker, url, nr_pub, nr_con, interval=1):
    global timevals
    timevals = []
    if (broker == 'mqtt' or broker == 'amqp'):
        p_clients = []
        s_clients = []
        pubs = 0
        subs = 0
        timeout = 170

        for c in range(0, nr_pub + nr_con):
            client = None
            topic = None
            kwargs = None

            if (broker == 'mqtt'):
                client = mqttClient(c, url)
                topic = {'topic': 'my/topic', 'psize': 1, 'qos': 0}
                kwargs_p = {'nr': 1, 'ival': interval}
                msg_s = {
                    'topic': 'my/topic',
                    'qos': 0,
                    'cb': callback_pub_sub_test_mqtt
                }
                kwargs_s = {'timeout': timeout}
            else:
                client = amqpClient(c, 'amqp://{0}'.format(url))
                topic = [{'exchange': 'x', 'routing_key': '', 'psize': 1}]
                kwargs_p = {'nr': 1, 'ival': interval}
                msg_s = {
                    'exchange': 'x',
                    'cb': callback_pub_sub_test,
                    'no_ack': True,
                    'auto_delete': True
                }
                kwargs_s = {'timeout': timeout}
            if (c < nr_pub):
                p_clients.append(client)
                pubs += 1
            else:
                s_clients.append(client)
                subs += 1
            client.connect()

        print('Publishers: {0} Subscribers: {1}'.format(pubs, subs))

        for s in s_clients:
            s.subscribe(msg_s, kwargs_s)

        time.sleep(5)

        for s in s_clients:
            s.start_subscribe_timeout(topic, kwargs_s)

        for p in p_clients:
            p.publish(topic, kwargs_p)

        ## wait until they are terminated, make sure to disconnect so that connections at the host are freed
        for p in p_clients:
            p.waitForClient()

        for s in s_clients:
            s.waitForClient()

        print('Total msgs received: {}'.format(len(timevals)))
    return np.median(timevals), nr_pub - nr_con
def msg_interval_test(broker,
                      url,
                      fileName,
                      iterations=1,
                      stepsize=1,
                      interval=0.01):
    y_packetloss = []
    x_msg_s = []

    y_times = []
    for i in range(stepsize, iterations + 1, stepsize):
        global recv_msgs, timevals
        recv_msgs = 0
        timevals = []
        p_clients = []
        s_client = None
        msgs_pr_publisher = 600
        timeout = 170

        if (broker == 'mqtt' or broker == 'amqp'):
            client = None
            topic = None
            kwargs = None

            subs = 0
            pubs = 0
            for j in range(i + 1):
                if (broker == 'mqtt'):
                    client = mqttClient(j, url)
                    topic = {'topic': 'x', 'psize': 1, 'qos': 0}
                    kwargs_p = {'nr': msgs_pr_publisher, 'ival': interval}
                    msg_s = {
                        'topic': 'x',
                        'qos': 0,
                        'cb': callback_msg_interval_mqtt
                    }
                    kwargs_s = {'timeout': timeout}
                else:
                    client = amqpClient(j, 'amqp://{0}'.format(url))
                    topic = [{'exchange': 'x', 'routing_key': '', 'psize': 1}]
                    kwargs_p = {'nr': msgs_pr_publisher, 'ival': interval}
                    msg_s = {
                        'exchange': 'x',
                        'cb': callback_msg_interval,
                        'no_ack': True,
                        'auto_delete': True
                    }
                    kwargs_s = {'timeout': timeout}

                if (j < i):
                    p_clients.append(client)
                    pubs += 1
                else:
                    s_client = client
                    subs += 1

                client.connect()

            print('Publishers: {0} Subscribers: {1}'.format(pubs, subs))
            if (not s_client.isConnected()):
                s_client.connect()

            s_client.subscribe(msg_s, kwargs_s)
            s_client.start_subscribe_timeout(topic, kwargs_s)

            time.sleep(1)

            for p in p_clients:
                p.publish(topic, kwargs_p)

            ## wait until they are terminated, make sure to disconnect so that connections at the host are freed
            s_client.waitForClient()

            for p in p_clients:
                p.waitForClient()

            sent_msgs = i / interval

            x_msg_s.append(i * interval)

            if (sent_msgs > 0):
                y_packetloss.append(recv_msgs / sent_msgs)
            else:
                y_packetloss.append(0)

            y_times.append(np.median(timevals))
        print('Total msgs received: {}'.format(len(timevals)))

    write_to_csv(x_msg_s, y_packetloss,
                 '../csv/finalresults/{0}'.format(fileName[0]),
                 'Packet loss test')
    write_to_csv(x_msg_s, y_times,
                 '../csv/finalresults/{0}'.format(fileName[1]),
                 'Median receive time single consumer')
示例#8
0
from amqpClient import amqpClient


def callback(ch, method, properties, body):
    print(" [x] %r" % body)


url = 'amqp://*****:*****@golden-kangaroo.rmq.cloudamqp.com/bbjpgbhk'
amqpC = amqpClient(url)
amqpC.connect()
amqpC.subscribe({'exchange': 'logs', 'callback': callback, 'no_ack': True})
示例#9
0
from amqpClient import amqpClient
from threading import Thread
import pika
import time


def callback(ch, method, properties, body):
    print(body.decode('utf-8'))


if __name__ == "__main__":

    url = 'amqp://*****:*****@golden-kangaroo.rmq.cloudamqp.com/bbjpgbhk'
    amqp = amqpClient(url)

    amqp.connect()
    amqp.subscribe({
        'exchange': 'x',
        'cb': callback,
        'no_ack': True
    }, {'timeout': 30})

    print("going to while loop")
    while (True):
        time.sleep(1)
    #    print('in script')