Class: Rubyists::Dapr::Client::Publisher

Inherits:
Object
  • Object
show all
Includes:
Rubyists::Dapr::Client
Defined in:
lib/dapr/client/publisher.rb

Overview

Handles publishing messages to Dapr pub/sub topics

Constant Summary collapse

Proto =

The proto class for the publish event request

::Dapr::Proto::Runtime::V1::PublishEventRequest

Constants included from Rubyists::Dapr::Client

DAPR_PORT, DAPR_STUB, DAPR_URI, Runtime

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rubyists::Dapr::Client

client, singleton, #singleton

Constructor Details

#initialize(name, serialization: :to_json) ⇒ Publisher

Initialize the publisher

Parameters:

  • name (String)

    The name of the pubsub component in Dapr

  • serialization (Symbol) (defaults to: :to_json)

    The serialization format to use. Defaults to :to_json this can be :to_json, :to_dapr, or any object that responds to :wrap. If it responds to :wrap, it will be called with the message to be sent.



24
25
26
27
# File 'lib/dapr/client/publisher.rb', line 24

def initialize(name, serialization: :to_json)
  @serialization = serialization
  @pubsub_name = name
end

Instance Attribute Details

#clientObject (readonly)

The name of the pubsub component, the client, and the serialization to use



14
15
16
# File 'lib/dapr/client/publisher.rb', line 14

def client
  @client
end

#pubsub_nameObject (readonly)

The name of the pubsub component, the client, and the serialization to use



14
15
16
# File 'lib/dapr/client/publisher.rb', line 14

def pubsub_name
  @pubsub_name
end

#serializationObject (readonly)

The name of the pubsub component, the client, and the serialization to use



14
15
16
# File 'lib/dapr/client/publisher.rb', line 14

def serialization
  @serialization
end

Instance Method Details

#publish(topic, message) ⇒ Object



29
30
31
# File 'lib/dapr/client/publisher.rb', line 29

def publish(topic, message)
  singleton.publish_event(Proto.new(pubsub_name:, topic:, data: wrap(message)))
end