GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support Pub/Sub Emulator · Issue #1973 · googleapis/google-cloud-java

Support Pub/Sub Emulator #1973

New issue
Copy link
New issue
Copy link
Closed
Closed
Support Pub/Sub Emulator#1973
Copy link
Assignees
pongad
Labels
api: pubsubIssues related to the Pub/Sub API.authpriority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@fkorotkov
fkorotkov
opened on Apr 22, 2017
Issue body actions

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 googleapis/google-cloud-datastore#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"
}

Activity

Next
  1. pongad
    added
    auth
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on May 1, 2017
  2. pongad commented on May 1, 2017

    @pongad
    pongad
    on May 1, 2017
    Contributor
    More actions

    I can replicate this on my desktop; it looks like a bug.

    This seems to work correctly however:

    ManagedChannel chan = ManagedChannelBuilder.forAddress("localhost", 8085).usePlaintext(true).build();
    
    SubscriptionAdminSettings settings =
        SubscriptionAdminSettings.defaultBuilder()
            .setChannelProvider(FixedChannelProvider.create(chan))
            .build();
    
    try (SubscriptionAdminClient subscriptionAdminClient =
        SubscriptionAdminClient.create(settings)) {
      subscriptionAdminClient.createSubscription(
          subscription, topic, PushConfig.getDefaultInstance(), 0);
    }

    @tcoffee-google Since you're working on auth-related stuff, could you take a look?

  3. pongad
    assigned
    tcoffee-google
    on May 1, 2017
  4. fkorotkov commented on May 1, 2017

    @fkorotkov
    fkorotkov
    on May 1, 2017
    Author
    More actions

    @pongad @tcoffee-google thank you for taking a look!

    I've created a reproducible example if you'll need to: https://github.com/fkorotkov/snippets/commit/a0dd999135e753b78d2b36ce11623b162e620dcc

    Also interesting that if I change pubsub version to 0.17.1-alpha the test case simply hangs. I can see that a container is running through docker ps and by getting logs via docekr logs CONTAINER_ID I can see bunch of:

    [pubsub] May 01, 2017 4:38:42 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
    [pubsub] INFO: Detected non-HTTP/2 connection.
    [pubsub] May 01, 2017 4:38:42 PM io.gapi.emulators.netty.NotFoundHandler handleRequest
    [pubsub] INFO: Unknown request URI: /bad-request
    [pubsub] May 01, 2017 4:38:42 PM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
    [pubsub] INFO: Adding handler(s) to newly registered Channel.
    [pubsub] May 01, 2017 4:38:42 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
    [pubsub] INFO: Detected non-HTTP/2 connection.
    

    Will play around with 0.17.1-alpha a bit more. Great speed of releases!

  5. pongad commented on May 2, 2017

    @pongad
    pongad
    on May 2, 2017
    Contributor
    More actions

    @fkorotkov I can also reproduce that. I suspect that's actually gRPC retrying a connection; NoCredentials is probably causing an infinite retry behavior somehow.

    The fix I added above seems to solve both issues though. Is it good enough to unblock you for now?

  6. fkorotkov commented on May 2, 2017

    @fkorotkov
    fkorotkov
    on May 2, 2017
    Author
    More actions

    @pongad yeah, works perfectly for me https://github.com/fkorotkov/snippets/commit/d310bf967fb79e2e5617ede076051c3cd7e4e336. Thank you very much! Going to incorporate it into the main app(using an in-memory in-house implementation at the moment).

  7. pongad
    self-assigned this
    on May 3, 2017
  8. pongad commented on May 3, 2017

    @pongad
    pongad
    on May 3, 2017
    Contributor
    More actions

    This can be fixed by adding setPlainText to InstantiatingChannelProvider but it would have to call ManagedChannelBuilder::usePlainText which is beta API.

    @garrettjonesgoogle ?

  9. garrettjonesgoogle commented on May 4, 2017

    @garrettjonesgoogle
    garrettjonesgoogle
    on May 4, 2017
    Contributor
    More actions

    I would prefer not to add the dependency on the beta API within our non-test code (InstantiatingChannelProvider).

  10. shinfan
    added
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    on May 8, 2017
  11. rcleveng commented on May 10, 2017

    @rcleveng
    rcleveng
    on May 10, 2017
    More actions

    I tried the workarounds in code and was able to send a message, however never received it using a pull subscription.

  12. fkorotkov commented on May 14, 2017

    @fkorotkov
    fkorotkov
    on May 14, 2017
    Author
    More actions

    @rcleveng I also just got back to it and my test case hangs on trying to publish a message with bunch of:

    [pubsub] May 14, 2017 10:06:53 PM com.google.cloud.iam.testing.v1.shared.authorization.AuthInterceptor interceptCall
    [pubsub] INFO: Authentication interceptor: Header value is null
    

    At the moment we use an in-memory implementation of Publisher but would love to move to an official emulator to have better tests.

  13. fkorotkov commented on May 15, 2017

    @fkorotkov
    fkorotkov
    on May 15, 2017
    Author
    More actions

    Actually publishing is fine. Seems I have the same issue as @rcleveng when I'm not able to receive a message after publishing.

  14. pongad commented on May 15, 2017

    @pongad
    pongad
    on May 15, 2017
    Contributor
    More actions

    @fkorotkov I think your test is incorrect. In your PubSubTestingUtil.kt, you seem to be pulling messages to check whether there are messages pending, is this correct? The following sequence of events can happen:

    1. Subscriber start
    2. Subscriber pulls messages, found none, and back off to not spam the server.
    3. You publish the message.
    4. Before Subscriber pulls again, hasMessages pulls from the same subscription, finds the message, and reports that the subscription isn't empty.
    5. Subscriber pulls, but the server cannot give it the message
    • This is intended behavior. The message has already been given to hasMessages, and pubsub tries to not send duplicate messages.
    1. hasMessages run again. By the same reason as (5), it receives no messages and falsely reports that the subscription is empty.
    2. Your test checks messagesFromSubscriber, finds it empty, and fails.

    Because we have a concurrent system, writing tests for it is a little difficult. What do you want the test to check?

    If you're experimenting with the client library, maybe you just want MessageReceiver to print the message to the console. If you see the message, you can be pretty sure you set things up right.

    If you need automated testing, consider using BlockingQueue::poll. You can set the timeout to something improbably long like 30 seconds. The test might flake if your computer is really busy, but it should work well enough under normal circumstances.

  15. 15 remaining items

  16. pongad
    closed this as completedon May 29, 2017
  17. omrihq commented on Nov 7, 2017

    @omrihq
    omrihq
    on Nov 7, 2017
    More actions

    What dependency allows you to use val channelProvider = InstantiatingChannelProvider.newBuilder()....?

  18. garrettjonesgoogle commented on Nov 7, 2017

    @garrettjonesgoogle
    garrettjonesgoogle
    on Nov 7, 2017
    Contributor
    More actions

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

  19. omrihq commented on Nov 7, 2017

    @omrihq
    omrihq
    on Nov 7, 2017
    More actions

    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

    Reacted by Joseph Lewis III, trinityXmontoya and Max Gurewitz
  20. theacodes
    unassigned
    pongad
    on Sep 28, 2018
  21. JustinBeckwith
    assigned
    pongad
    on Feb 1, 2021
  22. chingor13
    added a commit that references this issue on Jan 22, 2026

    deps: update dependency com.google.cloud:sdk-platform-java-config to …

    141ec94
  23. chingor13
    added 2 commits that reference this issue on Feb 20, 2026

    feat: Add userClose flag back to StreamWriter (#1973)

    4b51acd

    chore(main): release 2.30.0 (#1976)

    423ee19
  24. lqiu96
    added a commit that references this issue on Mar 20, 2026

    deps: update dependency com.google.cloud:sdk-platform-java-config to …

    7c1ee6f
  25. suztomo
    added 2 commits that reference this issue on Mar 23, 2026

    feat: support isolation level repeatable read (googleapis#1973)

    ea51d68

    chore(main): release 2.29.0 (googleapis#1972)

    561216c
  26. meltsufin
    added 2 commits that reference this issue on Apr 29, 2026

    chore(deps): update dependency com.google.cloud:libraries-bom to v26.…

    1837776

    chore(deps): update dependency com.google.cloud:libraries-bom to v26.…

    44a6b06
  27. benjaminp
    added a commit that references this issue on Jul 13, 2026

    chore: bump urllib3 from 1.26.17 to 1.26.18 in /synthtool/gcp/templat…

    7faa0ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @pongad
    pongad

Labels

api: pubsubIssues related to the Pub/Sub API.authpriority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.