reader = new SpecificDatumReader<>(State.getClassSchema());
+
+ // Instantiate an asynchronous message receiver.
+ MessageReceiver receiver =
+ (PubsubMessage message, AckReplyConsumer consumer) -> {
+ ByteString data = message.getData();
+
+ // Get the schema encoding type.
+ String encoding = message.getAttributesMap().get("googclient_schemaencoding");
+
+ // Send the message data to a byte[] input stream.
+ InputStream inputStream = new ByteArrayInputStream(data.toByteArray());
+
+ Decoder decoder = null;
+
+ // Prepare an appropriate decoder for the message data in the input stream
+ // based on the schema encoding type.
+ block:
+ try {
+ switch (encoding) {
+ case "BINARY":
+ decoder = DecoderFactory.get().directBinaryDecoder(inputStream, /*reuse=*/ null);
+ System.out.println("Receiving a binary-encoded message:");
+ break;
+ case "JSON":
+ decoder = DecoderFactory.get().jsonDecoder(State.getClassSchema(), inputStream);
+ System.out.println("Receiving a JSON-encoded message:");
+ break;
+ default:
+ break block;
+ }
+
+ // Obtain an object of the generated Avro class using the decoder.
+ State state = reader.read(null, decoder);
+ System.out.println(state.getName() + " is abbreviated as " + state.getPostAbbr());
+
+ } catch (IOException e) {
+ System.err.println(e);
+ }
+
+ // Ack the message.
+ consumer.ack();
+ };
+
+ Subscriber subscriber = null;
+ try {
+ subscriber = Subscriber.newBuilder(subscriptionName, receiver).build();
+ subscriber.startAsync().awaitRunning();
+ System.out.printf("Listening for messages on %s:\n", subscriptionName.toString());
+ subscriber.awaitTerminated(30, TimeUnit.SECONDS);
+ } catch (TimeoutException timeoutException) {
+ subscriber.stopAsync();
+ }
+ }
+}
+// [END pubsub_subscribe_avro_records]
diff --git a/samples/snippets/src/main/java/pubsub/SubscribeWithProtoSchemaExample.java b/samples/snippets/src/main/java/pubsub/SubscribeWithProtoSchemaExample.java
new file mode 100644
index 000000000..65ff2b39d
--- /dev/null
+++ b/samples/snippets/src/main/java/pubsub/SubscribeWithProtoSchemaExample.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pubsub;
+
+// [START pubsub_subscribe_proto_messages]
+
+import com.google.cloud.pubsub.v1.AckReplyConsumer;
+import com.google.cloud.pubsub.v1.MessageReceiver;
+import com.google.cloud.pubsub.v1.Subscriber;
+import com.google.protobuf.ByteString;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.util.JsonFormat;
+import com.google.pubsub.v1.ProjectSubscriptionName;
+import com.google.pubsub.v1.PubsubMessage;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import utilities.StateProto.State;
+
+public class SubscribeWithProtoSchemaExample {
+
+ public static void main(String... args) throws Exception {
+ // TODO(developer): Replace these variables before running the sample.
+ String projectId = "your-project-id";
+ // Use an existing subscription.
+ String subscriptionId = "your-subscription-id";
+
+ subscribeWithProtoSchemaExample(projectId, subscriptionId);
+ }
+
+ public static void subscribeWithProtoSchemaExample(String projectId, String subscriptionId) {
+
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscriptionId);
+
+ MessageReceiver receiver =
+ (PubsubMessage message, AckReplyConsumer consumer) -> {
+ ByteString data = message.getData();
+
+ // Get the schema encoding type.
+ String encoding = message.getAttributesMap().get("googclient_schemaencoding");
+
+ block:
+ try {
+ switch (encoding) {
+ case "BINARY":
+ // Obtain an object of the generated proto class.
+ State state = State.parseFrom(data);
+ System.out.println("Received a BINARY-formatted message: " + state);
+ break;
+
+ case "JSON":
+ State.Builder stateBuilder = State.newBuilder();
+ JsonFormat.parser().merge(data.toStringUtf8(), stateBuilder);
+ System.out.println("Received a JSON-formatted message:" + stateBuilder.build());
+ break;
+
+ default:
+ break block;
+ }
+ } catch (InvalidProtocolBufferException e) {
+ e.printStackTrace();
+ }
+
+ consumer.ack();
+ System.out.println("Ack'ed the message");
+ };
+
+ // Create subscriber client.
+ Subscriber subscriber = Subscriber.newBuilder(subscriptionName, receiver).build();
+
+ try {
+ subscriber.startAsync().awaitRunning();
+ System.out.printf("Listening for messages on %s:\n", subscriptionName);
+ subscriber.awaitTerminated(30, TimeUnit.SECONDS);
+ } catch (TimeoutException timeoutException) {
+ subscriber.stopAsync();
+ }
+ }
+}
+// [END pubsub_subscribe_proto_messages]
diff --git a/samples/snippets/src/main/java/utilities/State.java b/samples/snippets/src/main/java/utilities/State.java
new file mode 100644
index 000000000..a3d837e85
--- /dev/null
+++ b/samples/snippets/src/main/java/utilities/State.java
@@ -0,0 +1,441 @@
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Autogenerated by Avro
+ *
+ * DO NOT EDIT DIRECTLY
+ */
+package utilities;
+
+import org.apache.avro.message.BinaryMessageDecoder;
+import org.apache.avro.message.BinaryMessageEncoder;
+import org.apache.avro.message.SchemaStore;
+import org.apache.avro.specific.SpecificData;
+import org.apache.avro.util.Utf8;
+
+/** A list of states in the United States of America. */
+@org.apache.avro.specific.AvroGenerated
+public class State extends org.apache.avro.specific.SpecificRecordBase
+ implements org.apache.avro.specific.SpecificRecord {
+ private static final long serialVersionUID = -6098929419967278282L;
+ public static final org.apache.avro.Schema SCHEMA$ =
+ new org.apache.avro.Schema.Parser()
+ .parse(
+ "{\"type\":\"record\",\"name\":\"State\",\"namespace\":\"utilities\",\"doc\":\"A list of states in the United States of America.\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"The common name of the state.\"},{\"name\":\"post_abbr\",\"type\":\"string\",\"doc\":\"The postal code abbreviation of the state.\"}]}");
+
+ public static org.apache.avro.Schema getClassSchema() {
+ return SCHEMA$;
+ }
+
+ private static SpecificData MODEL$ = new SpecificData();
+
+ private static final BinaryMessageEncoder ENCODER =
+ new BinaryMessageEncoder(MODEL$, SCHEMA$);
+
+ private static final BinaryMessageDecoder DECODER =
+ new BinaryMessageDecoder(MODEL$, SCHEMA$);
+
+ /**
+ * Return the BinaryMessageEncoder instance used by this class.
+ *
+ * @return the message encoder used by this class
+ */
+ public static BinaryMessageEncoder getEncoder() {
+ return ENCODER;
+ }
+
+ /**
+ * Return the BinaryMessageDecoder instance used by this class.
+ *
+ * @return the message decoder used by this class
+ */
+ public static BinaryMessageDecoder getDecoder() {
+ return DECODER;
+ }
+
+ /**
+ * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link
+ * SchemaStore}.
+ *
+ * @param resolver a {@link SchemaStore} used to find schemas by fingerprint
+ * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore
+ */
+ public static BinaryMessageDecoder createDecoder(SchemaStore resolver) {
+ return new BinaryMessageDecoder(MODEL$, SCHEMA$, resolver);
+ }
+
+ /**
+ * Serializes this State to a ByteBuffer.
+ *
+ * @return a buffer holding the serialized data for this instance
+ * @throws java.io.IOException if this instance could not be serialized
+ */
+ public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
+ return ENCODER.encode(this);
+ }
+
+ /**
+ * Deserializes a State from a ByteBuffer.
+ *
+ * @param b a byte buffer holding serialized data for an instance of this class
+ * @return a State instance decoded from the given buffer
+ * @throws java.io.IOException if the given bytes could not be deserialized into an instance of
+ * this class
+ */
+ public static State fromByteBuffer(java.nio.ByteBuffer b) throws java.io.IOException {
+ return DECODER.decode(b);
+ }
+
+ /** The common name of the state. */
+ private java.lang.CharSequence name;
+ /** The postal code abbreviation of the state. */
+ private java.lang.CharSequence post_abbr;
+
+ /**
+ * Default constructor. Note that this does not initialize fields to their default values from the
+ * schema. If that is desired then one should use newBuilder()
.
+ */
+ public State() {}
+
+ /**
+ * All-args constructor.
+ *
+ * @param name The common name of the state.
+ * @param post_abbr The postal code abbreviation of the state.
+ */
+ public State(java.lang.CharSequence name, java.lang.CharSequence post_abbr) {
+ this.name = name;
+ this.post_abbr = post_abbr;
+ }
+
+ public org.apache.avro.specific.SpecificData getSpecificData() {
+ return MODEL$;
+ }
+
+ public org.apache.avro.Schema getSchema() {
+ return SCHEMA$;
+ }
+ // Used by DatumWriter. Applications should not call.
+ public java.lang.Object get(int field$) {
+ switch (field$) {
+ case 0:
+ return name;
+ case 1:
+ return post_abbr;
+ default:
+ throw new IndexOutOfBoundsException("Invalid index: " + field$);
+ }
+ }
+
+ // Used by DatumReader. Applications should not call.
+ @SuppressWarnings(value = "unchecked")
+ public void put(int field$, java.lang.Object value$) {
+ switch (field$) {
+ case 0:
+ name = (java.lang.CharSequence) value$;
+ break;
+ case 1:
+ post_abbr = (java.lang.CharSequence) value$;
+ break;
+ default:
+ throw new IndexOutOfBoundsException("Invalid index: " + field$);
+ }
+ }
+
+ /**
+ * Gets the value of the 'name' field.
+ *
+ * @return The common name of the state.
+ */
+ public java.lang.CharSequence getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the 'name' field. The common name of the state.
+ *
+ * @param value the value to set.
+ */
+ public void setName(java.lang.CharSequence value) {
+ this.name = value;
+ }
+
+ /**
+ * Gets the value of the 'post_abbr' field.
+ *
+ * @return The postal code abbreviation of the state.
+ */
+ public java.lang.CharSequence getPostAbbr() {
+ return post_abbr;
+ }
+
+ /**
+ * Sets the value of the 'post_abbr' field. The postal code abbreviation of the state.
+ *
+ * @param value the value to set.
+ */
+ public void setPostAbbr(java.lang.CharSequence value) {
+ this.post_abbr = value;
+ }
+
+ /**
+ * Creates a new State RecordBuilder.
+ *
+ * @return A new State RecordBuilder
+ */
+ public static utilities.State.Builder newBuilder() {
+ return new utilities.State.Builder();
+ }
+
+ /**
+ * Creates a new State RecordBuilder by copying an existing Builder.
+ *
+ * @param other The existing builder to copy.
+ * @return A new State RecordBuilder
+ */
+ public static utilities.State.Builder newBuilder(utilities.State.Builder other) {
+ if (other == null) {
+ return new utilities.State.Builder();
+ } else {
+ return new utilities.State.Builder(other);
+ }
+ }
+
+ /**
+ * Creates a new State RecordBuilder by copying an existing State instance.
+ *
+ * @param other The existing instance to copy.
+ * @return A new State RecordBuilder
+ */
+ public static utilities.State.Builder newBuilder(utilities.State other) {
+ if (other == null) {
+ return new utilities.State.Builder();
+ } else {
+ return new utilities.State.Builder(other);
+ }
+ }
+
+ /** RecordBuilder for State instances. */
+ @org.apache.avro.specific.AvroGenerated
+ public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase
+ implements org.apache.avro.data.RecordBuilder {
+
+ /** The common name of the state. */
+ private java.lang.CharSequence name;
+ /** The postal code abbreviation of the state. */
+ private java.lang.CharSequence post_abbr;
+
+ /** Creates a new Builder */
+ private Builder() {
+ super(SCHEMA$);
+ }
+
+ /**
+ * Creates a Builder by copying an existing Builder.
+ *
+ * @param other The existing Builder to copy.
+ */
+ private Builder(utilities.State.Builder other) {
+ super(other);
+ if (isValidValue(fields()[0], other.name)) {
+ this.name = data().deepCopy(fields()[0].schema(), other.name);
+ fieldSetFlags()[0] = other.fieldSetFlags()[0];
+ }
+ if (isValidValue(fields()[1], other.post_abbr)) {
+ this.post_abbr = data().deepCopy(fields()[1].schema(), other.post_abbr);
+ fieldSetFlags()[1] = other.fieldSetFlags()[1];
+ }
+ }
+
+ /**
+ * Creates a Builder by copying an existing State instance
+ *
+ * @param other The existing instance to copy.
+ */
+ private Builder(utilities.State other) {
+ super(SCHEMA$);
+ if (isValidValue(fields()[0], other.name)) {
+ this.name = data().deepCopy(fields()[0].schema(), other.name);
+ fieldSetFlags()[0] = true;
+ }
+ if (isValidValue(fields()[1], other.post_abbr)) {
+ this.post_abbr = data().deepCopy(fields()[1].schema(), other.post_abbr);
+ fieldSetFlags()[1] = true;
+ }
+ }
+
+ /**
+ * Gets the value of the 'name' field. The common name of the state.
+ *
+ * @return The value.
+ */
+ public java.lang.CharSequence getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the 'name' field. The common name of the state.
+ *
+ * @param value The value of 'name'.
+ * @return This builder.
+ */
+ public utilities.State.Builder setName(java.lang.CharSequence value) {
+ validate(fields()[0], value);
+ this.name = value;
+ fieldSetFlags()[0] = true;
+ return this;
+ }
+
+ /**
+ * Checks whether the 'name' field has been set. The common name of the state.
+ *
+ * @return True if the 'name' field has been set, false otherwise.
+ */
+ public boolean hasName() {
+ return fieldSetFlags()[0];
+ }
+
+ /**
+ * Clears the value of the 'name' field. The common name of the state.
+ *
+ * @return This builder.
+ */
+ public utilities.State.Builder clearName() {
+ name = null;
+ fieldSetFlags()[0] = false;
+ return this;
+ }
+
+ /**
+ * Gets the value of the 'post_abbr' field. The postal code abbreviation of the state.
+ *
+ * @return The value.
+ */
+ public java.lang.CharSequence getPostAbbr() {
+ return post_abbr;
+ }
+
+ /**
+ * Sets the value of the 'post_abbr' field. The postal code abbreviation of the state.
+ *
+ * @param value The value of 'post_abbr'.
+ * @return This builder.
+ */
+ public utilities.State.Builder setPostAbbr(java.lang.CharSequence value) {
+ validate(fields()[1], value);
+ this.post_abbr = value;
+ fieldSetFlags()[1] = true;
+ return this;
+ }
+
+ /**
+ * Checks whether the 'post_abbr' field has been set. The postal code abbreviation of the state.
+ *
+ * @return True if the 'post_abbr' field has been set, false otherwise.
+ */
+ public boolean hasPostAbbr() {
+ return fieldSetFlags()[1];
+ }
+
+ /**
+ * Clears the value of the 'post_abbr' field. The postal code abbreviation of the state.
+ *
+ * @return This builder.
+ */
+ public utilities.State.Builder clearPostAbbr() {
+ post_abbr = null;
+ fieldSetFlags()[1] = false;
+ return this;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public State build() {
+ try {
+ State record = new State();
+ record.name =
+ fieldSetFlags()[0] ? this.name : (java.lang.CharSequence) defaultValue(fields()[0]);
+ record.post_abbr =
+ fieldSetFlags()[1]
+ ? this.post_abbr
+ : (java.lang.CharSequence) defaultValue(fields()[1]);
+ return record;
+ } catch (org.apache.avro.AvroMissingFieldException e) {
+ throw e;
+ } catch (java.lang.Exception e) {
+ throw new org.apache.avro.AvroRuntimeException(e);
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static final org.apache.avro.io.DatumWriter WRITER$ =
+ (org.apache.avro.io.DatumWriter) MODEL$.createDatumWriter(SCHEMA$);
+
+ @Override
+ public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
+ WRITER$.write(this, SpecificData.getEncoder(out));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static final org.apache.avro.io.DatumReader READER$ =
+ (org.apache.avro.io.DatumReader) MODEL$.createDatumReader(SCHEMA$);
+
+ @Override
+ public void readExternal(java.io.ObjectInput in) throws java.io.IOException {
+ READER$.read(this, SpecificData.getDecoder(in));
+ }
+
+ @Override
+ protected boolean hasCustomCoders() {
+ return true;
+ }
+
+ @Override
+ public void customEncode(org.apache.avro.io.Encoder out) throws java.io.IOException {
+ out.writeString(this.name);
+
+ out.writeString(this.post_abbr);
+ }
+
+ @Override
+ public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException {
+ org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
+ if (fieldOrder == null) {
+ this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null);
+
+ this.post_abbr = in.readString(this.post_abbr instanceof Utf8 ? (Utf8) this.post_abbr : null);
+
+ } else {
+ for (int i = 0; i < 2; i++) {
+ switch (fieldOrder[i].pos()) {
+ case 0:
+ this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null);
+ break;
+
+ case 1:
+ this.post_abbr =
+ in.readString(this.post_abbr instanceof Utf8 ? (Utf8) this.post_abbr : null);
+ break;
+
+ default:
+ throw new java.io.IOException("Corrupt ResolvingDecoder.");
+ }
+ }
+ }
+ }
+}
diff --git a/samples/snippets/src/main/java/utilities/StateProto.java b/samples/snippets/src/main/java/utilities/StateProto.java
new file mode 100644
index 000000000..7afab1ca2
--- /dev/null
+++ b/samples/snippets/src/main/java/utilities/StateProto.java
@@ -0,0 +1,781 @@
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: us-states.proto
+
+package utilities;
+
+public final class StateProto {
+ private StateProto() {}
+
+ public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {}
+
+ public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) {
+ registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry);
+ }
+
+ public interface StateOrBuilder
+ extends
+ // @@protoc_insertion_point(interface_extends:utilities.State)
+ com.google.protobuf.MessageOrBuilder {
+
+ /**
+ * string name = 1;
+ *
+ * @return The name.
+ */
+ java.lang.String getName();
+ /**
+ * string name = 1;
+ *
+ * @return The bytes for name.
+ */
+ com.google.protobuf.ByteString getNameBytes();
+
+ /**
+ * string post_abbr = 2;
+ *
+ * @return The postAbbr.
+ */
+ java.lang.String getPostAbbr();
+ /**
+ * string post_abbr = 2;
+ *
+ * @return The bytes for postAbbr.
+ */
+ com.google.protobuf.ByteString getPostAbbrBytes();
+ }
+ /** Protobuf type {@code utilities.State} */
+ public static final class State extends com.google.protobuf.GeneratedMessageV3
+ implements
+ // @@protoc_insertion_point(message_implements:utilities.State)
+ StateOrBuilder {
+ private static final long serialVersionUID = 0L;
+ // Use State.newBuilder() to construct.
+ private State(com.google.protobuf.GeneratedMessageV3.Builder> builder) {
+ super(builder);
+ }
+
+ private State() {
+ name_ = "";
+ postAbbr_ = "";
+ }
+
+ @java.lang.Override
+ @SuppressWarnings({"unused"})
+ protected java.lang.Object newInstance(UnusedPrivateParameter unused) {
+ return new State();
+ }
+
+ @java.lang.Override
+ public final com.google.protobuf.UnknownFieldSet getUnknownFields() {
+ return this.unknownFields;
+ }
+
+ private State(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ this();
+ if (extensionRegistry == null) {
+ throw new java.lang.NullPointerException();
+ }
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder();
+ try {
+ boolean done = false;
+ while (!done) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ done = true;
+ break;
+ case 10:
+ {
+ java.lang.String s = input.readStringRequireUtf8();
+
+ name_ = s;
+ break;
+ }
+ case 18:
+ {
+ java.lang.String s = input.readStringRequireUtf8();
+
+ postAbbr_ = s;
+ break;
+ }
+ default:
+ {
+ if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
+ done = true;
+ }
+ break;
+ }
+ }
+ }
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(this);
+ } catch (java.io.IOException e) {
+ throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this);
+ } finally {
+ this.unknownFields = unknownFields.build();
+ makeExtensionsImmutable();
+ }
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() {
+ return utilities.StateProto.internal_static_utilities_State_descriptor;
+ }
+
+ @java.lang.Override
+ protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return utilities.StateProto.internal_static_utilities_State_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ utilities.StateProto.State.class, utilities.StateProto.State.Builder.class);
+ }
+
+ public static final int NAME_FIELD_NUMBER = 1;
+ private volatile java.lang.Object name_;
+ /**
+ * string name = 1;
+ *
+ * @return The name.
+ */
+ @java.lang.Override
+ public java.lang.String getName() {
+ java.lang.Object ref = name_;
+ if (ref instanceof java.lang.String) {
+ return (java.lang.String) ref;
+ } else {
+ com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
+ java.lang.String s = bs.toStringUtf8();
+ name_ = s;
+ return s;
+ }
+ }
+ /**
+ * string name = 1;
+ *
+ * @return The bytes for name.
+ */
+ @java.lang.Override
+ public com.google.protobuf.ByteString getNameBytes() {
+ java.lang.Object ref = name_;
+ if (ref instanceof java.lang.String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
+ name_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+
+ public static final int POST_ABBR_FIELD_NUMBER = 2;
+ private volatile java.lang.Object postAbbr_;
+ /**
+ * string post_abbr = 2;
+ *
+ * @return The postAbbr.
+ */
+ @java.lang.Override
+ public java.lang.String getPostAbbr() {
+ java.lang.Object ref = postAbbr_;
+ if (ref instanceof java.lang.String) {
+ return (java.lang.String) ref;
+ } else {
+ com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
+ java.lang.String s = bs.toStringUtf8();
+ postAbbr_ = s;
+ return s;
+ }
+ }
+ /**
+ * string post_abbr = 2;
+ *
+ * @return The bytes for postAbbr.
+ */
+ @java.lang.Override
+ public com.google.protobuf.ByteString getPostAbbrBytes() {
+ java.lang.Object ref = postAbbr_;
+ if (ref instanceof java.lang.String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
+ postAbbr_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+
+ private byte memoizedIsInitialized = -1;
+
+ @java.lang.Override
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized == 1) return true;
+ if (isInitialized == 0) return false;
+
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ @java.lang.Override
+ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException {
+ if (!getNameBytes().isEmpty()) {
+ com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_);
+ }
+ if (!getPostAbbrBytes().isEmpty()) {
+ com.google.protobuf.GeneratedMessageV3.writeString(output, 2, postAbbr_);
+ }
+ unknownFields.writeTo(output);
+ }
+
+ @java.lang.Override
+ public int getSerializedSize() {
+ int size = memoizedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (!getNameBytes().isEmpty()) {
+ size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_);
+ }
+ if (!getPostAbbrBytes().isEmpty()) {
+ size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, postAbbr_);
+ }
+ size += unknownFields.getSerializedSize();
+ memoizedSize = size;
+ return size;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof utilities.StateProto.State)) {
+ return super.equals(obj);
+ }
+ utilities.StateProto.State other = (utilities.StateProto.State) obj;
+
+ if (!getName().equals(other.getName())) return false;
+ if (!getPostAbbr().equals(other.getPostAbbr())) return false;
+ if (!unknownFields.equals(other.unknownFields)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ if (memoizedHashCode != 0) {
+ return memoizedHashCode;
+ }
+ int hash = 41;
+ hash = (19 * hash) + getDescriptor().hashCode();
+ hash = (37 * hash) + NAME_FIELD_NUMBER;
+ hash = (53 * hash) + getName().hashCode();
+ hash = (37 * hash) + POST_ABBR_FIELD_NUMBER;
+ hash = (53 * hash) + getPostAbbr().hashCode();
+ hash = (29 * hash) + unknownFields.hashCode();
+ memoizedHashCode = hash;
+ return hash;
+ }
+
+ public static utilities.StateProto.State parseFrom(java.nio.ByteBuffer data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+
+ public static utilities.StateProto.State parseFrom(
+ java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+
+ public static utilities.StateProto.State parseFrom(com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+
+ public static utilities.StateProto.State parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+
+ public static utilities.StateProto.State parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+
+ public static utilities.StateProto.State parseFrom(
+ byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+
+ public static utilities.StateProto.State parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
+ }
+
+ public static utilities.StateProto.State parseFrom(
+ java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3.parseWithIOException(
+ PARSER, input, extensionRegistry);
+ }
+
+ public static utilities.StateProto.State parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input);
+ }
+
+ public static utilities.StateProto.State parseDelimitedFrom(
+ java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(
+ PARSER, input, extensionRegistry);
+ }
+
+ public static utilities.StateProto.State parseFrom(com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
+ }
+
+ public static utilities.StateProto.State parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return com.google.protobuf.GeneratedMessageV3.parseWithIOException(
+ PARSER, input, extensionRegistry);
+ }
+
+ @java.lang.Override
+ public Builder newBuilderForType() {
+ return newBuilder();
+ }
+
+ public static Builder newBuilder() {
+ return DEFAULT_INSTANCE.toBuilder();
+ }
+
+ public static Builder newBuilder(utilities.StateProto.State prototype) {
+ return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
+ }
+
+ @java.lang.Override
+ public Builder toBuilder() {
+ return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this);
+ }
+
+ @java.lang.Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ /** Protobuf type {@code utilities.State} */
+ public static final class Builder
+ extends com.google.protobuf.GeneratedMessageV3.Builder
+ implements
+ // @@protoc_insertion_point(builder_implements:utilities.State)
+ utilities.StateProto.StateOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() {
+ return utilities.StateProto.internal_static_utilities_State_descriptor;
+ }
+
+ @java.lang.Override
+ protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return utilities.StateProto.internal_static_utilities_State_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ utilities.StateProto.State.class, utilities.StateProto.State.Builder.class);
+ }
+
+ // Construct using utilities.StateProto.State.newBuilder()
+ private Builder() {
+ maybeForceBuilderInitialization();
+ }
+
+ private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
+ super(parent);
+ maybeForceBuilderInitialization();
+ }
+
+ private void maybeForceBuilderInitialization() {
+ if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) {}
+ }
+
+ @java.lang.Override
+ public Builder clear() {
+ super.clear();
+ name_ = "";
+
+ postAbbr_ = "";
+
+ return this;
+ }
+
+ @java.lang.Override
+ public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() {
+ return utilities.StateProto.internal_static_utilities_State_descriptor;
+ }
+
+ @java.lang.Override
+ public utilities.StateProto.State getDefaultInstanceForType() {
+ return utilities.StateProto.State.getDefaultInstance();
+ }
+
+ @java.lang.Override
+ public utilities.StateProto.State build() {
+ utilities.StateProto.State result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ @java.lang.Override
+ public utilities.StateProto.State buildPartial() {
+ utilities.StateProto.State result = new utilities.StateProto.State(this);
+ result.name_ = name_;
+ result.postAbbr_ = postAbbr_;
+ onBuilt();
+ return result;
+ }
+
+ @java.lang.Override
+ public Builder clone() {
+ return super.clone();
+ }
+
+ @java.lang.Override
+ public Builder setField(
+ com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) {
+ return super.setField(field, value);
+ }
+
+ @java.lang.Override
+ public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) {
+ return super.clearField(field);
+ }
+
+ @java.lang.Override
+ public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) {
+ return super.clearOneof(oneof);
+ }
+
+ @java.lang.Override
+ public Builder setRepeatedField(
+ com.google.protobuf.Descriptors.FieldDescriptor field,
+ int index,
+ java.lang.Object value) {
+ return super.setRepeatedField(field, index, value);
+ }
+
+ @java.lang.Override
+ public Builder addRepeatedField(
+ com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) {
+ return super.addRepeatedField(field, value);
+ }
+
+ @java.lang.Override
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof utilities.StateProto.State) {
+ return mergeFrom((utilities.StateProto.State) other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(utilities.StateProto.State other) {
+ if (other == utilities.StateProto.State.getDefaultInstance()) return this;
+ if (!other.getName().isEmpty()) {
+ name_ = other.name_;
+ onChanged();
+ }
+ if (!other.getPostAbbr().isEmpty()) {
+ postAbbr_ = other.postAbbr_;
+ onChanged();
+ }
+ this.mergeUnknownFields(other.unknownFields);
+ onChanged();
+ return this;
+ }
+
+ @java.lang.Override
+ public final boolean isInitialized() {
+ return true;
+ }
+
+ @java.lang.Override
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ utilities.StateProto.State parsedMessage = null;
+ try {
+ parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ parsedMessage = (utilities.StateProto.State) e.getUnfinishedMessage();
+ throw e.unwrapIOException();
+ } finally {
+ if (parsedMessage != null) {
+ mergeFrom(parsedMessage);
+ }
+ }
+ return this;
+ }
+
+ private java.lang.Object name_ = "";
+ /**
+ * string name = 1;
+ *
+ * @return The name.
+ */
+ public java.lang.String getName() {
+ java.lang.Object ref = name_;
+ if (!(ref instanceof java.lang.String)) {
+ com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
+ java.lang.String s = bs.toStringUtf8();
+ name_ = s;
+ return s;
+ } else {
+ return (java.lang.String) ref;
+ }
+ }
+ /**
+ * string name = 1;
+ *
+ * @return The bytes for name.
+ */
+ public com.google.protobuf.ByteString getNameBytes() {
+ java.lang.Object ref = name_;
+ if (ref instanceof String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
+ name_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+ /**
+ * string name = 1;
+ *
+ * @param value The name to set.
+ * @return This builder for chaining.
+ */
+ public Builder setName(java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+
+ name_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * string name = 1;
+ *
+ * @return This builder for chaining.
+ */
+ public Builder clearName() {
+
+ name_ = getDefaultInstance().getName();
+ onChanged();
+ return this;
+ }
+ /**
+ * string name = 1;
+ *
+ * @param value The bytes for name to set.
+ * @return This builder for chaining.
+ */
+ public Builder setNameBytes(com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ checkByteStringIsUtf8(value);
+
+ name_ = value;
+ onChanged();
+ return this;
+ }
+
+ private java.lang.Object postAbbr_ = "";
+ /**
+ * string post_abbr = 2;
+ *
+ * @return The postAbbr.
+ */
+ public java.lang.String getPostAbbr() {
+ java.lang.Object ref = postAbbr_;
+ if (!(ref instanceof java.lang.String)) {
+ com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
+ java.lang.String s = bs.toStringUtf8();
+ postAbbr_ = s;
+ return s;
+ } else {
+ return (java.lang.String) ref;
+ }
+ }
+ /**
+ * string post_abbr = 2;
+ *
+ * @return The bytes for postAbbr.
+ */
+ public com.google.protobuf.ByteString getPostAbbrBytes() {
+ java.lang.Object ref = postAbbr_;
+ if (ref instanceof String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
+ postAbbr_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+ /**
+ * string post_abbr = 2;
+ *
+ * @param value The postAbbr to set.
+ * @return This builder for chaining.
+ */
+ public Builder setPostAbbr(java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+
+ postAbbr_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * string post_abbr = 2;
+ *
+ * @return This builder for chaining.
+ */
+ public Builder clearPostAbbr() {
+
+ postAbbr_ = getDefaultInstance().getPostAbbr();
+ onChanged();
+ return this;
+ }
+ /**
+ * string post_abbr = 2;
+ *
+ * @param value The bytes for postAbbr to set.
+ * @return This builder for chaining.
+ */
+ public Builder setPostAbbrBytes(com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ checkByteStringIsUtf8(value);
+
+ postAbbr_ = value;
+ onChanged();
+ return this;
+ }
+
+ @java.lang.Override
+ public final Builder setUnknownFields(
+ final com.google.protobuf.UnknownFieldSet unknownFields) {
+ return super.setUnknownFields(unknownFields);
+ }
+
+ @java.lang.Override
+ public final Builder mergeUnknownFields(
+ final com.google.protobuf.UnknownFieldSet unknownFields) {
+ return super.mergeUnknownFields(unknownFields);
+ }
+
+ // @@protoc_insertion_point(builder_scope:utilities.State)
+ }
+
+ // @@protoc_insertion_point(class_scope:utilities.State)
+ private static final utilities.StateProto.State DEFAULT_INSTANCE;
+
+ static {
+ DEFAULT_INSTANCE = new utilities.StateProto.State();
+ }
+
+ public static utilities.StateProto.State getDefaultInstance() {
+ return DEFAULT_INSTANCE;
+ }
+
+ private static final com.google.protobuf.Parser PARSER =
+ new com.google.protobuf.AbstractParser() {
+ @java.lang.Override
+ public State parsePartialFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return new State(input, extensionRegistry);
+ }
+ };
+
+ public static com.google.protobuf.Parser parser() {
+ return PARSER;
+ }
+
+ @java.lang.Override
+ public com.google.protobuf.Parser getParserForType() {
+ return PARSER;
+ }
+
+ @java.lang.Override
+ public utilities.StateProto.State getDefaultInstanceForType() {
+ return DEFAULT_INSTANCE;
+ }
+ }
+
+ private static final com.google.protobuf.Descriptors.Descriptor
+ internal_static_utilities_State_descriptor;
+ private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
+ internal_static_utilities_State_fieldAccessorTable;
+
+ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() {
+ return descriptor;
+ }
+
+ private static com.google.protobuf.Descriptors.FileDescriptor descriptor;
+
+ static {
+ java.lang.String[] descriptorData = {
+ "\n\017us-states.proto\022\tutilities\"(\n\005State\022\014\n"
+ + "\004name\030\001 \001(\t\022\021\n\tpost_abbr\030\002 \001(\tB\014B\nStateP"
+ + "rotob\006proto3"
+ };
+ descriptor =
+ com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(
+ descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {});
+ internal_static_utilities_State_descriptor = getDescriptor().getMessageTypes().get(0);
+ internal_static_utilities_State_fieldAccessorTable =
+ new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
+ internal_static_utilities_State_descriptor,
+ new java.lang.String[] {
+ "Name", "PostAbbr",
+ });
+ }
+
+ // @@protoc_insertion_point(outer_class_scope)
+}
diff --git a/samples/snippets/src/main/resources/us-states.avsc b/samples/snippets/src/main/resources/us-states.avsc
new file mode 100644
index 000000000..7521882c7
--- /dev/null
+++ b/samples/snippets/src/main/resources/us-states.avsc
@@ -0,0 +1,18 @@
+{
+ "type":"record",
+ "name":"State",
+ "namespace":"utilities",
+ "doc":"A list of states in the United States of America.",
+ "fields":[
+ {
+ "name":"name",
+ "type":"string",
+ "doc":"The common name of the state."
+ },
+ {
+ "name":"post_abbr",
+ "type":"string",
+ "doc":"The postal code abbreviation of the state."
+ }
+ ]
+}
\ No newline at end of file
diff --git a/samples/snippets/src/main/resources/us-states.proto b/samples/snippets/src/main/resources/us-states.proto
new file mode 100644
index 000000000..819387558
--- /dev/null
+++ b/samples/snippets/src/main/resources/us-states.proto
@@ -0,0 +1,9 @@
+syntax = "proto3";
+
+package utilities;
+option java_outer_classname = "StateProto";
+
+message State {
+ string name = 1;
+ string post_abbr = 2;
+}
\ No newline at end of file
diff --git a/samples/snippets/src/test/java/pubsub/AdminIT.java b/samples/snippets/src/test/java/pubsub/AdminIT.java
index 42825d63a..1d198044d 100644
--- a/samples/snippets/src/test/java/pubsub/AdminIT.java
+++ b/samples/snippets/src/test/java/pubsub/AdminIT.java
@@ -183,7 +183,6 @@ public void testAdmin() throws Exception {
assertThat(bout.toString()).contains("Created a subscription with ordering");
assertThat(bout.toString()).contains("enable_message_ordering=true");
-
bout.reset();
// Test delete subscription. Run twice to delete both pull and push subscriptions.
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, pullSubscriptionId);
diff --git a/samples/snippets/src/test/java/pubsub/SchemaIT.java b/samples/snippets/src/test/java/pubsub/SchemaIT.java
new file mode 100644
index 000000000..45e899619
--- /dev/null
+++ b/samples/snippets/src/test/java/pubsub/SchemaIT.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pubsub;
+
+import static com.google.common.truth.Truth.assertThat;
+import static junit.framework.TestCase.assertNotNull;
+
+import com.google.api.gax.rpc.NotFoundException;
+import com.google.cloud.pubsub.v1.SchemaServiceClient;
+import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
+import com.google.cloud.pubsub.v1.TopicAdminClient;
+import com.google.pubsub.v1.Encoding;
+import com.google.pubsub.v1.ProjectSubscriptionName;
+import com.google.pubsub.v1.SchemaName;
+import com.google.pubsub.v1.TopicName;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.PrintStream;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.Timeout;
+
+public class SchemaIT {
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ private static final String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static final String _suffix = UUID.randomUUID().toString();
+ private static final String avroTopicId = "avro-topic-" + _suffix;
+ private static final String protoTopicId = "proto-topic-" + _suffix;
+ private static final String avroSubscriptionId = "avro-subscription-" + _suffix;
+ private static final String protoSubscriptionId = "proto-subscription-" + _suffix;
+ private static final String avroSchemaId = "avro-schema-" + _suffix;
+ private static final String protoSchemaId = "proto-schema-" + _suffix;
+
+ ClassLoader classLoader = getClass().getClassLoader();
+ File avscFile = new File(classLoader.getResource("us-states.avsc").getFile());
+ String absoluteAvscFilePath = avscFile.getAbsolutePath();
+
+ File protoFile = new File(classLoader.getResource("us-states.proto").getFile());
+ String absoluteProtoFilePath = protoFile.getAbsolutePath();
+
+ private static final TopicName avroTopicName = TopicName.of(projectId, avroTopicId);
+ private static final TopicName protoTopicName = TopicName.of(projectId, protoTopicId);
+ private static final ProjectSubscriptionName avroSubscriptionName =
+ ProjectSubscriptionName.of(projectId, avroSubscriptionId);
+ private static final ProjectSubscriptionName protoSubscriptionName =
+ ProjectSubscriptionName.of(projectId, protoSubscriptionId);
+ private static final SchemaName avroSchemaName = SchemaName.of(projectId, avroSchemaId);
+ private static final SchemaName protoSchemaName = SchemaName.of(projectId, protoSchemaId);
+
+ private static void requireEnvVar(String varName) {
+ assertNotNull(
+ "Environment variable " + varName + " is required to perform these tests.",
+ System.getenv(varName));
+ }
+
+ @Rule public Timeout globalTimeout = Timeout.seconds(300); // 5 minute timeout
+
+ @BeforeClass
+ public static void checkRequirements() {
+ requireEnvVar("GOOGLE_CLOUD_PROJECT");
+ }
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ // Delete the schemas if they have not been cleaned up.
+ try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
+ schemaServiceClient.deleteSchema(protoSchemaName);
+ schemaServiceClient.deleteSchema(avroSchemaName);
+ } catch (NotFoundException ignored) {
+ // Ignore this as resources may have already been cleaned up.
+ }
+
+ // Delete the subscriptions.
+ try (SubscriptionAdminClient subscriptionAdmin = SubscriptionAdminClient.create()) {
+ subscriptionAdmin.deleteSubscription(avroSubscriptionName.toString());
+ subscriptionAdmin.deleteSubscription(protoSubscriptionName.toString());
+ } catch (NotFoundException ignored) {
+ // Ignore this as resources may have already been cleaned up.
+ }
+
+ // Delete the topics.
+ try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
+ topicAdminClient.deleteTopic(avroTopicName.toString());
+ topicAdminClient.deleteTopic(protoTopicName.toString());
+ } catch (NotFoundException ignored) {
+ // Ignore this as resources may have already been cleaned up.
+ }
+ System.setOut(null);
+ }
+
+ @Test
+ public void testSchema() throws Exception {
+ // Test creating Avro schema.
+ CreateAvroSchemaExample.createAvroSchemaExample(projectId, avroSchemaId, absoluteAvscFilePath);
+ assertThat(bout.toString()).contains("Created a schema using an Avro schema:");
+ assertThat(bout.toString()).contains(avroSchemaName.toString());
+
+ // Test creating Proto schema.
+ CreateProtoSchemaExample.createProtoSchemaExample(
+ projectId, protoSchemaId, absoluteProtoFilePath);
+ assertThat(bout.toString()).contains("Created a schema using a protobuf schema:");
+ assertThat(bout.toString()).contains(protoSchemaName.toString());
+
+ bout.reset();
+ // Test getting a schema.
+ GetSchemaExample.getSchemaExample(projectId, avroSchemaId);
+ assertThat(bout.toString()).contains("Got a schema:");
+ assertThat(bout.toString()).contains(avroSchemaName.toString());
+
+ bout.reset();
+ // Test listing schemas.
+ ListSchemasExample.listSchemasExample(projectId);
+ assertThat(bout.toString()).contains("Listed schemas.");
+ assertThat(bout.toString()).contains(avroSchemaName.toString());
+
+ bout.reset();
+ // Test creating a topic with an Avro schema with BINARY encoding.
+ CreateTopicWithSchemaExample.createTopicWithSchemaExample(
+ projectId, avroTopicId, avroSchemaId, Encoding.BINARY);
+ assertThat(bout.toString()).contains("Created topic with schema: " + avroTopicName.toString());
+
+ bout.reset();
+ // Test creating a topic with a proto schema with JSON encoding.
+ CreateTopicWithSchemaExample.createTopicWithSchemaExample(
+ projectId, protoTopicId, protoSchemaId, Encoding.JSON);
+ assertThat(bout.toString()).contains("Created topic with schema: " + protoTopicName.toString());
+
+ // Attach a default pull subscription to each topic.
+ CreatePullSubscriptionExample.createPullSubscriptionExample(
+ projectId, avroSubscriptionId, avroTopicId);
+ CreatePullSubscriptionExample.createPullSubscriptionExample(
+ projectId, protoSubscriptionId, protoTopicId);
+
+ bout.reset();
+ // Test publishing BINARY-encoded Avro records.
+ PublishAvroRecordsExample.publishAvroRecordsExample(projectId, avroTopicId);
+ assertThat(bout.toString()).contains("Preparing a BINARY encoder...");
+ assertThat(bout.toString()).contains("Published message ID:");
+
+ bout.reset();
+ // Test publishing JSON-encoded proto messages.
+ PublishProtobufMessagesExample.publishProtobufMessagesExample(projectId, protoTopicId);
+ assertThat(bout.toString()).contains("Publishing a JSON-formatted message:");
+ assertThat(bout.toString()).contains("Published message ID:");
+
+ bout.reset();
+ // Test receiving BINARY-encoded Avro records.
+ SubscribeWithAvroSchemaExample.subscribeWithAvroSchemaExample(projectId, avroSubscriptionId);
+ assertThat(bout.toString()).contains("Receiving a binary-encoded message:");
+ assertThat(bout.toString()).contains(" is abbreviated as ");
+
+ bout.reset();
+ // Test receiving JSON-encoded proto messages.
+ SubscribeWithProtoSchemaExample.subscribeWithProtoSchemaExample(projectId, protoSubscriptionId);
+ assertThat(bout.toString()).contains("Received a JSON-formatted message:");
+ assertThat(bout.toString()).contains("Ack'ed the message");
+
+ bout.reset();
+ // Test deleting a schema.
+ DeleteSchemaExample.deleteSchemaExample(projectId, avroSchemaId);
+ assertThat(bout.toString()).contains("Deleted a schema:");
+ assertThat(bout.toString()).contains(avroSchemaName.toString());
+ }
+}
diff --git a/samples/snippets/src/test/resources/us-states.avsc b/samples/snippets/src/test/resources/us-states.avsc
new file mode 100644
index 000000000..7521882c7
--- /dev/null
+++ b/samples/snippets/src/test/resources/us-states.avsc
@@ -0,0 +1,18 @@
+{
+ "type":"record",
+ "name":"State",
+ "namespace":"utilities",
+ "doc":"A list of states in the United States of America.",
+ "fields":[
+ {
+ "name":"name",
+ "type":"string",
+ "doc":"The common name of the state."
+ },
+ {
+ "name":"post_abbr",
+ "type":"string",
+ "doc":"The postal code abbreviation of the state."
+ }
+ ]
+}
\ No newline at end of file
diff --git a/samples/snippets/src/test/resources/us-states.proto b/samples/snippets/src/test/resources/us-states.proto
new file mode 100644
index 000000000..819387558
--- /dev/null
+++ b/samples/snippets/src/test/resources/us-states.proto
@@ -0,0 +1,9 @@
+syntax = "proto3";
+
+package utilities;
+option java_outer_classname = "StateProto";
+
+message State {
+ string name = 1;
+ string post_abbr = 2;
+}
\ No newline at end of file
From 9f95e90948d7f8f076e95e9e59f3e3593df6155d Mon Sep 17 00:00:00 2001
From: Yoshi Automation Bot
Date: Wed, 24 Feb 2021 10:02:03 -0800
Subject: [PATCH 07/11] chore: regenerate README (#523)
This PR was generated using Autosynth. :rainbow:
Log from Synthtool
```
2021-02-24 17:47:45,183 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-pubsub/.github/readme/synth.py.
On branch autosynth-readme
nothing to commit, working tree clean
2021-02-24 17:47:46,809 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata.
```
Full log will be available here:
https://source.cloud.google.com/results/invocations/befb92b0-6e17-4478-a77c-3b6600ad2335/targets
- [ ] To automatically regenerate this PR, check this box.
---
.github/readme/synth.metadata/synth.metadata | 2 +-
README.md | 15 ++++++++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/.github/readme/synth.metadata/synth.metadata b/.github/readme/synth.metadata/synth.metadata
index 27d1905c9..692be94f5 100644
--- a/.github/readme/synth.metadata/synth.metadata
+++ b/.github/readme/synth.metadata/synth.metadata
@@ -4,7 +4,7 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/java-pubsub.git",
- "sha": "87f081f5ccadc01ea4d3c5fe188d5e1b6ba32fbe"
+ "sha": "a71e898ebe768f07966a13779c890818e9dad694"
}
},
{
diff --git a/README.md b/README.md
index d520c5d4c..a427555a1 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file
com.google.cloud
google-cloud-pubsub
+ 1.111.0
```
@@ -45,7 +46,7 @@ If you are using Maven without BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies
```Groovy
-implementation platform('com.google.cloud:libraries-bom:16.4.0')
+implementation platform('com.google.cloud:libraries-bom:17.0.0')
compile 'com.google.cloud:google-cloud-pubsub'
```
@@ -229,19 +230,27 @@ has instructions for running the samples.
| Sample | Source Code | Try it |
| --------------------------- | --------------------------------- | ------ |
+| Create Avro Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java) |
+| Create Proto Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java) |
| Create Pull Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java) |
| Create Push Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreatePushSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreatePushSubscriptionExample.java) |
| Create Subscription With Dead Letter Policy Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithDeadLetterPolicyExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateSubscriptionWithDeadLetterPolicyExample.java) |
| Create Subscription With Ordering | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithOrdering.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateSubscriptionWithOrdering.java) |
| Create Topic Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreateTopicExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateTopicExample.java) |
+| Create Topic With Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreateTopicWithSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateTopicWithSchemaExample.java) |
+| Delete Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/DeleteSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/DeleteSchemaExample.java) |
| Delete Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/DeleteSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/DeleteSubscriptionExample.java) |
| Delete Topic Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/DeleteTopicExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/DeleteTopicExample.java) |
| Detach Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/DetachSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/DetachSubscriptionExample.java) |
+| Get Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/GetSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/GetSchemaExample.java) |
| Get Subscription Policy Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/GetSubscriptionPolicyExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/GetSubscriptionPolicyExample.java) |
| Get Topic Policy Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/GetTopicPolicyExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/GetTopicPolicyExample.java) |
+| List Schemas Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/ListSchemasExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/ListSchemasExample.java) |
| List Subscriptions In Project Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/ListSubscriptionsInProjectExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/ListSubscriptionsInProjectExample.java) |
| List Subscriptions In Topic Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/ListSubscriptionsInTopicExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/ListSubscriptionsInTopicExample.java) |
| List Topics Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/ListTopicsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/ListTopicsExample.java) |
+| Publish Avro Records Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/PublishAvroRecordsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/PublishAvroRecordsExample.java) |
+| Publish Protobuf Messages Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/PublishProtobufMessagesExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/PublishProtobufMessagesExample.java) |
| Publish With Batch Settings Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/PublishWithBatchSettingsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/PublishWithBatchSettingsExample.java) |
| Publish With Concurrency Control Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/PublishWithConcurrencyControlExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/PublishWithConcurrencyControlExample.java) |
| Publish With Custom Attributes Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/PublishWithCustomAttributesExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/PublishWithCustomAttributesExample.java) |
@@ -257,14 +266,18 @@ has instructions for running the samples.
| Subscribe Async Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeAsyncExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeAsyncExample.java) |
| Subscribe Sync Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeSyncExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeSyncExample.java) |
| Subscribe Sync With Lease Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeSyncWithLeaseExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeSyncWithLeaseExample.java) |
+| Subscribe With Avro Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeWithAvroSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithAvroSchemaExample.java) |
| Subscribe With Concurrency Control Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeWithConcurrencyControlExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithConcurrencyControlExample.java) |
| Subscribe With Custom Attributes Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeWithCustomAttributesExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithCustomAttributesExample.java) |
| Subscribe With Error Listener Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeWithErrorListenerExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithErrorListenerExample.java) |
| Subscribe With Flow Control Settings Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeWithFlowControlSettingsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithFlowControlSettingsExample.java) |
+| Subscribe With Proto Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeWithProtoSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithProtoSchemaExample.java) |
| Test Subscription Permissions Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/TestSubscriptionPermissionsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/TestSubscriptionPermissionsExample.java) |
| Test Topic Permissions Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/TestTopicPermissionsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/TestTopicPermissionsExample.java) |
| Update Dead Letter Policy Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/UpdateDeadLetterPolicyExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/UpdateDeadLetterPolicyExample.java) |
| Update Push Configuration Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/UpdatePushConfigurationExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/UpdatePushConfigurationExample.java) |
+| State | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/utilities/State.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/utilities/State.java) |
+| State Proto | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/utilities/StateProto.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/utilities/StateProto.java) |
From c1642a5fb732eda9bbb00d1cabae50fc3d03dec3 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Wed, 24 Feb 2021 19:02:38 +0100
Subject: [PATCH 08/11] chore(deps): update dependency
com.google.cloud:libraries-bom to v17 (#522)
---
samples/snippets/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index a578bfadf..d44a8e465 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -45,7 +45,7 @@
com.google.cloud
libraries-bom
- 16.4.0
+ 17.0.0
pom
import
From 868060214e0f1f3da770d9160753794680b761e9 Mon Sep 17 00:00:00 2001
From: Yoshi Automation Bot
Date: Wed, 24 Feb 2021 10:16:03 -0800
Subject: [PATCH 09/11] chore: regenerate README (#525)
This PR was generated using Autosynth. :rainbow:
Log from Synthtool
```
2021-02-24 18:04:44,617 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-pubsub/.github/readme/synth.py.
On branch autosynth-readme
nothing to commit, working tree clean
2021-02-24 18:04:46,208 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata.
```
Full log will be available here:
https://source.cloud.google.com/results/invocations/d41edf21-6233-4fc3-bb67-99b8c66e4b94/targets
- [ ] To automatically regenerate this PR, check this box.
---
.github/readme/synth.metadata/synth.metadata | 2 +-
README.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/readme/synth.metadata/synth.metadata b/.github/readme/synth.metadata/synth.metadata
index 692be94f5..d7583f371 100644
--- a/.github/readme/synth.metadata/synth.metadata
+++ b/.github/readme/synth.metadata/synth.metadata
@@ -4,7 +4,7 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/java-pubsub.git",
- "sha": "a71e898ebe768f07966a13779c890818e9dad694"
+ "sha": "c1642a5fb732eda9bbb00d1cabae50fc3d03dec3"
}
},
{
diff --git a/README.md b/README.md
index a427555a1..153aaf6ef 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file
com.google.cloud
libraries-bom
- 16.4.0
+ 17.0.0
pom
import
From b5e07a866f096744feafc6187bcb022669f5fa26 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Wed, 24 Feb 2021 19:54:12 +0100
Subject: [PATCH 10/11] deps: update dependency
com.google.protobuf:protobuf-java-util to v3.15.2 (#524)
---
samples/install-without-bom/pom.xml | 2 +-
samples/snapshot/pom.xml | 2 +-
samples/snippets/pom.xml | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index 9df2bb003..b1f9c28d6 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -75,7 +75,7 @@
com.google.protobuf
protobuf-java-util
- 3.14.0
+ 3.15.2