This repository has been archived by the owner on Mar 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get google pubsub working I think I can't test locally cause google e…
…mulator won't play nicely with local dev
- Loading branch information
Showing
9 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api | ||
class PubsubMessagesController < ApplicationController | ||
skip_before_action :verify_authenticity_token, only: :create | ||
|
||
def create | ||
Rails.logger.info create_params | ||
Rails.logger.info decoded_message | ||
head :no_content | ||
end | ||
|
||
private | ||
|
||
def decoded_message | ||
Base64.decode64(create_params[:message][:data]) | ||
end | ||
|
||
def create_params | ||
params.permit(:subscription, message: %i[message_id data]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
namespace :pubsub do | ||
desc 'Create the Pub/Sub Subscription if it does not already exist' | ||
task createSub: :environment do | ||
require 'google/cloud/pubsub' | ||
|
||
pubsub = Google::Cloud::Pubsub.new | ||
topic = pubsub.topic ENV.fetch('PUBSUB_TOPIC') | ||
endpoint = Rails.application.routes.url_helpers.api_pubsub_messages_url(host: ENV.fetch('APPLICATION_BASE_URL')) | ||
|
||
subscription_name = ENV.fetch('PUBSUB_SUB_NAME') | ||
|
||
sub = topic.subscription subscription_name | ||
|
||
if sub.present? | ||
sub.endpoint = endpoint | ||
else | ||
topic.subscribe subscription_name, endpoint: endpoint | ||
end | ||
end | ||
end |