Rest API Usage

REST API

The only way to communicate with the AllQServer is through the AllQClient.

By default, the AllQClient offers a RESTful API for communicating with the AllQServer. This HTTP API is configurable via environment variables.

HTTP_SERVER_PORT = 8090 (default)

You application will call into this local http server with JSON and standard REST API calls.

How do I use AllQ now?

The simplest way is to use the REST API provided by the AllQClient.

The AllQClient is running a simple http server on localhost. This REST API is defined here:

AllQueue Rest API

Alternately, you can use a REST API library from your language of choice, and simply use the defined API above. In the example below, we will use the Ruby AllQ gem.

Example

gem install allq_rest

Here is a simple ruby example that will put and get items from your server. This gem is just a thin wrapper around the REST API.

You must run this ON a machine that has the AllQClient installed. The REST API client assumes localhost:8090.

require 'allq_rest'
require 'base64'

base_client = Allq::ApiClient.new(Allq::Configuration.new)
@worker_client = Allq::ActionsApi.new(base_client)
@admin_client = Allq::AdminApi.new(base_client)

def done(job)
 @worker_client.job_delete(job.id)
end

def stats
  @admin_client.stats_get
end

def put_job(tube_name, data)
  job = build_new_job(data, { tube_name: tube_name})
  @worker_client.job_post(job)
end

def get_job(tube_name)
  @worker_client.job_get(tube_name)
end

def build_new_job(data, options)
  ttl = options[:ttl] || 600
  tube_name = options[:tube_name] || 'default'
  delay = options[:delay] || 0
  parent_id = options[:parent_id]

  new_job = Allq::NewJob.new(tube: tube_name,
                         body: data,
                         ttl: ttl,
                         delay: delay,
                         priority: 5,
                         parent_id: parent_id)
  new_job
end

# Put job on queue
put_job("my_tube_name", "Some data I want to push to queue")
# Get job off queue
job = get_job("my_tube_name")
# Output data (allq_client gem base64 encodes body)
puts Base64.decode64(job.body)
# Mark job as done
done(job)

# Example of stats from server
puts "Stats:", stats

Save this file as test.rb and simply run it via:

ruby test.rb

Last updated

Was this helpful?