Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<avro.version>1.7.7</avro.version>
<bigquery.version>v2-rev248-1.21.0</bigquery.version>
<bigtable.version>0.2.3</bigtable.version>
<pubsubgrpc.version>0.0.2</pubsubgrpc.version>
<clouddebugger.version>v2-rev6-1.21.0</clouddebugger.version>
<dataflow.version>v1b3-rev22-1.21.0</dataflow.version>
<dataflow.proto.version>0.5.160222</dataflow.proto.version>
Expand Down
34 changes: 34 additions & 0 deletions sdks/java/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,40 @@
<version>0.12.0</version>
</dependency>

<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>0.3.1</version>
<exclusions>
<!-- Exclude an old version of guava that is being pulled
in by a transitive dependency of google-api-client -->
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<version>4.1.0.Beta8</version>
</dependency>

<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-pubsub-v1</artifactId>
<version>${pubsubgrpc.version}</version>
<exclusions>
<!-- Exclude an old version of guava that is being pulled
in by a transitive dependency of google-api-client -->
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.google.cloud.bigtable</groupId>
<artifactId>bigtable-protos</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 com.google.cloud.dataflow.sdk.io;

import java.io.IOException;
import java.util.Collection;

/**
* A helper interface for talking to pub/sub via an underlying transport.
*/
public interface PubsubClient extends AutoCloseable {
/**
* Gracefully close the underlying transport.
*/
@Override
void close();

/**
* A message to be sent to pub/sub.
*/
class OutgoingMessage {
/**
* Underlying (encoded) element.
*/
public final byte[] elementBytes;

/**
* Timestamp for element (ms since epoch).
*/
public final long timestampMsSinceEpoch;

public OutgoingMessage(byte[] elementBytes, long timestampMsSinceEpoch) {
this.elementBytes = elementBytes;
this.timestampMsSinceEpoch = timestampMsSinceEpoch;
}
}

/**
* A message received from pub/sub.
*/
class IncomingMessage {
/**
* Underlying (encoded) element.
*/
public final byte[] elementBytes;

/**
* Timestamp for element (ms since epoch). Either pub/sub's processing time,
* or the custom timestamp associated with the message.
*/
public final long timestampMsSinceEpoch;

/**
* Timestamp (in system time) at which we requested the message (ms since epoch).
*/
public final long requestTimeMsSinceEpoch;

/**
* Id to pass back to pub/sub to acknowledge receipt of this message.
*/
public final String ackId;

/**
* Id to pass to the runner to distinguish this message from all others.
*/
public final byte[] recordId;

public IncomingMessage(
byte[] elementBytes,
long timestampMsSinceEpoch,
long requestTimeMsSinceEpoch,
String ackId,
byte[] recordId) {
this.elementBytes = elementBytes;
this.timestampMsSinceEpoch = timestampMsSinceEpoch;
this.requestTimeMsSinceEpoch = requestTimeMsSinceEpoch;
this.ackId = ackId;
this.recordId = recordId;
}
}

/**
* Publish {@code outgoingMessages} to pub/sub {@code topic}. Return number of messages
* published.
*
* @throws IOException
*/
int publish(String topic, Iterable<OutgoingMessage> outgoingMessages) throws IOException;

/**
* Request the next batch of up to {@code batchSize} messages from {@code subscription}.
* Return the received messages, or empty collection if none were available. Does not
* wait for messages to arrive. Returned messages will record heir request time
* as {@code requestTimeMsSinceEpoch}.
*
* @throws IOException
*/
Collection<IncomingMessage> pull(
long requestTimeMsSinceEpoch, String subscription, int
batchSize) throws IOException;

/**
* Acknowldege messages from {@code subscription} with {@code ackIds}.
*
* @throws IOException
*/
void acknowledge(String subscription, Iterable<String> ackIds) throws IOException;

/**
* Modify the ack deadline for messages from {@code subscription} with {@code ackIds} to
* be {@code deadlineSeconds} from now.
*
* @throws IOException
*/
void modifyAckDeadline(String subscription, Iterable<String> ackIds, int deadlineSeconds)
throws IOException;

/**
* Create {@code topic}.
*
* @throws IOException
*/
void createTopic(String topic) throws IOException;

/*
* Delete {@code topic}.
*
* @throws IOException
*/
void deleteTopic(String topic) throws IOException;

/**
* Return a list of topics for {@code project}.
*
* @throws IOException
*/
Collection<String> listTopics(String project) throws IOException;

/**
* Create {@code subscription} to {@code topic}.
*
* @throws IOException
*/
void createSubscription(String topic, String subscription, int ackDeadlineSeconds) throws
IOException;

/**
* Delete {@code subscription}.
*
* @throws IOException
*/
void deleteSubscription(String subscription) throws IOException;

/**
* Return a list of subscriptions for {@code topic} in {@code project}.
*
* @throws IOException
*/
Collection<String> listSubscriptions(String project, String topic) throws IOException;
}
Loading