Throws: io.grpc.StatusRuntimeException: NOT_FOUND: resource not found

I'm trying to write a pubsub test:

@Test
public void sendTopic() throws Exception {

    CustomSubscriber customSubscriber = new CustomSubscriber();
    customSubscriber.startAndWait();

    CustomPublisher customPublisher = new CustomPublisher();
    customPublisher.publish("123");
}

      

and

public CustomSubscriber() {
    this.subscriptionName = SubscriptionName.create(SdkServiceConfig.s.GCP_PROJECT_ID, SdkServiceConfig.s.TOPIC_ID );
    this.receiveMsgAction = (message, consumer) -> {
        // handle incoming message, then ack/nack the received message
        System.out.println("Id : " + message.getMessageId());
        System.out.println("Data : " + message.getData().toStringUtf8());
        consumer.ack();
    };
    this.afterStopAction = new ApiFutureEmpty();
}

// [TARGET startAsync()]
public void startAndWait() throws Exception {
    Subscriber subscriber = createSubscriberWithCustomCredentials();
    subscriber.startAsync();

    // Wait for a stop signal.
    afterStopAction.get();
    subscriber.stopAsync().awaitTerminated();
}

      

and

public ApiFuture<String> publish(String message) throws Exception {
    ByteString data = ByteString.copyFromUtf8(message);
    PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
    ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage);

    ApiFutures.addCallback(messageIdFuture, new ApiFutureCallback<String>() {
        public void onSuccess(String messageId) {
            System.out.println("published with message id: " + messageId);
        }

        public void onFailure(Throwable t) {
            System.out.println("failed to publish: " + t);
        }
    });
    return messageIdFuture;
}

/**
 * Example of creating a {@code Publisher}.
 */
// [TARGET newBuilder(TopicName)]
// [VARIABLE "my_project"]
// [VARIABLE "my_topic"]
public void createPublisher(String projectId, String topicId) throws Exception {
    TopicName topic = TopicName.create(projectId, topicId);
    try {
        publisher = createPublisherWithCustomCredentials(topic);

    } finally {
        // When finished with the publisher, make sure to shutdown to free up resources.
        publisher.shutdown();
    }
}

      

When I run the code, I get this error:

Caused by: io.grpc.StatusRuntimeException: NOT_FOUND: Resource not found (resource=add-partner-request).

      

What am I missing?

+5


source to share


4 answers


I am assuming TOPIC_ID is the name of your theme; you really need to link to the subscription. You can easily create a subscription from the GCP console and then reference that name in SubscriptionName.create (project, yoursubscriptionname)



0


source


I think you will forget to create a theme inside your project with the following name "add-partner-request". You can create it using the following code:



try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
  // projectId <=  unique project identifier, eg. "my-project-id"
  TopicName topicName = TopicName.create(projectId, "add-partner-request");
  Topic topic = topicAdminClient.createTopic(topicName);
  return topic;
}

      

0


source


I am getting the same error in the logstash logs. I am using plugins-input-google_pubsub (insert)

https://www.elastic.co/guide/en/logstash/current/plugins-inputs-google_pubsub.html

[2019-02-06T04:24:21,450][ERROR][logstash.inputs.googlepubsub] io.grpc.StatusRuntimeException: NOT_FOUND: Resource not found (resource=logstash-subwwww).
[2019-02-06T04:24:22,480][INFO ][logstash.inputs.googlepubsub] Subscription already exists
[2019-02-06T04:24:22,644][ERROR][logstash.pipeline        ] A plugin had an unrecoverable error. Will restart this plugin.
  Pipeline_id:main
  Plugin: <LogStash::Inputs::GooglePubSub json_key_file=>"/home/pksingh12021992/key.json", topic=>"testtopic", subscription=>"logstash-subwwww", id=>"d4d2d3350317dacb318d9d0c43b924c355
43002430fd6b6e50b4cee4231ac7ac", project_id=>"my-demo-228617", create_subscription=>true, enable_metric=>true, codec=><LogStash::Codecs::Plain id=>"plain_d0da18ef-9039-4915-999e-15c33e
e34bfc", enable_metric=>true, charset=>"UTF-8">, max_messages=>5, include_metadata=>false>
  Error: Expected the service InnerService [FAILED] to be TERMINATED, but the service has FAILED
  Exception: Java::JavaLang::IllegalStateException
  Stack: com.google.common.util.concurrent.AbstractService.checkCurrentState(com/google/common/util/concurrent/AbstractService.java:345)
com.google.common.util.concurrent.AbstractService.awaitTerminated(com/google/common/util/concurrent/AbstractService.java:308)
com.google.api.core.AbstractApiService.awaitTerminated(com/google/api/core/AbstractApiService.java:104)
java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:498)
org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(org/jruby/javasupport/JavaMethod.java:438)
org.jruby.javasupport.JavaMethod.invokeDirect(org/jruby/javasupport/JavaMethod.java:302)
usr.share.logstash.vendor.bundle.jruby.$2_dot_3_dot_0.gems.logstash_minus_input_minus_google_pubsub_minus_1_dot_2_dot_1.lib.logstash.inputs.google_pubsub.run(/usr/share/logstash/vendor
/bundle/jruby/2.3.0/gems/logstash-input-google_pubsub-1.2.1/lib/logstash/inputs/google_pubsub.rb:277)
usr.share.logstash.logstash_minus_core.lib.logstash.pipeline.inputworker(/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:409)
usr.share.logstash.logstash_minus_core.lib.logstash.pipeline.RUBY$method$inputworker$0$__VARARGS__(usr/share/logstash/logstash_minus_core/lib/logstash//usr/share/logstash/logstash-core
/lib/logstash/pipeline.rb)
usr.share.logstash.logstash_minus_core.lib.logstash.pipeline.block in start_input(/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:403)
org.jruby.RubyProc.call(org/jruby/RubyProc.java:289)
org.jruby.RubyProc.call(org/jruby/RubyProc.java:246)
java.lang.Thread.run(java/lang/Thread.java:748)
[2019-02-06T04:24:22,648][ERROR][logstash.inputs.googlepubsub] io.grpc.StatusRuntimeException: NOT_FOUND: Resource not found (resource=logstash-subwwww).

      

anyone got a solution for this logstash plugin?

0


source


Whichever object is named "add-partner-request" has not been successfully created or is not owned by the project. If the topic is "add-partner-request", then you really need to create a topic; the string is TopicName.create(projectId, topicId)

not enough to create the theme itself Typically, you can create a theme in the Cloud Pub / Sub section of the Cloud console or using the gcloud command, for example

gcloud pubsub topics create add-partner-request

      

Make sure that the project you log into the console is the one used in your code. You must also set the project explicitly when creating the theme using a flag, --project

or make sure the default project is correct:

gcloud config list --format='text(core.project)'

      

It is typical for tests to create and delete in code. For example, to create a theme:

Topic topic = null;
ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
TopicAdminClient topicAdminClient = TopicAdminClient.create();
try {
  topic = topicAdminClient.createTopic(topicName);
} catch (APIException e) {
  System.out.println("Issue creating topic!");
}

      

If "add-partner-request" is a subscription name, then the same rules apply. The gcloud command would change slightly:

gcloud pubsub subscriptions create add-partner-request --topic=<topic name>

      

The command to create a Java subscription will look like this:

Subscription subscription = null;
ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId);
SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create();
try {
  subscription = subscriptionAdminClient.createSubscription(
          subscriptionName, topicName, PushConfig.newBuilder().build(), 600);
} catch (APIException e) {
  System.out.println("Issue creating topic!");
}

      

0


source







All Articles