2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nest.internal.sdm.dto;
15 import java.time.ZonedDateTime;
16 import java.util.List;
19 * The {@link PubSubRequestsResponses} provides classes used for mapping Pub/Sub REST API requests and responses.
20 * Only the subset of requests/responses and fields that are used by the binding are implemented.
22 * @author Wouter Born - Initial contribution
24 * @see <a href="https://cloud.google.com/pubsub/docs/reference/rest">
25 * https://cloud.google.com/pubsub/docs/reference/rest</a>
27 public class PubSubRequestsResponses {
29 // Method: projects.subscriptions.acknowledge
32 * Acknowledges the messages associated with the ackIds in the AcknowledgeRequest. The Pub/Sub system can remove the
33 * relevant messages from the subscription.
35 * Acknowledging a message whose ack deadline has expired may succeed, but such a message may be redelivered later.
36 * Acknowledging a message more than once will not result in an error.
38 public static class PubSubAcknowledgeRequest {
40 public List<String> ackIds;
42 public PubSubAcknowledgeRequest(List<String> ackIds) {
47 // Method: projects.subscriptions.create
50 * Creates a subscription to a given topic. See the resource name rules. If the subscription already exists, returns
51 * ALREADY_EXISTS. If the corresponding topic doesn't exist, returns NOT_FOUND.
53 * If the name is not provided in the request, the server will assign a random name for this subscription on the
54 * same project as the topic, conforming to the resource name format. The generated name is populated in the
55 * returned Subscription object. Note that for REST API requests, you must specify a name in the request.
57 public static class PubSubCreateRequest {
60 public boolean enableMessageOrdering;
63 * @param topic The name of the topic from which this subscription is receiving messages. Format is
64 * <code>projects/{project}/topics/{topic}</code>.
65 * @param enableMessageOrdering If true, messages published with the same orderingKey in the message will be
66 * delivered to the subscribers in the order in which they are received by the Pub/Sub system.
67 * Otherwise, they may be delivered in any order.
69 public PubSubCreateRequest(String topic, boolean enableMessageOrdering) {
71 this.enableMessageOrdering = enableMessageOrdering;
75 // Method: projects.subscriptions.pull
78 * Pulls messages from the server. The server may return UNAVAILABLE if there are too many concurrent pull requests
79 * pending for the given subscription.
81 * A {@link PubSubPullResponse} is returned when successful.
83 public static class PubSubPullRequest {
85 public int maxMessages;
88 * @param maxMessages The maximum number of messages to return for this request. Must be a positive integer. The
89 * Pub/Sub system may return fewer than the number specified.
91 public PubSubPullRequest(int maxMessages) {
92 this.maxMessages = maxMessages;
97 * A message that is published by publishers and consumed by subscribers.
99 public static class PubSubMessage {
101 * The message data field. A base64-encoded string.
106 * ID of this message, assigned by the server when the message is published. Guaranteed to be unique within the
107 * topic. This value may be read by a subscriber that receives a PubsubMessage via a
108 * <code>subscriptions.pull</code> call or a push delivery. It must not be populated by the publisher in a
109 * topics.publish call.
111 public String messageId;
114 * The time at which the message was published, populated by the server when it receives the topics.publish
115 * call. It must not be populated by the publisher in a topics publish call.
117 * A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.
118 * Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
120 public ZonedDateTime publishTime;
124 * A message and its corresponding acknowledgment ID.
126 public static class PubSubReceivedMessage {
128 * This ID can be used to acknowledge the received message.
135 public PubSubMessage message;
139 * Response to a {@link PubSubPullRequest}.
141 public class PubSubPullResponse {
143 * Received Pub/Sub messages. The list will be empty if there are no more messages available in the backlog. For
144 * JSON, the response can be entirely empty. The Pub/Sub system may return fewer than the maxMessages requested
145 * even if there are more messages available in the backlog.
147 public List<PubSubReceivedMessage> receivedMessages;