Skip to content

Commit

Permalink
delete publish-related methods from PubSub
Browse files Browse the repository at this point in the history
  • Loading branch information
pongad committed Dec 22, 2016
1 parent 994479f commit bd4b537
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 827 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,40 +285,6 @@ public String params() {
}
}

/**
* This class demonstrates how to publish messages to a Pub/Sub topic.
*
* @see <a href="https://cloud.google.com/pubsub/publisher#publish-messages-to-a-topic">Publish
* messages to a topic</a>
*/
private static class PublishMessagesAction extends PubSubAction<Tuple<String, List<Message>>> {
@Override
public void run(PubSub pubsub, Tuple<String, List<Message>> params) {
String topic = params.x();
List<Message> messages = params.y();
pubsub.publish(topic, messages);
System.out.printf("Published %d messages to topic %s%n", messages.size(), topic);
}

@Override
Tuple<String, List<Message>> parse(String... args) throws Exception {
if (args.length < 2) {
throw new IllegalArgumentException("Missing required topic and messages");
}
String topic = args[0];
List<Message> messages = new ArrayList<>();
for (String payload : Arrays.copyOfRange(args, 1, args.length)) {
messages.add(Message.of(payload));
}
return Tuple.of(topic, messages);
}

@Override
public String params() {
return "<topic> <message>+";
}
}

