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.

Support Pub/Sub Emulator

See original GitHub issue

It seems right now google-cloud-pubsub doesn’t support gcloud emulator. At least I’m not able to configure it for Pub/Sub even though I managed to use an emulator with google-cloud-datastore. I think it is related to https://github.com/GoogleCloudPlatform/google-cloud-datastore/issues/114.

Anyways, when I’m trying to create a subscriber using a channel provider with no credentials. Here are some snippets in Kotlin of how I create a SubscriptionAdminClient:

val channelProvider = InstantiatingChannelProvider.newBuilder()
        .setEndpoint("localhost:$port")
        .setCredentialsProvider(FixedCredentialsProvider.create(NoCredentials.getInstance()))
        .build()
protected fun getSubscriptionAdminClient(): SubscriptionAdminClient {
  val adminSettings = SubscriptionAdminSettings.defaultBuilder()
    .setChannelProvider(channelProvider)
    .build()
  return SubscriptionAdminClient.create(adminSettings)
}

When I’m trying to call com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient#createSubscription I’m getting:

com.google.api.gax.grpc.ApiException: io.grpc.StatusRuntimeException: UNKNOWN
	at com.google.api.gax.grpc.ExceptionTransformingCallable$ExceptionTransformingFuture.onFailure(ExceptionTransformingCallable.java:109)
	at com.google.api.gax.core.ApiFutures$1.onFailure(ApiFutures.java:53)
	at com.google.common.util.concurrent.Futures$4.run(Futures.java:1126)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902)
	at com.google.common.util.concurrent.AbstractFuture.addListener(AbstractFuture.java:636)
	at com.google.common.util.concurrent.ForwardingListenableFuture.addListener(ForwardingListenableFuture.java:45)
	at com.google.api.gax.core.internal.ApiFutureToListenableFuture.addListener(ApiFutureToListenableFuture.java:53)
	at com.google.common.util.concurrent.Futures.addCallback(Futures.java:1138)
	at com.google.common.util.concurrent.Futures.addCallback(Futures.java:1076)
	at com.google.api.gax.core.ApiFutures.addCallback(ApiFutures.java:48)
	at com.google.api.gax.grpc.ExceptionTransformingCallable.futureCall(ExceptionTransformingCallable.java:65)
	at com.google.api.gax.grpc.RetryingCallable$GrpcRetryCallable.call(RetryingCallable.java:139)
	at com.google.api.gax.grpc.RetryingCallable.futureCall(RetryingCallable.java:84)
	at com.google.api.gax.grpc.UnaryCallable.futureCall(UnaryCallable.java:219)
	at com.google.api.gax.grpc.UnaryCallable.futureCall(UnaryCallable.java:230)
	at com.google.api.gax.grpc.UnaryCallable.call(UnaryCallable.java:258)
	at com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient.createSubscription(SubscriptionAdminClient.java:339)
	at com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient.createSubscription(SubscriptionAdminClient.java:307)
	at com.fkorotkov.gcloud.pubsub.PubSubImpl.registerSubscriber(PubSubImpl.kt:72)
Caused by: io.grpc.StatusRuntimeException: UNKNOWN
	at io.grpc.Status.asRuntimeException(Status.java:540)
	at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:439)
	at io.grpc.ClientInterceptors$CheckedForwardingClientCall.start(ClientInterceptors.java:202)
	at io.grpc.ForwardingClientCall.start(ForwardingClientCall.java:47)
	at com.google.api.gax.grpc.HeaderInterceptor$1.start(HeaderInterceptor.java:62)
	at io.grpc.stub.ClientCalls.startCall(ClientCalls.java:270)
	at io.grpc.stub.ClientCalls.asyncUnaryRequestCall(ClientCalls.java:249)
	at io.grpc.stub.ClientCalls.futureUnaryCall(ClientCalls.java:186)
	at com.google.api.gax.grpc.DirectCallable.futureCall(DirectCallable.java:59)
	at com.google.api.gax.grpc.ExceptionTransformingCallable.futureCall(ExceptionTransformingCallable.java:62)
	... 55 more
Caused by: java.lang.IllegalStateException: OAuth2Credentials instance does not support refreshing the access token. An instance with a new access token should be used, or a derived type that supports refreshing.
	at com.google.auth.oauth2.OAuth2Credentials.refreshAccessToken(OAuth2Credentials.java:182)
	at com.google.auth.oauth2.OAuth2Credentials.refresh(OAuth2Credentials.java:149)
	at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:135)
	at io.grpc.auth.ClientAuthInterceptor.getRequestMetadata(ClientAuthInterceptor.java:148)
	at io.grpc.auth.ClientAuthInterceptor.access$100(ClientAuthInterceptor.java:62)
	at io.grpc.auth.ClientAuthInterceptor$1.checkedStart(ClientAuthInterceptor.java:94)
	at io.grpc.ClientInterceptors$CheckedForwardingClientCall.start(ClientInterceptors.java:194)
	... 62 more

As I mentioned above I’m able to use Datastore emulator when I run it with --no-legacy flag and by creating a Datastore service like this:

DatastoreOptions.newBuilder()
      .setProjectId("unit-testing")
      .setHost("localhost:$port")
      .setCredentials(NoCredentials.getInstance())
      .build()
      .getService()

I’m using the latest available version of the libraries at the moment:

{
  "group": "com.google.cloud",
  "name": "google-cloud-datastore",
  "version": "0.13.0-beta"
},
{
  "group": "com.google.cloud",
  "name": "google-cloud-pubsub",
  "version": "0.13.0-alpha"
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:26 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
omrihqcommented, Nov 7, 2017

Interesting, is there an updated example of a PubSub emulator then? Ex: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/TESTING.md#testing-code-that-uses-pubsub seems to use old code

0reactions
garrettjonesgooglecommented, Nov 7, 2017

The class name is now InstantiatingGrpcChannelProvider and it is present in gax-grpc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing apps locally with the emulator | Cloud Pub/Sub ...
To develop and test your application locally, you can use the Pub/Sub emulator, which provides local emulation of the production Pub/Sub service.
Read more >
google-pubsub-emulator - npm
Google pubsub emulator to nodejs / javascript. ... Perfect to support unit testing when you need the local emulator start in unit /...
Read more >
How do I use pubsub emulator for local testing?
Kush, The Pub/Sub emulator is detected using environment variables. The page you refer to gives: export PUBSUB_EMULATOR_HOST=localhost:8590 as an example.
Read more >
ridedott/pubsub-emulator-docker - GitHub
PubSub emulator in a form of a Docker image. Contribute to ridedott/pubsub-emulator-docker development by creating an account on GitHub.
Read more >
Can't reach GCP PubSub Emulator - Stack Overflow
emulators.netty.HttpVersionRoutingHandler channelRead [pubsub] INFO: Detected non-HTTP/2 connection. [pubsub] Nov 17, 2022 4:00:57 PM ...
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