This project has moved. For the latest updates, please go here.

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:
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)
    bus_service.send_queue_message(queue_name, msg)
    return msg.custom_properties

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,

    pool_outputs =, 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!
Jul 7, 2015 at 12:12 AM
hi, please see the front page.

PTVS has moved to github.

please post there.