Class: Cosmo::Publisher
- Inherits:
-
Object
- Object
- Cosmo::Publisher
- Extended by:
- Forwardable
- Defined in:
- lib/cosmo/publisher.rb,
sig/cosmo/publisher.rbs
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(subject, data, serializer: nil, **options) ⇒ Object
- #publish_batch(subject, batch, **options) ⇒ void
- #publish_job(data) ⇒ ::String
Constructor Details
Class Method Details
.instance ⇒ Publisher
13 14 15 |
# File 'lib/cosmo/publisher.rb', line 13 def self.instance @instance ||= new end |
.publish ⇒ Boolean
7 |
# File 'sig/cosmo/publisher.rbs', line 7
def self.publish: (::String subject, untyped data, ?serializer: Module?, **untyped options) -> bool
|
.publish_batch ⇒ void
This method returns an undefined value.
11 |
# File 'sig/cosmo/publisher.rbs', line 11
def self.publish_batch: (::String subject, Array[untyped] batch, **untyped options) -> void
|
.publish_job ⇒ ::String
9 |
# File 'sig/cosmo/publisher.rbs', line 9
def self.publish_job: (Job::Data data) -> ::String
|
Instance Method Details
#publish(subject, data, serializer: nil, **options) ⇒ Object
21 22 23 24 |
# File 'lib/cosmo/publisher.rb', line 21 def publish(subject, data, serializer: nil, **) payload = (serializer || Stream::Serializer).serialize(data) @client.publish(subject, payload, **) end |
#publish_batch(subject, batch, **options) ⇒ void
This method returns an undefined value.
34 35 36 |
# File 'lib/cosmo/publisher.rb', line 34 def publish_batch(subject, batch, **) batch.each { publish(subject, _1, **) } end |
#publish_job(data) ⇒ ::String
26 27 28 29 30 31 32 |
# File 'lib/cosmo/publisher.rb', line 26 def publish_job(data) subject, payload, params = data.to_args @client.publish(subject, payload, **params) data.jid rescue NATS::JetStream::Error::NoStreamResponse raise StreamNotFoundError, params[:stream].to_s end |