private abstract static class SubscriptionAction extends PubSubAction<String> {
@Override
String parse(String... args) throws Exception {
Expand Down Expand Up @@ -643,7 +609,6 @@ public void run(PubSub pubsub, Tuple<String, List<String>> param) throws Excepti
ACTIONS.put("get-policy", new ParentAction(GET_IAM_ACTIONS));
ACTIONS.put("add-identity", new ParentAction(REPLACE_IAM_ACTIONS));
ACTIONS.put("test-permissions", new ParentAction(TEST_IAM_ACTIONS));
ACTIONS.put("publish", new PublishMessagesAction());
ACTIONS.put("replace-push-config", new ReplacePushConfigAction());
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -186,99 +186,6 @@ public boolean deleteTopicAsync(String topicName)
return deleted;
}

/**
* Example of publishing one message to a topic.
*/
// [TARGET publish(String, Message)]
// [VARIABLE "my_topic_name"]
public String publishOneMessage(String topicName) {
// [START publishOneMessage]
Message message = Message.of("payload");
String messageId = pubsub.publish(topicName, message);
// [END publishOneMessage]
return messageId;
}

/**
* Example of asynchronously publishing one message to a topic.
*/
// [TARGET publishAsync(String, Message)]
// [VARIABLE "my_topic_name"]
public String publishOneMessageAsync(String topicName)
throws ExecutionException, InterruptedException {
// [START publishOneMessageAsync]
Message message = Message.of("payload");
Future<String> future = pubsub.publishAsync(topicName, message);
// ...
String messageId = future.get();
// [END publishOneMessageAsync]
return messageId;
}

/**
* Example of publishing a list of messages to a topic.
*/
// [TARGET publish(String, Iterable)]
// [VARIABLE "my_topic_name"]
public List<String> publishMessageList(String topicName) {
// [START publishMessageList]
List<Message> messages = new LinkedList<>();
messages.add(Message.of("payload1"));
messages.add(Message.of("payload2"));
List<String> messageIds = pubsub.publish(topicName, messages);
// [END publishMessageList]
return messageIds;
}

/**
* Example of asynchronously publishing a list of messages to a topic.
*/
// [TARGET publishAsync(String, Iterable)]
// [VARIABLE "my_topic_name"]
public List<String> publishMessageListAsync(String topicName)
throws ExecutionException, InterruptedException {
// [START publishMessageListAsync]
List<Message> messages = new LinkedList<>();
messages.add(Message.of("payload1"));
messages.add(Message.of("payload2"));
Future<List<String>> future = pubsub.publishAsync(topicName, messages);
// ...
List<String> messageIds = future.get();
// [END publishMessageListAsync]
return messageIds;
}

/**
* Example of publishing some messages to a topic.
*/
// [TARGET publish(String, Message, Message...)]
// [VARIABLE "my_topic_name"]
public List<String> publishMessages(String topicName) {
// [START publishMessages]
Message message1 = Message.of("payload1");
Message message2 = Message.of("payload2");
List<String> messageIds = pubsub.publish(topicName, message1, message2);
// [END publishMessages]
return messageIds;
}

/**
* Example of asynchronously publishing some messages to a topic.
*/
// [TARGET publishAsync(String, Message, Message...)]
// [VARIABLE "my_topic_name"]
public List<String> publishMessagesAsync(String topicName)
throws ExecutionException, InterruptedException {
// [START publishMessagesAsync]
Message message1 = Message.of("payload1");
Message message2 = Message.of("payload2");
Future<List<String>> future = pubsub.publishAsync(topicName, message1, message2);
// ...
List<String> messageIds = future.get();
// [END publishMessagesAsync]
return messageIds;
}

/**
* Example of creating a pull subscription for a topic.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,94 +113,6 @@ public boolean deleteAsync() throws ExecutionException, InterruptedException {
return deleted;
}

/**
* Example of publishing one message to the topic.
*/
// [TARGET publish(Message)]
public String publishOneMessage() {
// [START publishOneMessage]
Message message = Message.of("payload");
String messageId = topic.publish(message);
// [END publishOneMessage]
return messageId;
}

/**
* Example of asynchronously publishing one message to the topic.
*/
// [TARGET publishAsync(Message)]
public String publishOneMessageAsync()
throws ExecutionException, InterruptedException {
// [START publishOneMessageAsync]
Message message = Message.of("payload");
Future<String> future = topic.publishAsync(message);
// ...
String messageId = future.get();
// [END publishOneMessageAsync]
return messageId;
}


/**
* Example of publishing a list of messages to the topic.
*/
// [TARGET publish(Iterable)]
public List<String> publishMessageList() {
// [START publishMessageList]
List<Message> messages = new LinkedList<>();
messages.add(Message.of("payload1"));
messages.add(Message.of("payload2"));
List<String> messageIds = topic.publish(messages);
// [END publishMessageList]
return messageIds;
}

/**
* Example of asynchronously publishing a list of messages to the topic.
*/
// [TARGET publishAsync(Iterable)]
public List<String> publishMessageListAsync()
throws ExecutionException, InterruptedException {
// [START publishMessageListAsync]
List<Message> messages = new LinkedList<>();
messages.add(Message.of("payload1"));
messages.add(Message.of("payload2"));
Future<List<String>> future = topic.publishAsync(messages);
// ...
List<String> messageIds = future.get();
// [END publishMessageListAsync]
return messageIds;
}

/**
* Example of publishing some messages to the topic.
*/
// [TARGET publish(Message, Message...)]
public List<String> publishMessages() {
// [START publishMessages]
Message message1 = Message.of("payload1");
Message message2 = Message.of("payload2");
List<String> messageIds = topic.publish(message1, message2);
// [END publishMessages]
return messageIds;
}

/**
* Example of asynchronously publishing some messages to the topic.
*/
// [TARGET publishAsync(Message, Message...)]
public List<String> publishMessagesAsync()
throws ExecutionException, InterruptedException {
// [START publishMessagesAsync]
Message message1 = Message.of("payload1");
Message message2 = Message.of("payload2");
Future<List<String>> future = topic.publishAsync(message1, message2);
// ...
List<String> messageIds = future.get();
// [END publishMessagesAsync]
return messageIds;
}

/**
* Example of listing subscriptions for the topic, specifying the page size.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ public void testTopic() throws ExecutionException, InterruptedException {
assertEquals(topic, updatedTopic);
updatedTopic = topicSnippets.reloadAsync();
assertEquals(topic, updatedTopic);
assertNotNull(topicSnippets.publishOneMessage());
assertNotNull(topicSnippets.publishOneMessageAsync());
assertEquals(2, topicSnippets.publishMessageList().size());
assertEquals(2, topicSnippets.publishMessageListAsync().size());
assertEquals(2, topicSnippets.publishMessages().size());
assertEquals(2, topicSnippets.publishMessagesAsync().size());
}

@Test
Expand Down
Loading

0 comments on commit bd4b537

Please sign in to comment.