Class: Kiyohime::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/kiyohime/publisher.rb

Overview

A publisher can be used to publish a message to a specific function. It also has the facility to list the names of the available functions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store = nil) ⇒ Publisher

Initialises the publisher by obtaining a Redis connection



11
12
13
# File 'lib/kiyohime/publisher.rb', line 11

def initialize(store = nil)
  @store = store || Kiyohime::Stores::RedisStore.new.redis
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



8
9
10
# File 'lib/kiyohime/publisher.rb', line 8

def store
  @store
end

Instance Method Details

#publish(service, message) ⇒ Object

A message can be published to a service/function, a message can be a simple type, or at present a JSON compliant type



17
18
19
20
21
# File 'lib/kiyohime/publisher.rb', line 17

def publish(service, message)
  if store
    puts "Published message: #{message} to service: #{service}" if store.publish(service, message)
  end
end