Skip to content

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

Merged
paradigm314 merged 7 commits into
lifechurch: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 into
lifechurch:masterfrom
IcaliaLabs:feature/auto-subscribing-subscribers

Conversation

@vovimayhem

@vovimayhem vovimayhem commented Mar 13, 2020

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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

vovimayhem commented Mar 13, 2020

Copy link
Copy Markdown
Contributor Author

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

vovimayhem commented Mar 13, 2020

Copy link
Copy Markdown
Contributor Author

@WintheDay Please take a look at this :)

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

Copy link
Copy Markdown
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