Class: EventStoreClient::GRPC::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.

Parameters:



11
12
13
# File 'lib/event_store_client/adapters/grpc/client.rb', line 11

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/event_store_client/adapters/grpc/client.rb', line 8

def config
  @config
end

Instance Method Details

#append_to_stream(stream_name, events_or_event, options: {}, credentials: {}) {|EventStore::Client::Streams::AppendReq, EventStore::Client::Streams::AppendReq| ... } ⇒ EventStore::Client::Streams::AppendResp+

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:

Raises:



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/event_store_client/adapters/grpc/client.rb', line 36

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

#cluster_info(credentials: {}) ⇒ EventStore::Client::Gossip::ClusterInfo

Parameters:

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

Options Hash (credentials:):

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

Returns:



282
283
284
# File 'lib/event_store_client/adapters/grpc/client.rb', line 282

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

#delete_stream(stream_name, options: {}, credentials: {}) {|EventStore::Client::Streams::DeleteReq::Options| ... } ⇒ EventStore::Client::Streams::DeleteResp

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:

Raises:



167
168
169
170
171
# File 'lib/event_store_client/adapters/grpc/client.rb', line 167

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

#hard_delete_stream(stream_name, options: {}, credentials: {}) {|EventStore::Client::Streams::TombstoneReq::Options| ... } ⇒ EventStore::Client::Streams::DeleteResp

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:

Raises:



143
144
145
146
147
# File 'lib/event_store_client/adapters/grpc/client.rb', line 143

def hard_delete_stream(stream_name, options: {}, credentials: {}, &blk)
  Commands::Streams::HardDelete.
    new(config: config, **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.



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/event_store_client/adapters/grpc/client.rb', line 260

def link_to(stream_name, events_or_event, options: {}, credentials: {}, &blk)
  if events_or_event.is_a?(Array)
    Commands::Streams::LinkToMultiple.new(config: config, **credentials).call(
      stream_name,
      events_or_event,
      options: options,
      &blk
    )
  else
    Commands::Streams::LinkTo.new(config: config, **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| ... } ⇒ Array<EventStoreClient::DeserializedEvent>, Array<EventStore::Client::Streams::ReadResp>

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:

Raises:



98
99
100
101
102
103
104
105
106
107
# File 'lib/event_store_client/adapters/grpc/client.rb', line 98

def read(stream_name, options: {}, skip_deserialization: config.skip_deserialization,
         skip_decryption: config.skip_decryption, credentials: {}, &blk)
  Commands::Streams::Read.new(config: config, **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

EventStore::Client::Streams::ReadResp on each iteration depending on ‘:skip_deserialization` argument value

Returns:

  • (Enumerator)

    enumerator will yield EventStoreClient::DeserializedEvent or

See Also:

  • for available params


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/event_store_client/adapters/grpc/client.rb', line 113

def read_paginated(stream_name, options: {}, credentials: {},
                   skip_deserialization: config.skip_deserialization,
                   skip_decryption: config.skip_decryption, &blk)
  Commands::Streams::ReadPaginated.new(config: config, **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



242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/event_store_client/adapters/grpc/client.rb', line 242

def subscribe_to_all(handler:, options: {}, credentials: {},
                     skip_deserialization: config.skip_deserialization,
                     skip_decryption: config.skip_decryption, &blk)
  Commands::Streams::Subscribe.new(config: config, **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| ... } ⇒ void

This method returns an undefined value.

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
    ```
    


226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/event_store_client/adapters/grpc/client.rb', line 226

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