# Write out the message body to a temp file for facial detection process
    temp_file = utils.write_temp_file(message.body,
                                      message.properties['content_type'])

    # Detect faces
    result_file = detect.faces(temp_file)

    # Build response properties including the timestamp from the first publish
    properties = {'app_id': 'Chapter 6 Listing 2 Consumer',
                  'content_type': message.properties['content_type'],
                  'correlation_id': message.properties['correlation_id'],
                  'headers': {
                      'first_publish': message.properties['timestamp']}}

    # The result file could just be the original image if nothing detected
    body = utils.read_image(result_file)

    # Remove the temp file
    os.unlink(temp_file)

    # Remove the result file
    os.unlink(result_file)

    # Publish the response response
    response = rabbitpy.Message(channel, body, properties, opinionated=True)
    response.publish('rpc-replies', message.properties['reply_to'])

    # Acknowledge the delivery of the RPC request message
    message.ack()
# Declare the response queue
if response_queue.declare():
    print('Response queue declared')

# Bind the response queue
if response_queue.bind('rpc-replies', queue_name):
    print('Response queue bound')

# Iterate through the images to send RPC requests for
for img_id, filename in enumerate(utils.get_images()):

    print 'Sending request for image #%s: %s' % (img_id, filename)

    # Create the message
    message = rabbitpy.Message(channel,
                               utils.read_image(filename),
                               {'content_type': utils.mime_type(filename),
                                'correlation_id': str(img_id),
                                'reply_to': queue_name},
                               opinionated=True)

    # Pubish the message
    message.publish('fanout-rpc-requests')

    # Loop until there is a response message
    message = None
    while not message:
        time.sleep(0.5)
        message = response_queue.get()

    # Ack the response message
Example #3
0
# Declare the response queue
if response_queue.declare():
    print('Response queue declared')

# Bind the response queue
if response_queue.bind('rpc-replies', queue_name):
    print('Response queue bound')

# Iterate through the images to send RPC requests for
for img_id, filename in enumerate(utils.get_images()):

    print('Sending request for image #%s: %s' % (img_id, filename))

    # Create the message
    message = rabbitpy.Message(channel,
                               utils.read_image(filename), {
                                   'content_type': utils.mime_type(filename),
                                   'correlation_id': str(img_id),
                                   'headers': {
                                       'source': 'profile',
                                       'object': 'image',
                                       'action': 'new'
                                   },
                                   'reply_to': queue_name
                               },
                               opinionated=True)

    # Pubish the message
    message.publish('headers-rpc-requests')

    # Loop until there is a response message
Example #4
0
                                      message.properties['content_type'])

    # Detect faces
    result_file = detect.faces(temp_file)

    # Build response properties including the timestamp from the first publish
    properties = {
        'app_id': 'Chapter 6 Listing 2 Consumer',
        'content_type': message.properties['content_type'],
        'correlation_id': message.properties['correlation_id'],
        'headers': {
            'first_publish': message.properties['timestamp']
        }
    }

    # The result file could just be the original image if nothing detected
    body = utils.read_image(result_file)

    # Remove the temp file
    os.unlink(temp_file)

    # Remove the result file
    os.unlink(result_file)

    # Publish the response response
    response = rabbitpy.Message(channel, body, properties, opinionated=True)
    response.publish('rpc-replies', message.properties['reply_to'])

    # Acknowledge the delivery of the RPC request message
    message.ack()