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 https://cloud.google.com/pubsub/docs/reference/rest
26 public class PubSubRequestsResponses {
28 // Method: projects.subscriptions.acknowledge
31 * Acknowledges the messages associated with the ackIds in the AcknowledgeRequest. The Pub/Sub system can remove the
32 * relevant messages from the subscription.
34 * Acknowledging a message whose ack deadline has expired may succeed, but such a message may be redelivered later.
35 * Acknowledging a message more than once will not result in an error.
37 public static class PubSubAcknowledgeRequest {
39 public List<String> ackIds;
41 public PubSubAcknowledgeRequest(List<String> ackIds) {
46 // Method: projects.subscriptions.create
49 * Creates a subscription to a given topic. See the resource name rules. If the subscription already exists, returns
50 * ALREADY_EXISTS. If the corresponding topic doesn't exist, returns NOT_FOUND.
52 * If the name is not provided in the request, the server will assign a random name for this subscription on the
53 * same project as the topic, conforming to the resource name format. The generated name is populated in the
54 * returned Subscription object. Note that for REST API requests, you must specify a name in the request.
56 public static class PubSubCreateRequest {
59 public boolean enableMessageOrdering;
62 * @param topic The name of the topic from which this subscription is receiving messages. Format is
63 * <code>projects/{project}/topics/{topic}</code>.
64 * @param enableMessageOrdering If true, messages published with the same orderingKey in the message will be
65 * delivered to the subscribers in the order in which they are received by the Pub/Sub system.
66 * Otherwise, they may be delivered in any order.
68 public PubSubCreateRequest(String topic, boolean enableMessageOrdering) {
70 this.enableMessageOrdering = enableMessageOrdering;
74 // Method: projects.subscriptions.pull
77 * Pulls messages from the server. The server may return UNAVAILABLE if there are too many concurrent pull requests
78 * pending for the given subscription.
80 * A {@link PubSubPullResponse} is returned when successful.
82 public static class PubSubPullRequest {
84 public int maxMessages;
87 * @param maxMessages The maximum number of messages to return for this request. Must be a positive integer. The
88 * Pub/Sub system may return fewer than the number specified.
90 public PubSubPullRequest(int maxMessages) {
91 this.maxMessages = maxMessages;
96 * A message that is published by publishers and consumed by subscribers.
98 public static class PubSubMessage {
100 * The message data field. A base64-encoded string.
105 * ID of this message, assigned by the server when the message is published. Guaranteed to be unique within the
106 * topic. This value may be read by a subscriber that receives a PubsubMessage via a
107 * <code>subscriptions.pull</code> call or a push delivery. It must not be populated by the publisher in a
108 * topics.publish call.
110 public String messageId;
113 * The time at which the message was published, populated by the server when it receives the topics.publish
114 * call. It must not be populated by the publisher in a topics publish call.
116 * A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.
117 * Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
119 public ZonedDateTime publishTime;
123 * A message and its corresponding acknowledgment ID.
125 public static class PubSubReceivedMessage {
127 * This ID can be used to acknowledge the received message.
134 public PubSubMessage message;
138 * Response to a {@link PubSubPullRequest}.
140 public class PubSubPullResponse {
142 * Received Pub/Sub messages. The list will be empty if there are no more messages available in the backlog. For
143 * JSON, the response can be entirely empty. The Pub/Sub system may return fewer than the maxMessages requested
144 * even if there are more messages available in the backlog.
146 public List<PubSubReceivedMessage> receivedMessages;