[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit - FR: realtime event listener for RTDB (#229) #245

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

johndelavega
Copy link

Here's a pull request against dev

see cmd/listen/main.go for working simple test client app

To run the test app, edit main.go for credential json file location "edit 1." and db url "edit 2."
then from command line terminal, cd to cmd/listen
go run . init - creates snapshot user1/path1/key1:"init" for listener testing
go run . - starts listening
start a new command line terminal, cd to cmd/listen
go run . hey - this will trigger an event and should show up from other cmd line listener

Here's the gist of the code:

  iter, err := ref.Listen(ctx)
  
  defer iter.Stop()
  
  go func() {
    for {
      event, err := iter.Next()

      if err != nil {
        break
      }
    }
  }()

FR #229

@hiranya911
Copy link
Contributor

Thanks @johndelavega. The general shape of things look good. However the SSE sessions will die after an hour, when the underlying credential becomes invalid. You will need a way to reconnect when this happens. Also try to use the APIs in the json package as much as possible to parse SSE data.

@johndelavega
Copy link
Author

Thanks for the feedback. Will work on the fix to reconnect. Will use json package for the SSE data parsing as that should make the code more resilient. Actually had plan to do that, so it was great seeing that feedback :)

@johndelavega
Copy link
Author

Here's a fix for the timeout reconnection.

The code is tested and continued running for over 2 days.

The tested use case is similar to if we have a client-go SDK used for an IoT device or installed app using "authorized_user" JSON credential file,
like this: refresh_token.json

The JSON file is created from Google APIs Credential OAuth 2.0 Client IDs using Type: Other

This tool create-refresh-token can be used to create the JSON file.

This admin SDK can also be used as a client SDK, similar to Node.js SDK

@johndelavega
Copy link
Author

Updated to use json package APIs for parsing SSE data.

This firebase-admin-go SDK can be used as firebase-client-go SDK using refresh_token "authorized_user" credential JSON file.

db/event_ref.go Outdated

var snapshotMap map[string]interface{}

err := json.Unmarshal([]byte(s[6:]), &snapshotMap)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to comment why you've used a constant here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've added comments from a recent commit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thatreguy I think you need to sign a CLA https://cla.developers.google.com/

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

 rebased branch jd-event-listener with upstream/master 'Bumped version to 3.9.0 ...'
 removed branch dev
@smoya
Copy link
smoya commented Oct 6, 2019

Any update on this?

@joseph-grabinger
Copy link

Any updates on this ?
Got the Event Listeners working thanks to @johndelavega github repo.
Only issue I find is that the event is only triggered when I do manual changes from the firebase console.
However the event is NOT triggered when I change data from another app (flutter), nor is it triggered when I update data via the Firebase Database REST API.

@iamkhalidbashir
Copy link

I think they are not going to work on this, sad.

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.

7 participants