Class: Dor::Event::Client::CreateOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/event/client/create_operation.rb

Overview

Create an Event

Instance Method Summary collapse

Constructor Details

#initialize(channel:) ⇒ CreateOperation

Returns a new instance of CreateOperation.



8
9
10
# File 'lib/dor/event/client/create_operation.rb', line 8

def initialize(channel:)
  @channel = channel
end

Instance Method Details

#create(druid:, type:, data:) ⇒ Boolean

Returns true if successful.

Parameters:

  • druid (String)

    object identifier

  • type (String)

    a type for the event, e.g., publish, shelve

  • data (Hash)

    an unstructured hash of event data

Returns:

  • (Boolean)

    true if successful



16
17
18
19
20
21
# File 'lib/dor/event/client/create_operation.rb', line 16

def create(druid:, type:, data:)
  message = { druid: druid, event_type: type, data: data }
  channel.topic('sdr.objects.event').publish(message.to_json, routing_key: type)

  true
end