Class: EventStoreClient::GRPC::Commands::PersistentSubscriptions::Create

Inherits:
Command
  • Object
show all
Defined in:
lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/create.rb

Instance Method Summary collapse

Methods inherited from Command

inherited, #metadata

Methods included from Configuration

#config

Instance Method Details

#call(stream, group, options: {}) ⇒ Dry::Monads::Result::Success, Dry::Monads::Result::Failure

Creates persistent subscription in a given group

Parameters:

  • name (String)

    of the stream to subscribe

  • name (String)

    of the subscription group

  • options (Hash) (defaults to: {})
    • additional settings to be set on subscription.

    Refer to SettingsSchema for detailed attributes allowed

Returns:

  • (Dry::Monads::Result::Success, Dry::Monads::Result::Failure)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/create.rb', line 25

def call(stream, group, options: {})
  schema = SettingsSchema.call(options)
  return Failure(schema.errors) if schema.failure?
  opts =
    {
      stream_identifier: {
        streamName: stream
      },
      group_name: group,
      settings: schema.to_h
    }

  service.create(request.new(options: opts), metadata: )
  Success()
rescue ::GRPC::AlreadyExists
  Failure(:conflict)
end