class EventStoreClient::GRPC::Commands::PersistentSubscriptions::Create

Public Instance Methods

call(stream, group, options: {}) click to toggle source

Creates persistent subscription in a given group @param [String] name of the stream to subscribe @param [String] name of the subscription group @param [Hash] options - additional settings to be set on subscription.

Refer to SettingsSchema for detailed attributes allowed

@return [Dry::Monads::Result::Success, Dry::Monads::Result::Failure]

# 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: metadata)
  Success()
rescue ::GRPC::AlreadyExists
  Failure(:conflict)
end