Configuration - ericchapman/ruby_wamp_worker GitHub Wiki

The Wamp::Worker module has a global method that exposes configuration capabilities to the design. An example of this is shown below

Wamp::Worker.configure do
  timeout 30
  redis Redis.new(url : "<some URL>")
  connection uri: 'ws://127.0.0.1:8080/ws', realm: 'realm1'
end

The parameters are defined as follows

  • timeout (default: 60): number of seconds that a requestor will wait for a response before timing out
  • redis (default: Redis.new): a Redis object or the options to pass to the instantiation of a Redis object
  • connection (default: nil): these options will be passed to the instantiation of the Wamp::Client object that executes inside the runner

Note that the Wamp::Worker object has the concept of a "name" for the worker. This allows different workers to be configured and instantiated in the same program. To take advantage of this, the configure method accepts a "name" parameter where different configurations can be created as illustrated below

Wamp::Worker.configure :worker1 do
  connection uri: 'ws://127.0.0.1:8080/ws', realm: 'realm1'
end

Wamp::Worker.configure :worker2 do
  connection uri: 'ws://127.0.0.1:8080/ws', realm: 'realm2'
end

and then the runner can be instantiated using the name

Thread.new
  runner = Wamp::Worker::Runner::Main.new :worker1
  runner.start
end

when the name is omitted, ":default" will be used. Note that the Wamp::Worker.run method supports passing a name as does the bin/wamp-worker script.

Registrations and Subscriptions

Registrations and subscriptions can either be done in the Wamp::Worker::Handler class (see Handlers) or in the configure call. See below

Wamp::Worker.configure do
  connection uri: 'ws://127.0.0.1:8080/ws', realm: 'realm1'

  register "com.example.add", MyHandler, :add 
  register "com.example.subtract", MyHandler, :subtract
  subscribe "com.example.listener", MyHandler, :listener
end

The register and subscribe methods have the following function prototypes

def register(procedure, klass, method, **options)
def subscribe(topic, klass, method, **options)
⚠️ **GitHub.com Fallback** ⚠️