Class: Pulsar::Producer

Inherits:
Object
  • Object
show all
Defined in:
lib/pulsar/producer.rb

Overview

Public producer API for sending messages to one Pulsar topic.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic:, impl: nil) ⇒ Producer

Returns a new instance of Producer.



8
9
10
11
12
# File 'lib/pulsar/producer.rb', line 8

def initialize(topic:, impl: nil)
  @topic = String(topic)
  @impl = impl
  @closed = false
end

Instance Attribute Details

#topicObject (readonly)

Returns the value of attribute topic.



6
7
8
# File 'lib/pulsar/producer.rb', line 6

def topic
  @topic
end

Instance Method Details

#closeObject



21
22
23
24
25
26
27
# File 'lib/pulsar/producer.rb', line 21

def close
  return if closed?

  @impl&.close
  @closed = true
  nil
end

#closed?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/pulsar/producer.rb', line 29

def closed?
  @closed
end

#send(payload, properties: {}, key: nil, event_time: nil, timeout: nil) ⇒ Object



14
15
16
17
18
19
# File 'lib/pulsar/producer.rb', line 14

def send(payload, properties: {}, key: nil, event_time: nil, timeout: nil)
  ensure_open!
  raise UnsupportedFeatureError, 'producer send is not implemented yet' unless @impl

  @impl.send(payload, properties: properties, key: key, event_time: event_time, timeout: timeout)
end