question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Publishing to and Subscribing from multiple Pub/Sub projects is extremely difficult

See original GitHub issue

Is your feature request related to a problem? Please describe. We publish and subscribe to/from topics and subscriptions in other projects, and the libraries do not support this at all well, especially with the Pub/Sub emulator complication.

Please have a look at how we did it, to get a sense of how difficult it was to meet the basic requirement of being able to specify a project for a topic to publish to, or a subscription to pull from: https://github.com/ONSdigital/ssdc-rm-caseprocessor/pull/50

Describe the solution you’d like It would be ideal if there was simply an optional “project ID” parameter on the PubSubInboundChannelAdapter class constructor, in addition to the subscription name. For example:

new PubSubInboundChannelAdapter(pubSubTemplate, subscriptionName, projectId);

Likewise, it would be ideal if there was an optional “project name” parameter PubSubTemplate.publish() function. For example:

pubSubTemplate.publish(topic, message, projectId);

This would make it very trivial to be able to publish to a topic in a different project, or subscribe to a subscription in a different project.

Describe alternatives you’ve considered We have written a lot of config to work around this, as you can see here: https://github.com/ONSdigital/ssdc-rm-caseprocessor/pull/50

In my opinion, you shouldn’t have to write so much code just to specify the project.

Additional context There’s not a lot of documentation around this. I had to dig in the source code to arrive at the solution, which in fact is not complete in the PR I attached… we had to do extra stuff because the GcpPubSubProperties and PubsubTransportConfig behaved in a really unexpected way in production. We ended up bringing more and more of the GcpPubSubAutoConfiguration class into our code, to make it do what we need.

Our requirement is fairly simple: to be able to do integration tests with the pubsub emulator, to be able to run on our local machine with the pubsub emulator, and then to be able to deploy to GCP with very similar code… except we’ve ended up with a lot of code having to be in our “prod” codebase just for testing, which is really not ideal. It should be easier.

We appreciate the help with this. There’s not a lot of stuff in the docs or in the wider community about how to achieve what we need. I found just 1 (one) single stackoverflow post about this: https://stackoverflow.com/questions/61495154/how-to-subscribe-to-multiple-google-pubsub-projects-in-spring-gcp

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
meltsufincommented, Aug 19, 2021

@NickGrantONS I’m glad the suggestion worked well for you! I’m in favor of making improvements to the documentation, but I’m not sure about the proposal to significantly expand the public API of PubSubTemplate. This can potentially have the unintended consequence of making it more confusing for a lot of users. Note that the existing methods already point out the FQN support in the javadoc. We can probably do more in the reference documentation, however.

0reactions
NickGrantXcommented, Aug 19, 2021

@meltsufin we have changed our project to use fully qualified topics & subscriptions, when they are in another project, and it works very well. It’s cut down the complexity a whole lot: https://github.com/ONSdigital/ssdc-rm-caseprocessor/pull/56

However, I think the interface could be a lot clearer so that it’s obvious that project can be specified. The line in the documentation you referred me to was very easy to miss.

I’ve sent a pull request with a suggested improvement, which would allow developers to more easily understand that a project can be supplied as either ProjectSubscriptionName or ProjectTopicName.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building a one-to-many Pub/Sub system - Google Cloud
Start three independent applications: one publisher and two subscribers. Tutorial setup. Set up your Google Cloud project and Pub/Sub topic and subscriptions.
Read more >
Can I use Google Cloud Pub/Sub across ... - Stack Overflow
To publish to a Pub/Sub topic from another project you should grant the right permissions for it's service account in the destination project....
Read more >
Publishing to multiple topics and subscribing to ... - GitHub
Just to round this issue out, it's possible to publish/subscribe to a different project's resources at a lower level than Spring Integration -- ......
Read more >
Everything You Need To Know About Publish/Subscribe
Synchronous point-to-point communication between the two endpoints is the best solution for media streaming. Pub/Sub is not suitable for ...
Read more >
Publish And Subscribe Message Operation: the big hope for ...
Google Cloud Pub/Sub is an asynchronous messaging carrier-based product that has relied on many Google products.GCP Pub-Sub in details.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found