-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Pubsub flexible sample #592
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
Conversation
* Updated timeout for PubSubPush
- changed com/example/appengine/pubsub to com/example/flexible/pubsub - added Apache License - removed unnecessary dependencies
@jabubake Circle failed :( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, it's looking great. I commented on a few things.
- Style check failed in CircleCI
- The sample is missing tests.
try { | ||
messageRepository.save(message); | ||
// 200, 201, 204, 102 status codes are interpreted as success by the Pub/Sub system | ||
resp.setStatus(200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
200 -> HttpServletResponse.SC_OK
// 200, 201, 204, 102 status codes are interpreted as success by the Pub/Sub system | ||
resp.setStatus(200); | ||
} catch (Exception e) { | ||
resp.setStatus(500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
500 -> HttpServletResponse.SC_INTERNAL_SERVER_ERROR
|
||
# [START env_variables] | ||
env_variables: | ||
PUBSUB_TOPIC: test-topic-1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values should reflect the README for this sample.
export PUBSUB_TOPIC=
export PUBSUB_VERIFICATION_TOKEN=
export PUBSUB_SUBSCRIPTION_ID=
try (SubscriptionAdminClient subscriberAdminClient = SubscriptionAdminClient.create()) { | ||
try { | ||
subscriberAdminClient.createSubscription( | ||
subscriptionName, getTopicName(topicId), pushConfig, 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the '3' represent?
flexible/pubsub/README.md
Outdated
## Run | ||
|
||
Set the following environment variables and run using shown Maven command. You can then | ||
direct your browser to `http://localhost:8080/` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double space next to "browser to[SPACE][SPACE]"
private static final PubSubService INSTANCE; | ||
|
||
static { | ||
System.out.println("instance"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line necessary?
private static class LazyInit { | ||
private static final PubSubService INSTANCE; | ||
|
||
static { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading into this Lazy initialization singleton pattern. I wonder if there's a more readable solution? This wasn't clear during my first pass.
flexible/pubsub/pom.xml
Outdated
@@ -0,0 +1,114 @@ | |||
<!-- | |||
Copyright 2016 Google Inc. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New sample change year to 2016.
// Get Message saved in Datastore | ||
Datastore datastore = getDatastoreInstance(); | ||
Query<Entity> query = | ||
Query.newEntityQueryBuilder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should fit in the previous line.
* @param endpoint push endpoint URL | ||
* @throws Exception | ||
*/ | ||
private void addPushEndPoint(String topicId, String subscriptionId, String endpoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method wasn't easy to read. Can you make this method be more descriptive?
Codecov Report
@@ Coverage Diff @@
## master #592 +/- ##
=========================================
Coverage 55.84% 55.84%
Complexity 202 202
=========================================
Files 74 74
Lines 2052 2052
Branches 131 131
=========================================
Hits 1146 1146
Misses 874 874
Partials 32 32 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! I have a few minor nits.
flexible/pubsub/README.md
Outdated
|
||
## Deploy | ||
|
||
Update the environment variables `PUBSUB_TOPIC` and `PUBSUB_VERIFICATION_TOKEN` in `app.yaml`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provide a link to the app.yaml or a full path. src/main/appengine/app.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
<%= PubSubHome.getReceivedMessages() %> | ||
</table> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -0,0 +1,21 @@ | |||
<%@ page import="com.example.flexible.pubsub.PubSubHome" %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I noticed is, I had to refresh the page to see an updated list of messages. What do you think about adding an auto-refresh every 10 seconds or so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
} | ||
|
||
// ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to show that it was an incomplete class but it seems useless, removed.
flexible/pubsub/pom.xml
Outdated
</parent> | ||
|
||
<properties> | ||
<appengine.maven.plugin>1.0.0</appengine.maven.plugin> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure this will be auto-updated once merged, but this version has updated to 1.3.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, done.
* | ||
* @return html representation of messages (one per row) | ||
*/ | ||
public static String getReceivedMessages() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaner solution 👍
*/ | ||
List<Message> retrieve(int limit); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean up whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
</plugins> | ||
</build> | ||
</project> | ||
<!-- [END project] --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
flexible/pubsub/README.md
Outdated
|
||
## Setup | ||
|
||
Make sure `gcloud` is installed and authenticated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a link to Cloud SDK https://cloud.google.com/sdk/docs/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
flexible/pubsub/README.md
Outdated
gcloud beta pubsub topics create <your-topic-name> | ||
``` | ||
|
||
Create a subscription, which includes specifying the endpoint to which the Pub/Sub server should send requests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change this to:
Create a push subscription, to send pushed messages to a Google Cloud Project URL such as https://<your-project-id>.appspot.com/
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. That does sound better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
…3.0 (#592) [](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [com.google.cloud:libraries-bom](https://cloud.google.com/java/docs/bom) ([source](https://togithub.com/GoogleCloudPlatform/cloud-opensource-java)) | `25.2.0` -> `25.3.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-notification).
Flex pubsub push endpoint sample with Datastore persistence.
Tests : TODO (given we're consolidating the flex apps for testing, removed the existing ones for now for this sample)