-
Notifications
You must be signed in to change notification settings - Fork 598
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
auto-created topic and subscribe do not work together #696
Comments
Should it? Subscribing to a topic that doesn't exist seems like it should be an error, since that subscription would never receive a message event. Like if I try to Creating a topic when a message is published is really just a developer convenience, since the user has always given us the details we needed: "publish message x to topic y", but we were just being stubborn about making them create the topic before we let them publish. I'm not an expert with Pub/Sub patterns, though, so anyone can set me straight, and it will be easy enough to implement. |
@tmatsuo PTAL. Publishing to a non-existing topic is more dangerous than subscribing to one, in my opinion. Sending a message to a topic with no subscribers just gets dropped. I think we should either auto-create on both or neither for consistency. This came up on stack overflow with a user following the node.js getting started tutorial. Because our worker runs first and just calls subscribe, the worker will fail. Once the user runs the frontend and triggers a message, then the worker can run successfully. Of course, the message that was used to "prime" the topic is lost forever. |
If that's true, having Can you link the SO issue? |
In terms of having auto create around, I think it's useful per our lengthy discussion when we originally added the feature. However, if there's a way to go back on that decision without making the above code horribly complicated then I'm for it. |
😵 3 months ago feels like 3 years ago. Here's the original discussion and the PR. I see that @tmatsuo brought up the concern initially:
And your response:
At that time, I believe you were referring to: pubsub.createTopic('new-topic', function(err, topic) {
topic.publish({ data: 'message' }, function(err) {});
}); And what we have now: pubsub.topic('new-topic').publish({ data: 'message' }, function(err) {}); While the first example is more steps, it isn't a common practice & would result in a dropped message, so why try to create a good experience to cater to a bad idea? If the message continued to exist until a subscriber picked it up, then it would make sense to make this a one-liner. Since that's not the case, I think it would be best to revert back to the old behavior and remove I think this whole thing about wanting to make the code easier is mostly to solve the problem of: "My same script that creates the topic also publishes and subscribes to the topic" - but is this a rational use in the wild, or are topics typically created one place and then used in another? A comparison here could be uploading a file to a bucket that doesn't exist with Storage. It will fail since I didn't create the bucket first. Assuming I'm running a website that lets users upload files, which I store in gcs, I wouldn't lazily create the bucket; I would have planned ahead and made the bucket, given it proper metadata/caching/privacy settings, etc, then used it in my server script. If I'm running a production app with Pub/Sub, I would think a similar approach would be taken. In the case of the tutorial code, it would get a little more complex. It might be better to have a step where users create a topic with the Developer's Console UI, then put the name of it in the config file. |
I agree, this an unfortunate situation. There is also the case that this code:
Isn't safely idempotent, you'd have to specifically handle the case where the topic already exists, pushing more logic into user-space code, something like:
In python, it's much more succinct (then again, python favors imperative over callbacks):
It's absolutely rational in the wild. Subscriptions more so than topics, but still equally valid. For example reliable task scheduling makes each instance create a new subscription. We're also working on a task queueing library for python that allows you to define arbitrary queues that map to topics. @tmatsuo what do you think? I know you originally told me that the "intent" was to have topics and subscriptions pre-created, but I just don't think that's how things are being used at this point.
When the original issue was raised, the UI didn't exist. This could be an option, but it's still onerous to make the users manually do something that should be both possible and simple within the code. |
Some applications are OK with fixed topics and subscriptions. Some applications want to create resources (especially subscriptions) dynamically. I still have a concern that topic's autocreate option is dangerous because it will lead message loss. How about to have a simple check script which runs on the application startup time, or even on the deploy time, instead of using the "autocreate" feature? I think requirements differ depending on the application and they are different enough for us to be uncomfortable with the single "autocreate" mechanism. The check script may actually create the required resources if it makes sense. Also the check script can decide what to do upon failures (just die, report via e-mail, etc). |
I'm opposed to adding an additional step to what is already a very involved tutorial, @stephenplusplus, do you have an recommendations of a simple, reliable, and clear way to do this? One way I can think of is to add a
Or If I can find a simple, intuitive way to create or use an existing topic, then the rest of the tutorial code could remain mostly unchanged. |
Is there an easy way for a nodejs app to automatically run some code on startup? You don't have to change steps in the tutorial. You only need to add some code in the repo. |
Not exactly simple, but more clear maybe. I still would recommend using the UI for the tutorial to create a topic. I would prefer to avoid adding functions or modifying behavior just for our Pub/Sub api. If I'm writing an app, I expect to handle basic things like tracking what I create and re-use. I'm still not clear on why one would publish a message to a topic that doesn't exist. What I've learned here is that's essentially just To go further, I also don't understand how a user gets into a situation where they would publish to a topic that they think exists. The developer should be handling errors, and if they tried to do that, they would get one. |
I will concede the point and modify the tutorial to instruct the user to create the topic beforehand. I still think that this library should provide a easy, idiomatic way to get or create a topic. |
I want this library to be useful as well, but not at the expense of catering to error-prone/incorrect architectures. Our code will be difficult to maintain as we have to drag along legacy support for use cases that we don't understand or recommend. Where we're at here:
On point 2, in other places in our library, we usually have |
I definitely think we should add I'm personally for 3, but I can see the other side of the argument against it. |
We should probably have a Notice |
Re: Yup, it's still not working. Just a note, not only Pub/Sub, but also all APIs which are running on the new infrastructure don't support |
FYI this commit fixes pubsub in our getting started tutorial. Hopefully nothing we change here will break that. |
If I'm playing the "I'm a lazy developer card", I have a feeling that my code would want to look something like....
Since we're all callback driven, the imperative existence checks and creates kind of suck when you're just trying to get from one step to another (however they're nice when you want to continuously poll for messages and do work whenever a new one comes in). Given the discussion above, what would the code look like to do this if the "auto-magically create a topic" stuff went away? @stephenplusplus |
Pretty close to https://gist.github.com/stephenplusplus/04594f5026dec99bf896. I'm only saying why would someone want to subscribe to a topic that doesn't exist? This reads to me as "woops! I must have specified the wrong topic name, let me try again", not "I meant for you to create this topic so I can sit here and wait for nothing to happen". |
🤖 I have created a release \*beep\* \*boop\* --- ### [6.2.5](https://www.github.com/googleapis/nodejs-translate/compare/v6.2.4...v6.2.5) (2021-07-12) ### Bug Fixes * **deps:** google-gax v2.17.1 ([#695](https://www.github.com/googleapis/nodejs-translate/issues/695)) ([20bac38](https://www.github.com/googleapis/nodejs-translate/commit/20bac38c89480e4e221419bab13e3f10d626df6c)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
topic.subscribe()
on a new topic fails. See this code:Will fail with a
404: Resource not found (resource=my-topic)
,However, this code works:
Seems
subscribe
doesn't callcreateTopic
if it doesn't exist.The text was updated successfully, but these errors were encountered: