Skip to content

Call auto-subscription to topics for subscribers that implement it#25

Merged
paradigm314 merged 7 commits intolifechurch:masterfrom
IcaliaLabs:feature/auto-subscribing-subscribers
Jun 16, 2020
Merged

Call auto-subscription to topics for subscribers that implement it#25
paradigm314 merged 7 commits intolifechurch:masterfrom
IcaliaLabs:feature/auto-subscribing-subscribers

Conversation

@vovimayhem
Copy link
Contributor

@vovimayhem vovimayhem commented Mar 13, 2020

What does this PR do?

Implements the plumbing that would enable subscribers to automatically create a subscription to a topic, if the Subscriber class implements how to do it.

This feature would be required for #17

@vovimayhem
Copy link
Contributor Author

I'll need to add a couple tests for this change, and add the documentation to use this.

@vovimayhem vovimayhem changed the title Feature/auto subscribing subscribers Subscriber auto-subscribing Mar 13, 2020
@vovimayhem
Copy link
Contributor Author

OH! I see the documentation is actually on a Github Wiki... I'll post an example of how to implement an auto_subscribe method, so it can get included in the Wiki.

@vovimayhem vovimayhem marked this pull request as ready for review March 13, 2020 06:09
@vovimayhem vovimayhem changed the title Subscriber auto-subscribing Enable auto-subscription to topics for subscribers Mar 13, 2020
@vovimayhem vovimayhem changed the title Enable auto-subscription to topics for subscribers Call auto-subscription to topics for subscribers that implement it Mar 13, 2020
@vovimayhem
Copy link
Contributor Author

vovimayhem commented Mar 13, 2020

This is a simple example of how to implement the "Auto-subscribe" method. Of course, you might implement a more complex logic if you need it:

class MyAutoSubscriber
  include Subserver::Subscriber
  subserver_options queue: 'default'

  def self.auto_subscribe
    client = Subserver::Pubsub.client
    client.topic('my-topic-name').tap do |topic|
      topic.subscription('my-topic-subscription-name') ||
      topic.subscribe('my-topic-subscription-name')
    end
  end

@vovimayhem
Copy link
Contributor Author

vovimayhem commented Mar 13, 2020

@WintheDay Please take a look at this :)

@paradigm314 paradigm314 added this to the 4.2 milestone Jun 16, 2020
@paradigm314
Copy link
Contributor

@vovimayhem Sorry it took a while to look at this. It looks great!

@paradigm314 paradigm314 merged commit c31abdc into lifechurch:master Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants