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_or_event, options: {}, credentials: {}) {|EventStore::Client::Streams::AppendReq, EventStore::Client::Streams::AppendReq| ... } ⇒ Dry::Monads::Result::Success, ...

Returns monads’ Success/Failure in case whether request was performed.

Parameters:

Options Hash (options:):

  • :expected_revision (Integer)

    provide your own revision number

  • :expected_revision (String)

    provide one of next values: ‘any’, ‘no_stream’ or ‘stream_exists’

Options Hash (credentials:):

  • :username (String)

    override authentication username

  • :password (String)

    override authentication password

Yields:

  • (EventStore::Client::Streams::AppendReq, EventStore::Client::Streams::AppendReq)

    yields options and proposed message option right before sending the request. You can extend it with your own options, not covered in the default implementation. Example:

    ```ruby
    append_to_stream('some-stream', event) do |req_opts, proposed_msg_opts|
      puts req_opts.options
      puts proposed_msg_opts.proposed_message
    end
    

    “‘

Returns:

  • (Dry::Monads::Result::Success, Dry::Monads::Result::Failure, Array<Dry::Monads::Result::Success, Dry::Monads::Result::Failure>)

    Returns monads’ Success/Failure in case whether request was performed.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/event_store_client/adapters/grpc/client.rb', line 31

def append_to_stream(stream_name, events_or_event, options: {}, credentials: {}, &blk)
  if events_or_event.is_a?(Array)
    Commands::Streams::AppendMultiple.new(**credentials).call(
      stream_name, events_or_event, options: options
    )
  else
    Commands::Streams::Append.new(**credentials).call(
      stream_name, events_or_event, options: options, &blk
    )
  end
end

#cluster_info(credentials: {}) ⇒ Dry::Monads::Success, Dry::Monads::Failure

Parameters:

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

Options Hash (credentials:):

  • :username (String)
  • :password (String)

Returns:

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


269
270
271
# File 'lib/event_store_client/adapters/grpc/client.rb', line 269

def cluster_info(credentials: {})
  Commands::Gossip::ClusterInfo.new(**credentials).call
end

#delete_stream(stream_name, options: {}, credentials: {}) {|EventStore::Client::Streams::DeleteReq::Options| ... } ⇒ Dry::Monads::Success, Dry::Monads::Failure

Parameters:

  • stream_name (String)
  • options (Hash) (defaults to: {})
  • credentials (Hash) (defaults to: {})

Options Hash (options:):

  • :expected_revision (Integer, String)

    provide your own revision number. Alternatively you can provide one of next values: ‘any’, ‘no_stream’ or ‘stream_exists’.

Options Hash (credentials:):

  • :username (String)

    override authentication username

  • :password (String)

    override authentication password

Yields:

  • (EventStore::Client::Streams::DeleteReq::Options)

    yields request options right before sending the request. You can override them in your own way. Example:

    ```ruby
    delete_stream('stream_name') do |opts|
      opts.stream_identifier.stream_name = 'overridden-stream-name'
    end
    ```
    

Returns:

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


156
157
158
# File 'lib/event_store_client/adapters/grpc/client.rb', line 156

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

#hard_delete_stream(stream_name, options: {}, credentials: {}) {|EventStore::Client::Streams::TombstoneReq::Options| ... } ⇒ Dry::Monads::Success, Dry::Monads::Failure

Parameters:

  • stream_name (String)
  • options (Hash) (defaults to: {})
  • credentials (Hash) (defaults to: {})

Options Hash (options:):

  • :expected_revision (Integer, String)

    provide your own revision number. Alternatively you can provide one of next values: ‘any’, ‘no_stream’ or ‘stream_exists’.

Options Hash (credentials:):

  • :username (String)

    override authentication username

  • :password (String)

    override authentication password

Yields:

  • (EventStore::Client::Streams::TombstoneReq::Options)

    yields request options right before sending the request. You can override them in your own way. Example:

    ```ruby
    delete_stream('stream_name') do |opts|
      opts.stream_identifier.stream_name = 'overridden-stream-name'
    end
    ```
    

Returns:

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


135
136
137
# File 'lib/event_store_client/adapters/grpc/client.rb', line 135

def hard_delete_stream(stream_name, options: {}, credentials: {}, &blk)
  Commands::Streams::HardDelete.new(**credentials).call(stream_name, options: options, &blk)
end

Links event from one stream into another stream. You can later access it by providing :resolve_link_tos option when reading from a stream. If you provide an event that does not present in EventStore database yet - its data will not be appended properly to the stream, thus, making it look as a malformed event.



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/event_store_client/adapters/grpc/client.rb', line 247

def link_to(stream_name, events_or_event, options: {}, credentials: {}, &blk)
  if events_or_event.is_a?(Array)
    Commands::Streams::LinkToMultiple.new(**credentials).call(
      stream_name,
      events_or_event,
      options: options,
      &blk
    )
  else
    Commands::Streams::LinkTo.new(**credentials).call(
      stream_name,
      events_or_event,
      options: options,
      &blk
    )
  end
end

#read(stream_name, options: {}, skip_deserialization: config.skip_deserialization, skip_decryption: config.skip_decryption, credentials: {}) {|EventStore::Client::Streams::ReadReq::Options| ... } ⇒ Dry::Monads::Success, Dry::Monads::Failure

Parameters:

  • stream_name (String)
  • skip_deserialization (Boolean) (defaults to: config.skip_deserialization)
  • skip_decryption (Boolean) (defaults to: config.skip_decryption)
  • options (Hash) (defaults to: {})

    request options

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

Options Hash (options:):

  • :direction (String)

    read direction - ‘Forwards’ or ‘Backwards’

  • :from_revision. (Integer, Symbol)

    If number is provided - it is threaded as starting revision number. Alternatively you can provide :start or :end value to define a stream revision. **Use this option when stream name is a normal stream name**

  • :from_position. (Hash, Symbol)

    If hash is provided - you should supply it with :commit_position and/or :prepare_position keys. Alternatively you can provide :start or :end value to define a stream position. **Use this option when stream name is “$all”**

  • :max_count (Integer)

    max number of events to return in one response

  • :resolve_link_tos (Boolean)

    When using projections to create new events you can set whether the generated events are pointers to existing events. Setting this value to true tells EventStoreDB to return the event as well as the event linking to it.

  • :filter (Hash)

    provide it to filter events when reading from $all. You can either filter by stream name or filter by event type. Filtering can be done by using Regexp or by a string. Examples:

    ```ruby
    # Include events only from streams which names start from 'some-stream-1' and
    # 'some-stream-2'
    { filter: { stream_identifier: { prefix: ['some-stream-1', 'some-stream-2'] } } }
    
    # Include events only from streams which names end with digit
    { filter: { stream_identifier: { regex: /\d$/.to_s } } }
    
    # Include events which start from 'some-event-1' and 'some-event-2'
    { filter: { event_type: { prefix: ['some-event-1', 'some-event-2'] } } }
    
    # Include events which names end with digit
    { filter: { event_type: { regex: /\d$/.to_s } } }
    ```
    

Options Hash (credentials:):

  • :username (String)

    override authentication username

  • :password (String)

    override authentication password

Yields:

  • (EventStore::Client::Streams::ReadReq::Options)

    yields request options right before sending the request. You can extend it with your own options, not covered in the default implementation. Example:

    ```ruby
    read('$all') do |opts|
      opts.filter = EventStore::Client::Streams::ReadReq::Options::FilterOptions.new(
        { stream_identifier: { prefix: ['as'] }, count: EventStore::Client::Empty.new }
      )
    end
    

    “‘

Returns:

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


92
93
94
95
96
97
98
99
100
101
# File 'lib/event_store_client/adapters/grpc/client.rb', line 92

def read(stream_name, options: {}, skip_deserialization: config.skip_deserialization,
         skip_decryption: config.skip_decryption, credentials: {}, &blk)
  Commands::Streams::Read.new(**credentials).call(
    stream_name,
    options: options,
    skip_deserialization: skip_deserialization,
    skip_decryption: skip_decryption,
    &blk
  )
end

#read_paginated(stream_name, options: {}, credentials: {}, skip_deserialization: config.skip_deserialization, skip_decryption: config.skip_decryption, &blk) ⇒ Enumerator

Returns enumerator will yield Dry::Monads::Success or Dry::Monads::Failure on each iteration.

Returns:

  • (Enumerator)

    enumerator will yield Dry::Monads::Success or Dry::Monads::Failure on each iteration

See Also:

  • for available params


106
107
108
109
110
111
112
113
114
115
116
# File 'lib/event_store_client/adapters/grpc/client.rb', line 106

def read_paginated(stream_name, options: {}, credentials: {},
                   skip_deserialization: config.skip_deserialization,
                   skip_decryption: config.skip_decryption, &blk)
  Commands::Streams::ReadPaginated.new(**credentials).call(
    stream_name,
    options: options,
    skip_deserialization: skip_deserialization,
    skip_decryption: skip_decryption,
    &blk
  )
