forked from tjwp/dapr-ruby-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.rb
25 lines (19 loc) · 918 Bytes
/
example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true
require 'dapr/proto/runtime/v1/dapr_services_pb'
port = ENV.fetch('DAPR_GRPC_PORT', '5001')
dapr_uri = "localhost:#{port}"
client = Dapr::Proto::Runtime::V1::Dapr::Stub.new(dapr_uri, :this_channel_is_insecure)
client.publish_event(Dapr::Proto::Runtime::V1::PublishEventRequest.new(pubsub_name: 'pubsub', topic: 'sith',
data: 'lala'))
puts('Published')
key = 'mykey'
store_name = 'statestore'
state = Dapr::Proto::Common::V1::StateItem.new(key:, value: 'my state')
req = Dapr::Proto::Runtime::V1::SaveStateRequest.new(store_name:, states: [state])
client.save_state(req)
puts('Saved!')
resp = client.get_state(Dapr::Proto::Runtime::V1::GetStateRequest.new(store_name:, key:))
puts('Got state!')
puts(resp)
client.delete_state(Dapr::Proto::Runtime::V1::DeleteStateRequest.new(store_name:, key:))
puts('Deleted!')