Readme.adoc in dapr-0.1.17 vs Readme.adoc in dapr-0.1.18

- old
+ new

@@ -45,9 +45,31 @@ ---- <1> Set the Dapr gRPC port to the Dapr runtime port. (This is automatically set in kubernetes environments) <2> Create a new publisher for the `pubsub-name` pubsub component. This component must be defined in the Dapr runtime. <3> Publish a message to the `topic-name` topic. +=== Subscribe to topics + +Subscriptions in Dapr work a little different than you may be used to. Instead of subscribing to a topic +then looping through consumed messages, you define a fully-fledged service that Dapr will +send each message to in the topic(s) that you specify. This unique appreach allows you to +focus on the business logic of your service, rather than the plumbing of message consumption. + +[source,ruby] +---- +require 'dapr/service/subscriber' +handler = ->(event) { puts "Got event: #{event}" } <1> +pubsub_name: 'pubsub' <2> +sub = Rubyists::Dapr::Service::Subscriber.new(pubsub_name:, topics: 'TOPIC-A', handler: handler) <3> +sub.start! <4> +---- +<1> Define a handler that will be called for each message received. `event` will be a `CloudEvents::Event` instance. +<2> The name of the Dapr pubsub component this subscriber will utilize. +<3> Create a new subscriber for the `pubsub` pubsub component, subscribing to the `TOPIC-A` topic. +<4> Start the subscriber. This will block the current thread and call the handler for each message received. + +TIP:: Multiple topics can be subscribed to simultaneously by passing an array of topic names to the `topics` argument. + == Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to https://rubygems.org[rubygems.org].