end

#subscribe_to_all(handler:, options: {}, credentials: {}, skip_deserialization: config.skip_deserialization, skip_decryption: config.skip_decryption, &blk) ⇒ Object

This method acts the same as #subscribe_to_stream with the only exception that it subscribes to $all stream



229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/event_store_client/adapters/grpc/client.rb', line 229

def subscribe_to_all(handler:, options: {}, credentials: {},
                     skip_deserialization: config.skip_deserialization,
                     skip_decryption: config.skip_decryption, &blk)
  Commands::Streams::Subscribe.new(**credentials).call(
    '$all',
    handler: handler,
    options: options,
    skip_deserialization: skip_deserialization,
    skip_decryption: skip_decryption,
    &blk
  )
end

#subscribe_to_stream(stream_name, handler:, options: {}, credentials: {}, skip_deserialization: config.skip_deserialization, skip_decryption: config.skip_decryption) {|EventStore::Client::Streams::ReadReq::Options| ... } ⇒ Dry::Monads::Success, Dry::Monads::Failure

Subscribe to the given stream and listens for events. Note, that it will block execution of

current stack. If you want to do it asynchronous - consider putting it out of current
thread.

Parameters:

  • stream_name (String)
  • handler (#call)

    whenever new event arrives - #call method of your handler will be called with the response passed into it

  • skip_deserialization (Boolean) (defaults to: config.skip_deserialization)
  • skip_decryption (Boolean) (defaults to: config.skip_decryption)
  • options (Hash) (defaults to: {})

    request options

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

Options Hash (options:):

  • :direction (String)

    read direction - ‘Forwards’ or ‘Backwards’

  • :from_revision. (Integer, Symbol)

    If number is provided - it is threaded as starting revision number. Alternatively you can provide :start or :end value to define a stream revision. **Use this option when stream name is a normal stream name**

  • :from_position. (Hash, Symbol)

    If hash is provided - you should supply it with :commit_position and/or :prepare_position keys. Alternatively you can provide :start or :end value to define a stream position. **Use this option when stream name is “$all”**

  • :resolve_link_tos (Boolean)

    When using projections to create new events you can set whether the generated events are pointers to existing events. Setting this value to true tells EventStoreDB to return the event as well as the event linking to it.

  • :filter (Hash)

    provide it to filter events when subscribing to $all. You can either filter by stream name or filter by event type. Filtering can be done by using Regexp or by a string. Examples:

    ```ruby
    # Include events only from streams which names start from 'some-stream-1' and
    # 'some-stream-2'
    { filter: { stream_identifier: { prefix: ['some-stream-1', 'some-stream-2'] } } }
    
    # Include events only from streams which names end with digit
    { filter: { stream_identifier: { regex: /\d$/.to_s } } }
    
    # Include events which start from 'some-event-1' and 'some-event-2'
    { filter: { event_type: { prefix: ['some-event-1', 'some-event-2'] } } }
    
    # Include events which names end with digit
    { filter: { event_type: { regex: /\d$/.to_s } } }
    ```
    

Options Hash (credentials:):

  • :username (String)

    override authentication username

  • :password (String)

    override authentication password

Yields:

  • (EventStore::Client::Streams::ReadReq::Options)

    yields request options right before sending the request. You can extend it with your own options, not covered in the default implementation. Example:

    ```ruby
    subscribe_to_stream('$all', handler: proc { |response| puts response }) do |opts|
      opts.filter = EventStore::Client::Streams::ReadReq::Options::FilterOptions.new(
        { stream_identifier: { prefix: ['as'] }, max: 100 }
      )
    end
    ```
    

Returns:

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


213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/event_store_client/adapters/grpc/client.rb', line 213

def subscribe_to_stream(stream_name, handler:, options: {}, credentials: {},
                        skip_deserialization: config.skip_deserialization,
                        skip_decryption: config.skip_decryption, &blk)
  Commands::Streams::Subscribe.new(**credentials).call(
    stream_name,
    handler: handler,
    options: options,
    skip_deserialization: skip_deserialization,
    skip_decryption: skip_decryption,
    &blk
  )
end