@Override public void createTopic(TopicPath topic) throws IOException { pubsub .projects() .topics() .create(topic.getPath(), new Topic()) .execute(); // ignore Topic result. }
try { pubsub.projects().topics() .create("projects/" + projectName + "/topics/" + topic, new Topic()).execute(); } catch (GoogleJsonResponseException e) { if (e.getStatusCode() != ALREADY_EXISTS) {
/** Create a topic if it doesn't exist. */ public static void createTopic(Pubsub client, String fullTopicName) throws IOException { System.out.println("fullTopicName " + fullTopicName); try { client.projects().topics().get(fullTopicName).execute(); } catch (GoogleJsonResponseException e) { if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) { Topic topic = client.projects().topics().create(fullTopicName, new Topic()).execute(); System.out.printf("Topic %s was created.%n", topic.getName()); } } } }
public void createTopic(String topic) throws IOException { client.projects().topics().create(getTopicPath(topic), new Topic()).execute(); }
/** * Creates a new topic with a given name. * * @param client Cloud Pub/Sub client. * @param args Command line arguments. * @throws IOException when Cloud Pub/Sub API calls fail. */ public static void createTopic(final Pubsub client, final String[] args) throws IOException { Main.checkArgsLength(args, 3); String topicName = PubsubUtils.getFullyQualifiedResourceName( PubsubUtils.ResourceType.TOPIC, args[0], args[2]); Topic topic = client.projects().topics() .create(topicName, new Topic()) .execute(); System.out.printf("Topic %s was created.\n", topic.getName()); }
private static Topic buildTopic(int i) { Topic topic = new Topic(); topic.setName(PubsubClient.topicPathFromName(PROJECT.getId(), "Topic" + i).getPath()); return topic; }
private void setupPubsubTopic(String topic) throws IOException { if (pubsubClient == null) { pubsubClient = newPubsubClient(options.as(PubsubOptions.class)).build(); } if (executeNullIfNotFound(pubsubClient.projects().topics().get(topic)) == null) { pubsubClient.projects().topics().create(topic, new Topic().setName(topic)).execute(); } }