Creating a Publisher - messagebus/lapine GitHub Wiki
Producer classes are Ruby classes that mix in Lapine::Publisher
. They must define a #to_hash
method. Lapine defines a #to_json
and a #publish
method.
require 'lapine'
class Worker
include Lapine::Publisher
exchange 'efrafa.topic'
def initialize(action)
@action = action
end
def to_hash
{
'action' => @action
}
end
end
The exchange must already be registered by Lapine, for instance in an initializer. See Basic Configuration for more information about configuring Lapine for publishing messages.