Sivaprasanna Sethuraman
Sivaprasanna Sethuraman

Reputation: 4132

How to use Google Cloud PubSub with Proxy?

I'm working with an application that interacts with Google Cloud PubSub. It works fine in normal scenario but I want to enable proxy support so I was going through Publisher.Builder and Subscriber classes and their APIs to see if there are any APIs available to enable proxy support. I managed to find only the setChannelProvider but I'm not sure whether that will work or not.

The following code snippet is what I'm thinking of using but that doesn't seem to work.

ManagedChannel channel = ManagedChannelBuilder.forAddress(proxyHost, proxyPort).build();
TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
publisherBuilder.setChannelProvider(channelProvider);

I wasn't able to successfully publish or pull messages to the cloud service. I get the following error:

java.util.concurrent.ExecutionException: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 9978300322ns

So I wanted to know does the PubSub service support proxy through APIs or does it only support the proxy setting i.e. host and port to be provided in the environment path only.

Upvotes: 0

Views: 4667

Answers (3)

Mustapha Abourouh
Mustapha Abourouh

Reputation: 1

You need to set JVM args: https.proxyHost, https.proxyPort for proxy authentication an additional configration is needed before any client creation:

 Authenticator.setDefault(new Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return
                                    new PasswordAuthentication(proxyUsername,proxyPassword).toCharArray());
                        }

Upvotes: 0

sal
sal

Reputation: 51

You can specify the proxyHost/port directly using JVM args https.proxyHost, https.proxyPort

mvn clean install -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128  exec:java

then just directly create a client of your choice

TopicAdminSettings topicAdminSettings =   TopicAdminSettings.newBuilder().build();
TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings);

FYI- Setting ManagedChannelBuilder.forAddress() here overrides the final target for pubsub (which should be pubsub.googleapis.com 443 (not the proxy)

Here is a medium post i put together as well as a gist specificlly for pubsub and pubsub+proxy that requires basic auth headers


finally, just note, its https.proxyHost even if you're using httpProxy, ref grpc#9561

Upvotes: 4

Iñigo
Iñigo

Reputation: 2680

Proxy authentication via HTTP is not supported by Google Pub/Sub, but it can be configured by using GRPC_PROXY_EXP environment variable.

I found the same error that you got here (that's why I assume you are using HTTP) and it got fixed by using what I said.

Upvotes: 2

Related Questions