GeezerVison is showing github.com — Pubsub: Invalid resource name given · Issue #3334 · googleapis/google-cloud-java
Pubsub: Invalid resource name given #3334Labels api: pubsubIssues related to the Pub/Sub API.priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue. DescriptionWhen I try to follow the example code as given here:
(NOTE: I altered the hardcoded strings here to match the ones I need)
ProjectTopicName topicName = ProjectTopicName.of("my-project-id", "my-topic-id");
Publisher publisher = null;
List<ApiFuture<String>> messageIdFutures = new ArrayList<>();
try {
// Create a publisher instance with default settings bound to the topic
publisher = Publisher.newBuilder(topicName).build();
List<String> messages = Arrays.asList("first message", "second message");
// schedule publishing one message at a time : messages get automatically batched
for (String message : messages) {
ByteString data = ByteString.copyFromUtf8(message);
PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
// Once published, returns a server-assigned message id (unique within the topic)
ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage);
messageIdFutures.add(messageIdFuture);
}
} finally {
// wait on any pending publish requests.
List<String> messageIds = ApiFutures.allAsList(messageIdFutures).get();
for (String messageId : messageIds) {
System.out.println("published with message ID: " + messageId);
}
if (publisher != null) {
// When finished with the publisher, shutdown to free up resources.
publisher.shutdown();
}
}
It raises an exception on:
ApiFutures.allAsList(messageIdFutures).get();
Exception:
java.util.concurrent.ExecutionException: com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Invalid resource name given (name=testResource) Refer to https://cloud.google.com/pubsub/overview#names for more information.
When I publish a message through the web console, it works as intended and my code (based on the example subscriber code) can read it out correctly.
My resource name matches with what I see in the console though:
projects/testProject-2013370/topics/testResource
Project info:
Java version: 1.8.0_131
Pubsub dependency: 'com.google.cloud:google-cloud-pubsub:1.31.0' Activityyihanzhen commented on Jun 4, 2018 Hi @DylanMeeus Sorry I wasn't able to repro this issue.
Can you make sure in this case, your topicName is created by:
ProjectTopicName topicName = ProjectTopicName.of("testProject-2013370", "testResource");
If that still does not help, can you try
publisher = Publisher.newBuilder("projects/testProject-2013370/topics/testResource").build();
and see if that works? MrThreepwood commented on Jun 5, 2018 I am getting the same issue. I think it's when I end up pulling.
Jun 05, 2018 3:13:25 PM com.google.cloud.pubsub.v1.StreamingSubscriberConnection$1 onFailure
SEVERE: terminated streaming with exception
com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Invalid resource name given (name=random). Refer to https://cloud.google.com/pubsub/overview#names for more information.
at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:49)
at com.google.cloud.pubsub.v1.StreamingSubscriberConnection$1.onFailure(StreamingSubscriberConnection.java:241)
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1123)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:435)
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:900)
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:811)
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:675)
at com.google.common.util.concurrent.SettableFuture.setException(SettableFuture.java:53)
at com.google.cloud.pubsub.v1.StreamingSubscriberConnection$StreamingPullResponseObserver.onError(StreamingSubscriberConnection.java:178)
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:419)
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:41)
at io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:684)
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:41)
at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:391)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:475)
at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:63)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:557)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:478)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:590)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
at java.util.concurrent.Executors$RunnableAdapter.call$$$capture(Executors.java:511)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java)
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Invalid resource name given (name=random). Refer to https://cloud.google.com/pubsub/overview#names for more information.
at io.grpc.Status.asRuntimeException(Status.java:526)
... 21 more
TopicAdminClient.create().createTopic(topicName) topicName is Test
ProjectTopicName.of(ServiceOptions.getDefaultProjectId(), topic) again, topic is Test
SubscriptionAdminClient.create().createSubscription(name, topicName, PushConfig.getDefaultInstance(), 0) name is apparently random
It kinda sorta seems to imply that random is just an invalid format for a subscriber name, however, if names have to be in a particular format it would be nice if the documentation specified this... The link provided in the exception mentions NOTHING about subscription name formatting. DylanMeeus commented on Jun 5, 2018 @hzyi-google I will test this asap.
@MrThreepwood Names do have to adhere to a certain format. As you have no doubt experienced as well, the URL the exception refers you to is useless. (for which I have made #3333 , which was swiftly resolved so props for that!)
The URL you should be looking at, as it turns out, is this one: https://cloud.google.com/pubsub/docs/admin#resource_names
Neither "random" nor "testResource" violate these restrictions. MrThreepwood commented on Jun 5, 2018 I figured out what my actual issue was. I was accidentally passing the string "random" to Subscriber.newBuilder() rather than he ProjectSubscriptionName.
I now have it up and working. So obviously the full name should end up being something along the lines of projectId/name. If using the builder with the string name parameter it's not obvious what the actual issue is by the error provided.
Thanks for the quick reply. DylanMeeus commented on Jun 6, 2018 @hzyi-google
I have tried it with the second builder you suggested - which worked.
After that, I have also found the problem with my original code.. rather than using the "topic name" I had used the "topic id" in this line: publisher = Publisher.newBuilder(topicName).build();.
🤦♂️
Thanks for the alternative method, that eventually led me to the solution! yihanzhen commented on Jun 6, 2018
MetadataMetadataapi: pubsubIssues related to the Pub/Sub API.priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue. DevelopmentNo branches or pull requestsIssue actions
|