Azure Service Bus Python message generator

Jul 7, 2015 at 12:10 AM
Edited Jul 7, 2015 at 12:11 AM
Hi *,

I would like to sent a as much as possible messages to service bus and then read by multiple instances from a queue.

Based on this example: http://pymotw.com/2/multiprocessing/communication.html#process-pools
I created this script:
#some SB connection code above

queue_name = ConfigSectionMap("Queue")["queue_name"]
messages_quantity = int(ConfigSectionMap("Messages")["message_quantity"])
message_size = urandom(int(ConfigSectionMap("Messages")["message_size"]))

def send_messages(msg_q):
    #for i in xrange(messages_quantity):
    msg = Message (message_size)
    msg.custom_properties={'id':msg_q}    
    bus_service.send_queue_message(queue_name, msg)
    return msg.custom_properties
    #print(msg.body)

def start_process():
    print 'Starting', multiprocessing.current_process().name

if __name__ == '__main__':
    inputs = list(range(messages_quantity))
    print 'Input   :', inputs

    builtin_outputs = map(send_messages, inputs)
    print 'Built-in:', builtin_outputs

    pool_size = multiprocessing.cpu_count() * 2
    pool = multiprocessing.Pool(processes=pool_size,
                                initializer=start_process,
                                )

    pool_outputs = pool.map(send_messages, inputs)
    pool.close() # no more tasks
    pool.join()  # wrap up current tasks

    print 'Pool    :', pool_outputs
However, I am not sure if it working right. Or is it possible make the multiprocessing part much more optimal?

Further, where I can find examples of information about sending message properties and headers with python?

Thank you!
Coordinator
Jul 7, 2015 at 12:12 AM
hi, please see the front page.

PTVS has moved to github.

please post there.

thx.