Class: ZooStream::KinesisPublisher

Inherits:
Object
  • Object
show all
Defined in:
lib/zoo_stream/kinesis_publisher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream_name: ENV.fetch("ZOO_STREAM_KINESIS_STREAM_NAME"), client: Aws::Kinesis::Client.new) ⇒ KinesisPublisher

Returns a new instance of KinesisPublisher.



7
8
9
10
# File 'lib/zoo_stream/kinesis_publisher.rb', line 7

def initialize(stream_name: ENV.fetch("ZOO_STREAM_KINESIS_STREAM_NAME"), client: Aws::Kinesis::Client.new)
  @stream_name = stream_name
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/zoo_stream/kinesis_publisher.rb', line 5

def client
  @client
end

#stream_nameObject (readonly)

Returns the value of attribute stream_name.



5
6
7
# File 'lib/zoo_stream/kinesis_publisher.rb', line 5

def stream_name
  @stream_name
end

Instance Method Details

#publish(event, shard_by: nil) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
# File 'lib/zoo_stream/kinesis_publisher.rb', line 12

def publish(event, shard_by: nil)
  raise ArgumentError, "Must specify shard_by" unless shard_by

  client.put_record(
    stream_name: stream_name,
    partition_key: shard_by,
    data: event.to_json
  )
end