27
27
import java .util .Objects ;
28
28
29
29
/**
30
- * PubSub subscription push configuration.
30
+ * Google Cloud Pub/Sub configuration for a push subscription.
31
+ *
32
+ * <p>In a push subscription, the Pub/Sub server sends a request to the subscriber application. A
33
+ * {@code PushConfig} object can be used to configure the application endpoint. The subscriber's
34
+ * HTTP response serves as an implicit acknowledgement: a success response indicates that the
35
+ * message has been succesfully processed and the Pub/Sub system can delete it from the
36
+ * subscription; a non-success response indicates that the Pub/Sub server should resend it
37
+ * (implicit "nack").
38
+ *
39
+ * @see <a href="https://cloud.google.com/pubsub/subscriber">Subscriber Guide</a>
31
40
*/
32
41
public final class PushConfig implements Serializable {
33
42
@@ -36,34 +45,97 @@ public final class PushConfig implements Serializable {
36
45
private final String endpoint ;
37
46
private final ImmutableMap <String , String > attributes ;
38
47
48
+ /**
49
+ * Builder for {@code PushConfig} objects.
50
+ */
39
51
public static final class Builder {
40
52
41
53
private String endpoint ;
42
- private final Map <String , String > attributes = new HashMap <>();
54
+ private Map <String , String > attributes = new HashMap <>();
43
55
44
56
private Builder () {
45
57
}
46
58
47
- public Builder endPoint (String endpoint ) {
59
+ /**
60
+ * Sets the URL locating the endpoint to which messages should be pushed. For example, an
61
+ * endpoint might use {@code https://example.com/push}.
62
+ */
63
+ public Builder endpoint (String endpoint ) {
48
64
this .endpoint = checkNotNull (endpoint );
49
65
return this ;
50
66
}
51
67
68
+ /**
69
+ * Adds an API-supported attribute that can be used to control different aspects of the message
70
+ * delivery.
71
+ *
72
+ * <p>The currently supported attribute is {@code x-goog-version}, which can be used to change
73
+ * the format of the push message. This attribute indicates the version of the data expected by
74
+ * the endpoint. The endpoint version is based on the version of the Pub/Sub API. Possible
75
+ * values for this attribute are:
76
+ * <ul>
77
+ * <li>{@code v1beta1}: uses the push format defined in the v1beta1 Pub/Sub API
78
+ * <li>{@code v1} or {@code v1beta2}: uses the push format defined in the v1 Pub/Sub API
79
+ * </ul>
80
+ *
81
+ * <p>If the {@code x-goog-version} attribute is not present when a subscription is created (see
82
+ * {@link PubSub#create(SubscriptionInfo)} and {@link PubSub#createAsync(SubscriptionInfo)}), it
83
+ * will default to {@code v1}. If it is not present when modifying the push config (see
84
+ * {@link PubSub#replacePushConfig(String, PushConfig)} and
85
+ * {@link PubSub#replacePushConfigAsync(String, PushConfig)}), its value will not be changed.
86
+ *
87
+ * @see <a href="https://cloud.google.com/pubsub/subscriber#msg-format">Message Format</a>
88
+ */
52
89
public Builder addAttribute (String name , String value ) {
53
90
attributes .put (name , value );
54
91
return this ;
55
92
}
56
93
94
+ /**
95
+ * Sets the API-supported attributes that can be used to control different aspects of the
96
+ * message delivery.
97
+ *
98
+ * <p>The currently supported attribute is {@code x-goog-version}, which can be used to change
99
+ * the format of the push message. This attribute indicates the version of the data expected by
100
+ * the endpoint. The endpoint version is based on the version of the Pub/Sub API. Possible
101
+ * values for this attribute are:
102
+ * <ul>
103
+ * <li>{@code v1beta1}: uses the push format defined in the v1beta1 Pub/Sub API
104
+ * <li>{@code v1} or {@code v1beta2}: uses the push format defined in the v1 Pub/Sub API
105
+ * </ul>
106
+ *
107
+ * <p>If the {@code x-goog-version} attribute is not present when a subscription is created (see
108
+ * {@link PubSub#create(SubscriptionInfo)} and {@link PubSub#createAsync(SubscriptionInfo)}), it
109
+ * will default to {@code v1}. If it is not present when modifying the push config (see
110
+ * {@link PubSub#replacePushConfig(String, PushConfig)} and
111
+ * {@link PubSub#replacePushConfigAsync(String, PushConfig)}), its value will not be changed.
112
+ *
113
+ * @see <a href="https://cloud.google.com/pubsub/subscriber#msg-format">Message Format</a>
114
+ */
115
+ public Builder attributes (Map <String , String > attributes ) {
116
+ this .attributes = new HashMap <>(attributes );
117
+ return this ;
118
+ }
119
+
120
+ /**
121
+ * Removes an API-supported attribute.
122
+ */
57
123
public Builder removeAttribute (String name ) {
58
124
attributes .remove (name );
59
125
return this ;
60
126
}
61
127
128
+ /**
129
+ * Clears all API-supported attributes.
130
+ */
62
131
public Builder clearAttributes () {
63
132
attributes .clear ();
64
133
return this ;
65
134
}
66
135
136
+ /**
137
+ * Creates a {@code PushConfig} object.
138
+ */
67
139
public PushConfig build () {
68
140
return new PushConfig (this );
69
141
}
@@ -74,24 +146,49 @@ private PushConfig(Builder builder) {
74
146
attributes = ImmutableMap .copyOf (builder .attributes );
75
147
}
76
148
149
+ /**
150
+ * Returns the URL locating the endpoint to which messages should be pushed. For example, an
151
+ * endpoint might use {@code https://example.com/push}.
152
+ */
77
153
public String endpoint () {
78
154
return endpoint ;
79
155
}
80
156
157
+ /**
158
+ * Returns the API-supported attributes that can be used to control different aspects of the
159
+ * message delivery.
160
+ *
161
+ * <p>The currently supported attribute is {@code x-goog-version}, which can be used to change
162
+ * the format of the push message. This attribute indicates the version of the data expected by
163
+ * the endpoint. The endpoint version is based on the version of the Pub/Sub API. Possible
164
+ * values for this attribute are:
165
+ * <ul>
166
+ * <li>{@code v1beta1}: uses the push format defined in the v1beta1 Pub/Sub API
167
+ * <li>{@code v1} or {@code v1beta2}: uses the push format defined in the v1 Pub/Sub API
168
+ * </ul>
169
+ *
170
+ * <p>If the {@code x-goog-version} attribute is not present when a subscription is created (see
171
+ * {@link PubSub#create(SubscriptionInfo)} and {@link PubSub#createAsync(SubscriptionInfo)}), it
172
+ * will default to {@code v1}. If it is not present when modifying the push config (see
173
+ * {@link PubSub#replacePushConfig(String, PushConfig)} and
174
+ * {@link PubSub#replacePushConfigAsync(String, PushConfig)}), its value will not be changed.
175
+ *
176
+ * @see <a href="https://cloud.google.com/pubsub/subscriber#msg-format">Message Format</a>
177
+ */
81
178
public Map <String , String > attributes () {
82
179
return attributes ;
83
180
}
84
181
85
182
@ Override
86
- public boolean equals (Object o ) {
87
- if (this == o ) {
183
+ public boolean equals (Object obj ) {
184
+ if (this == obj ) {
88
185
return true ;
89
186
}
90
- if (o == null || getClass () != o . getClass ( )) {
187
+ if (!( obj instanceof PushConfig )) {
91
188
return false ;
92
189
}
93
- PushConfig that = (PushConfig ) o ;
94
- return Objects .equals (endpoint , that .endpoint ) && Objects .equals (attributes , that .attributes );
190
+ PushConfig other = (PushConfig ) obj ;
191
+ return Objects .equals (endpoint , other .endpoint ) && Objects .equals (attributes , other .attributes );
95
192
}
96
193
97
194
@ Override
@@ -107,28 +204,57 @@ public String toString() {
107
204
.toString ();
108
205
}
109
206
207
+ /**
208
+ * Returns a builder for the {@code PushConfig} object.
209
+ */
110
210
public Builder toBuilder () {
111
211
return builder (endpoint , attributes );
112
212
}
113
213
214
+ /**
215
+ * Creates a {@code PushConfig} object given the push endpoint.
216
+ *
217
+ * @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
218
+ * an endpoint might use {@code https://example.com/push}.
219
+ */
114
220
public static PushConfig of (String endpoint ) {
115
221
return builder (endpoint ).build ();
116
222
}
117
223
224
+ /**
225
+ * Creates a {@code PushConfig} object given the push endpoint and the API-supported attributes
226
+ * that can be used to control different aspects of the message delivery.
227
+ *
228
+ * @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
229
+ * an endpoint might use {@code https://example.com/push}.
230
+ * @param attributes API supported attributes used to control message delivery. See
231
+ * {@link Builder#attributes(Map)} for more details.
232
+ */
118
233
public static PushConfig of (String endpoint , Map <String , String > attributes ) {
119
234
return builder (endpoint , attributes ).build ();
120
235
}
121
236
122
- public static Builder builder (String endPoint ) {
123
- return new Builder ().endPoint (endPoint );
237
+ /**
238
+ * Creates a builder for {@code PushConfig} objects given the push endpoint.
239
+ *
240
+ * @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
241
+ * an endpoint might use {@code https://example.com/push}.
242
+ */
243
+ public static Builder builder (String endpoint ) {
244
+ return new Builder ().endpoint (endpoint );
124
245
}
125
246
247
+ /**
248
+ * Creates a builder for {@code PushConfig} objects given the push endpoint and the API-supported
249
+ * attributes that can be used to control different aspects of the message delivery.
250
+ *
251
+ * @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
252
+ * an endpoint might use {@code https://example.com/push}.
253
+ * @param attributes API supported attributes used to control message delivery. See
254
+ * {@link Builder#attributes(Map)} for more details.
255
+ */
126
256
public static Builder builder (String endpoint , Map <String , String > attributes ) {
127
- Builder builder = builder (endpoint );
128
- for (Map .Entry <String , String > entry : attributes .entrySet ()) {
129
- builder .addAttribute (entry .getKey (), entry .getValue ());
130
- }
131
- return builder ;
257
+ return builder (endpoint ).attributes (attributes );
132
258
}
133
259
134
260
com .google .pubsub .v1 .PushConfig toPb () {
0 commit comments