def process_service_queue_message(metadata, payload)

      service_to_reply_to = metadata.reply_to
      message_replying_to = metadata.message_id
      this_message_id = AlchemyFlux::Service.generateUUID()
      delivery_tag = metadata.delivery_tag

      operation = proc {
        @processing_messages += 1
        begin
          response = @service_fn.call(payload)
          {
            'status_code' => response['status_code'] || 200,
            'body'        => response['body']        || "",
            'headers'     => response['headers']     || {}
          }
        rescue AlchemyFlux::NAckError => e
          AlchemyFlux::NAckError
        rescue Exception => e
          e
        end
      }

      callback = proc { |result|

        if result == AlchemyFlux::NAckError
          @service_queue.reject(delivery_tag)
        elsif result.is_a?(Exception)
          # if there is an unhandled exception from the service,
          # raise it to force exit and container management can spin up a new one
          raise result
        else
          #if there is a service to reply to then reply, else ignore

          if service_to_reply_to
            send_message(@channel.default_exchange, service_to_reply_to, result, {
              :message_id     => this_message_id,
              :correlation_id => message_replying_to,
              :type           =>    'http_response'
            })
          end

          @processing_messages -= 1
          @service_queue.acknowledge(delivery_tag)
        end
      }

      EventMachine.defer(operation, callback)
    end
def process_service_queue_message(metadata, payload)

      service_to_reply_to = metadata.reply_to
      message_replying_to = metadata.message_id
      this_message_id = AlchemyFlux::Service.generateUUID()
      delivery_tag = metadata.delivery_tag

      operation = proc {
        @processing_messages += 1
        begin
          response = @service_fn.call(payload)
          {
            'status_code' => response['status_code'] || 200,
            'body'        => response['body']        || "",
            'headers'     => response['headers']     || {}
          }
        rescue AlchemyFlux::NAckError => e
          AlchemyFlux::NAckError
        rescue Exception => e
          e
        end
      }

      callback = proc { |result|

        if result == AlchemyFlux::NAckError
          @service_queue.reject(delivery_tag)
        elsif result.is_a?(Exception)
          # if there is an unhandled exception from the service,
          # raise it to force exit and container management can spin up a new one
          raise result
        else
          #if there is a service to reply to then reply, else ignore

          if service_to_reply_to
            send_message(@channel.default_exchange, service_to_reply_to, result, {
              :message_id     => this_message_id,
              :correlation_id => message_replying_to,
              :type           =>    'http_response'
            })
          end

          @processing_messages -= 1
          @service_queue.acknowledge(delivery_tag)
        end
      }

      EventMachine.defer(operation, callback)
    end
RECIEVING MESSAGES
 process messages on the service queue