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

Can't get Pub/Sub subscription to initialize #459

Open
sgammon opened this issue Jul 22, 2021 · 12 comments
Open

Can't get Pub/Sub subscription to initialize #459

sgammon opened this issue Jul 22, 2021 · 12 comments

Comments

@sgammon
Copy link

sgammon commented Jul 22, 2021

Hey there Micronaut authors,

I tried to setup a Pub/Sub subscriber in Micronaut, but I'm having trouble getting it to start up and receive a signal from the subscription. Basically, here is my code (in Kotlin):

package com.example

import io.micronaut.gcp.pubsub.annotation.PubSubListener
import io.micronaut.gcp.pubsub.annotation.Subscription
import io.micronaut.gcp.pubsub.exception.PubSubMessageReceiverException
import io.micronaut.gcp.pubsub.exception.PubSubMessageReceiverExceptionHandler
import io.micronaut.messaging.Acknowledgement
import org.slf4j.Logger
import org.slf4j.LoggerFactory


@PubSubListener
open class CatalogPipeline {
    /** Private log pipe. */
    val logging: Logger = LoggerFactory.getLogger(CatalogPipeline::class.java)

    init {
        logging.info("Initializing catalog pipeline...")
    }

    @Subscription(value = "v1.catalog.commit")
    fun onMessage(data: ByteArray, acknowledgement: Acknowledgement) {
        logging.info("!! Message received via Pub/Sub trigger channel. !!")
    }
}

The expectation (unless I am mistaken) is that, if CatalogPipeline is present in the classpath and designated via the .packages(*) call in my Application, Micronaut will boot up the Pub/Sub subscription and begin calling it for signals. Is that correct, or is there more setup I need to do?

I also have this in my application.yml:

micronaut:
  application:
    name: demo

gcp:
  project-id: project-id-here

The subscription is named correctly in GCP, and the project ID matches. My local credentials are authorized to publish and subscribe to the topic/subscription.

Also, how would I go about diagnosing these issues with logging? Is there a class that I can enable logging for to see why it would, or would not, create the subscription?

@sgammon
Copy link
Author

sgammon commented Jul 22, 2021

I've added a repro from a vanilla demo project here: https://github.com/sgammon/micronaut-pubsub-repro

@sgammon
Copy link
Author

sgammon commented Jul 26, 2021

@graemerocher / @viniciusccarvalho any ideas of what might be going wrong here?

@graemerocher
Copy link
Contributor

Try debug

this.subscriberFactory.createSubscriber(new SubscriberFactoryConfig(projectSubscriptionName, receiver, configuration, pubSubConfigurationProperties.getSubscribingExecutor()));
since that is where the subscriber is registered

@viniciusccarvalho
Copy link
Collaborator

Like @graemerocher said you can put a breakpoint there and see if it gets created. Another common issue with GCP is if you are authenticating using default credentials, Google keeps changing the IAM policies, and a bunch of services will just not work if you are not using a json credentials file and use the GOOGLE_APPLICATION_CREDENTIALS to point to the file.

@sgammon
Copy link
Author

sgammon commented Jul 27, 2021

@graemerocher the breakpoint doesn't get hit

@viniciusccarvalho i don't think this is related to credentials, if only because i get no errors in TRACE mode.

i do however get this error:

Bean type interface io.micronaut.context.processor.ExecutableMethodProcessor is not compatible with candidate generic types [interface io.micronaut.gcp.pubsub.annotation.PubSubListener] of candidate Definition: io.micronaut.gcp.pubsub.intercept.PubSubConsumerAdvice

how could that possibly be the case, though?

@graemerocher
Copy link
Contributor

Which version of Micronaut?

@graemerocher
Copy link
Contributor

And which version of Micronaut GCP?

@viniciusccarvalho
Copy link
Collaborator

@graemerocher looks like it's micronaut 3.0.0, has anything changed on bean post processing? I have been AFK for a while, did not keep up, need to test the GCP support on 3.x version

@graemerocher
Copy link
Contributor

@viniciusccarvalho yes that is why I asked. For Micronaut 3.0 is currently at milestone stage, you should explicitly declare a dependency on the 4.0.0 RC1 release to get a compatible version of the GCP module https://github.com/micronaut-projects/micronaut-gcp/releases/tag/v4.0.0-RC1

@graemerocher
Copy link
Contributor

See #448

@viniciusccarvalho
Copy link
Collaborator

Somehow the javax.inject package is missing from the depedencies: implementation group: 'javax.inject', name: 'javax.inject', version: '1'

I noticed that after adding it, all gcp beans were being loaded (for instance the GoogleCredentialsFactory). You could also check that @Singleton annotation was erroring on the IDE as the dependency is missin.

@sgammon I would follow @graemerocher advice and just change the version of your micronaut base project.

Thanks @graemerocher

@sgammon
Copy link
Author

sgammon commented Jul 27, 2021

@graemerocher / @viniciusccarvalho the sample is in 3.x.x, and yes i was previously using that. downgrading to 2.5.4 gets me better TRACE logs, but I still don't get a subscription. let me get back to you guys with more information or as soon as i determine this to be an actual bug (and not just cavalier upgrades to unreleased code!).

thank you for your help both of you 😄

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

No branches or pull requests

3 participants