Class: EventStoreClient::GRPC::Client

Inherits:
Object
  • Object
show all
Includes:
Configuration
Defined in:
lib/event_store_client/adapters/grpc/client.rb

Instance Method Summary collapse

Methods included from Configuration

#config

Instance Method Details

#append_to_stream(stream_name, events, options: {}) ⇒ Object

Appends given events to the stream

Parameters:

  • Stream (String)

    name to append events to

  • (each: (Array)

    EventStoreClient::DeserializedEvent) list of events to publish

Returns:

  • Dry::Monads::Result::Success or Dry::Monads::Result::Failure



12
13
14
15
16
# File 'lib/event_store_client/adapters/grpc/client.rb', line 12

def append_to_stream(stream_name, events, options: {})
  Commands::Streams::Append.new.call(
    stream_name, events, options: {}
  )
end

#delete_stream(stream_name, options: {}) ⇒ Object

Softly deletes the given stream

Parameters:

  • Stream (String)

    name to delete

  • options (Hash) (defaults to: {})

    additional options to the request

Returns:

  • Dry::Monads::Result::Success or Dry::Monads::Result::Failure



23
24
25
26
27
# File 'lib/event_store_client/adapters/grpc/client.rb', line 23

def delete_stream(stream_name, options: {})
  Commands::Streams::Delete.new.call(
    stream_name, options: options
  )
end

Links given events with the given stream

Parameters:

  • Stream (String)

    name to link events to

  • (each: (Array)

    EventStoreClient::DeserializedEvent) a list of events to link

  • expected_version (Integer)

    expected number of events in the stream

Returns:

  • Dry::Monads::Result::Success or Dry::Monads::Result::Failure



76
77
78
# File 'lib/event_store_client/adapters/grpc/client.rb', line 76

def link_to(stream_name, events, options: {})
  Commands::Streams::LinkTo.new.call(stream_name, events, options: options)
end

#listen(subscription, options: {}) ⇒ Object

Runs the persistent subscription indeinitely

Parameters:

Returns:

    • Nothing, it is a blocking operation, yields the given block with event instead



85
86
87
88
89
90
91
# File 'lib/event_store_client/adapters/grpc/client.rb', line 85

def listen(subscription, options: {})
  consume_feed(subscription, options: options) do |event|
    yield event if block_given?
  end
rescue StandardError => e
  config.error_handler&.call(e)
end

#read(stream_name, options: {}) ⇒ Object

Reads a page of events from the given stream

Parameters:

  • Stream (String)

    name to read events from

  • options (Hash) (defaults to: {})

    additional options to the request

Returns:

  • Dry::Monads::Result::Success with returned events or Dry::Monads::Result::Failure



43
44
45
# File 'lib/event_store_client/adapters/grpc/client.rb', line 43

def read(stream_name, options: {})
  Commands::Streams::Read.new.call(stream_name, options: options)
end

#read_all_from_stream(stream_name, options: {}) ⇒ Object

Reads all events from the given stream

Parameters:

  • Stream (String)

    name to read events from

  • options (Hash) (defaults to: {})

    additional options to the request

Returns:

  • Dry::Monads::Result::Success with returned events or Dry::Monads::Result::Failure



52
53
54
# File 'lib/event_store_client/adapters/grpc/client.rb', line 52

def read_all_from_stream(stream_name, options: {})
  Commands::Streams::ReadAll.new.call(stream_name, options: options)
end

#subscribe_to_stream(subscription, options: {}) ⇒ Object

Creates the subscription for the given stream

Parameters:

Returns:

  • Dry::Monads::Result::Success or Dry::Monads::Result::Failure



61
62
63
64
65
66
67
68
# File 'lib/event_store_client/adapters/grpc/client.rb', line 61

def subscribe_to_stream(subscription, options: {})
  join_streams(subscription.name, subscription.observed_streams)
  Commands::PersistentSubscriptions::Create.new.call(
    subscription.stream,
    subscription.name,
    options: options
  )
end

#tombstone_stream(stream_name, options: {}) ⇒ Object

Completely removes the given stream

Parameters:

  • Stream (String)

    name to delete

  • options (Hash) (defaults to: {})

    additional options to the request

Returns:

  • Dry::Monads::Result::Success or Dry::Monads::Result::Failure



34
35
36
# File 'lib/event_store_client/adapters/grpc/client.rb', line 34

def tombstone_stream(stream_name, options: {})
  Commands::Streams::Tombstone.new.call(stream_name, options: options)
end