Class PubsubClient
- java.lang.Object
-
- org.apache.beam.sdk.io.gcp.pubsub.PubsubClient
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
PubsubGrpcClient,PubsubJsonClient,PubsubTestClient
public abstract class PubsubClient extends java.lang.Object implements java.io.CloseableAn (abstract) helper class for talking to Pubsub via an underlying transport.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPubsubClient.IncomingMessageA message received from Pubsub.static classPubsubClient.OutgoingMessageA message to be sent to Pubsub.static classPubsubClient.ProjectPathPath representing a cloud project id.static interfacePubsubClient.PubsubClientFactoryFactory for creating clients.static classPubsubClient.SchemaPathPath representing a Pubsub schema.static classPubsubClient.SubscriptionPathPath representing a Pubsub subscription.static classPubsubClient.TopicPathPath representing a Pubsub topic.
-
Constructor Summary
Constructors Constructor Description PubsubClient()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract intackDeadlineSeconds(PubsubClient.SubscriptionPath subscription)Return the ack deadline, in seconds, forsubscription.abstract voidacknowledge(PubsubClient.SubscriptionPath subscription, java.util.List<java.lang.String> ackIds)Acknowldege messages fromsubscriptionwithackIds.PubsubClient.SubscriptionPathcreateRandomSubscription(PubsubClient.ProjectPath project, PubsubClient.TopicPath topic, int ackDeadlineSeconds)Create a random subscription fortopic.abstract voidcreateSchema(PubsubClient.SchemaPath schemaPath, java.lang.String schemaContent, com.google.pubsub.v1.Schema.Type type)CreateSchemafrom Schema definition content.abstract voidcreateSubscription(PubsubClient.TopicPath topic, PubsubClient.SubscriptionPath subscription, int ackDeadlineSeconds)Createsubscriptiontotopic.abstract voidcreateTopic(PubsubClient.TopicPath topic)Createtopic.abstract voidcreateTopic(PubsubClient.TopicPath topic, PubsubClient.SchemaPath schema)Create {link TopicPath} withPubsubClient.SchemaPath.abstract voiddeleteSchema(PubsubClient.SchemaPath schemaPath)DeletePubsubClient.SchemaPath.abstract voiddeleteSubscription(PubsubClient.SubscriptionPath subscription)Deletesubscription.abstract voiddeleteTopic(PubsubClient.TopicPath topic)protected static longextractTimestampAttribute(java.lang.String timestampAttribute, @Nullable java.util.Map<java.lang.String,java.lang.String> attributes)Return the timestamp (in ms since unix epoch) to use for a Pubsub message withtimestampAttributeandattriutes.abstract org.apache.beam.sdk.schemas.SchemagetSchema(PubsubClient.SchemaPath schemaPath)Return a BeamSchemafrom the Pub/Sub schema resource, if exists.abstract PubsubClient.SchemaPathgetSchemaPath(PubsubClient.TopicPath topicPath)ReturnPubsubClient.SchemaPathfromPubsubClient.TopicPathif exists.abstract booleanisEOF()Return true ifpull(long, org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath, int, boolean)will always return empty list.abstract booleanisTopicExists(PubsubClient.TopicPath topic)Return true iftopicexists.abstract java.util.List<PubsubClient.SubscriptionPath>listSubscriptions(PubsubClient.ProjectPath project, PubsubClient.TopicPath topic)Return a list of subscriptions fortopicinproject.abstract java.util.List<PubsubClient.TopicPath>listTopics(PubsubClient.ProjectPath project)Return a list of topics forproject.abstract voidmodifyAckDeadline(PubsubClient.SubscriptionPath subscription, java.util.List<java.lang.String> ackIds, int deadlineSeconds)Modify the ack deadline for messages fromsubscriptionwithackIdsto bedeadlineSecondsfrom now.protected static java.lang.LongparseTimestampAsMsSinceEpoch(java.lang.String timestamp)Return timestamp as ms-since-unix-epoch corresponding totimestamp.static PubsubClient.ProjectPathprojectPathFromId(java.lang.String projectId)static PubsubClient.ProjectPathprojectPathFromPath(java.lang.String path)abstract intpublish(PubsubClient.TopicPath topic, java.util.List<PubsubClient.OutgoingMessage> outgoingMessages)PublishoutgoingMessagesto Pubsubtopic.abstract java.util.List<PubsubClient.IncomingMessage>pull(long requestTimeMsSinceEpoch, PubsubClient.SubscriptionPath subscription, int batchSize, boolean returnImmediately)Request the next batch of up tobatchSizemessages fromsubscription.static PubsubClient.SchemaPathschemaPathFromId(java.lang.String projectId, java.lang.String schemaId)static PubsubClient.SchemaPathschemaPathFromPath(java.lang.String path)static PubsubClient.SubscriptionPathsubscriptionPathFromName(java.lang.String projectId, java.lang.String subscriptionName)static PubsubClient.SubscriptionPathsubscriptionPathFromPath(java.lang.String path)static PubsubClient.TopicPathtopicPathFromName(java.lang.String projectId, java.lang.String topicName)static PubsubClient.TopicPathtopicPathFromPath(java.lang.String path)
-
-
-
Method Detail
-
parseTimestampAsMsSinceEpoch
protected static java.lang.Long parseTimestampAsMsSinceEpoch(java.lang.String timestamp)
Return timestamp as ms-since-unix-epoch corresponding totimestamp. ThrowIllegalArgumentExceptionif timestamp cannot be recognized.
-
extractTimestampAttribute
protected static long extractTimestampAttribute(java.lang.String timestampAttribute, @Nullable java.util.Map<java.lang.String,java.lang.String> attributes)Return the timestamp (in ms since unix epoch) to use for a Pubsub message withtimestampAttributeandattriutes.The message attributes must contain
timestampAttribute, and the value of that attribute will be taken as the timestamp.- Throws:
java.lang.IllegalArgumentException- if the timestamp cannot be recognized as a ms-since-unix-epoch or RFC3339 time.
-
projectPathFromPath
public static PubsubClient.ProjectPath projectPathFromPath(java.lang.String path)
-
projectPathFromId
public static PubsubClient.ProjectPath projectPathFromId(java.lang.String projectId)
-
schemaPathFromPath
public static PubsubClient.SchemaPath schemaPathFromPath(java.lang.String path)
-
schemaPathFromId
public static PubsubClient.SchemaPath schemaPathFromId(java.lang.String projectId, java.lang.String schemaId)
-
subscriptionPathFromPath
public static PubsubClient.SubscriptionPath subscriptionPathFromPath(java.lang.String path)
-
subscriptionPathFromName
public static PubsubClient.SubscriptionPath subscriptionPathFromName(java.lang.String projectId, java.lang.String subscriptionName)
-
topicPathFromPath
public static PubsubClient.TopicPath topicPathFromPath(java.lang.String path)
-
topicPathFromName
public static PubsubClient.TopicPath topicPathFromName(java.lang.String projectId, java.lang.String topicName)
-
publish
public abstract int publish(PubsubClient.TopicPath topic, java.util.List<PubsubClient.OutgoingMessage> outgoingMessages) throws java.io.IOException
PublishoutgoingMessagesto Pubsubtopic. Return number of messages published.- Throws:
java.io.IOException
-
pull
public abstract java.util.List<PubsubClient.IncomingMessage> pull(long requestTimeMsSinceEpoch, PubsubClient.SubscriptionPath subscription, int batchSize, boolean returnImmediately) throws java.io.IOException
Request the next batch of up tobatchSizemessages fromsubscription. Return the received messages, or empty collection if none were available. Does not wait for messages to arrive ifreturnImmediatelyis true. Returned messages will record their request time asrequestTimeMsSinceEpoch.- Throws:
java.io.IOException
-
acknowledge
public abstract void acknowledge(PubsubClient.SubscriptionPath subscription, java.util.List<java.lang.String> ackIds) throws java.io.IOException
Acknowldege messages fromsubscriptionwithackIds.- Throws:
java.io.IOException
-
modifyAckDeadline
public abstract void modifyAckDeadline(PubsubClient.SubscriptionPath subscription, java.util.List<java.lang.String> ackIds, int deadlineSeconds) throws java.io.IOException
Modify the ack deadline for messages fromsubscriptionwithackIdsto bedeadlineSecondsfrom now.- Throws:
java.io.IOException
-
createTopic
public abstract void createTopic(PubsubClient.TopicPath topic) throws java.io.IOException
Createtopic.- Throws:
java.io.IOException
-
createTopic
public abstract void createTopic(PubsubClient.TopicPath topic, PubsubClient.SchemaPath schema) throws java.io.IOException
Create {link TopicPath} withPubsubClient.SchemaPath.- Throws:
java.io.IOException
-
deleteTopic
public abstract void deleteTopic(PubsubClient.TopicPath topic) throws java.io.IOException
- Throws:
java.io.IOException
-
listTopics
public abstract java.util.List<PubsubClient.TopicPath> listTopics(PubsubClient.ProjectPath project) throws java.io.IOException
Return a list of topics forproject.- Throws:
java.io.IOException
-
isTopicExists
public abstract boolean isTopicExists(PubsubClient.TopicPath topic) throws java.io.IOException
Return true iftopicexists.- Throws:
java.io.IOException
-
createSubscription
public abstract void createSubscription(PubsubClient.TopicPath topic, PubsubClient.SubscriptionPath subscription, int ackDeadlineSeconds) throws java.io.IOException
Createsubscriptiontotopic.- Throws:
java.io.IOException
-
createRandomSubscription
public PubsubClient.SubscriptionPath createRandomSubscription(PubsubClient.ProjectPath project, PubsubClient.TopicPath topic, int ackDeadlineSeconds) throws java.io.IOException
Create a random subscription fortopic. Return thePubsubClient.SubscriptionPath. It is the responsibility of the caller to later delete the subscription.- Throws:
java.io.IOException
-
deleteSubscription
public abstract void deleteSubscription(PubsubClient.SubscriptionPath subscription) throws java.io.IOException
Deletesubscription.- Throws:
java.io.IOException
-
listSubscriptions
public abstract java.util.List<PubsubClient.SubscriptionPath> listSubscriptions(PubsubClient.ProjectPath project, PubsubClient.TopicPath topic) throws java.io.IOException
Return a list of subscriptions fortopicinproject.- Throws:
java.io.IOException
-
ackDeadlineSeconds
public abstract int ackDeadlineSeconds(PubsubClient.SubscriptionPath subscription) throws java.io.IOException
Return the ack deadline, in seconds, forsubscription.- Throws:
java.io.IOException
-
isEOF
public abstract boolean isEOF()
Return true ifpull(long, org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath, int, boolean)will always return empty list. Actual clients will return false. Test clients may return true to signal that all expected messages have been pulled and the test may complete.
-
createSchema
public abstract void createSchema(PubsubClient.SchemaPath schemaPath, java.lang.String schemaContent, com.google.pubsub.v1.Schema.Type type) throws java.io.IOException
CreateSchemafrom Schema definition content.- Throws:
java.io.IOException
-
deleteSchema
public abstract void deleteSchema(PubsubClient.SchemaPath schemaPath) throws java.io.IOException
DeletePubsubClient.SchemaPath.- Throws:
java.io.IOException
-
getSchemaPath
public abstract PubsubClient.SchemaPath getSchemaPath(PubsubClient.TopicPath topicPath) throws java.io.IOException
ReturnPubsubClient.SchemaPathfromPubsubClient.TopicPathif exists.- Throws:
java.io.IOException
-
getSchema
public abstract org.apache.beam.sdk.schemas.Schema getSchema(PubsubClient.SchemaPath schemaPath) throws java.io.IOException
Return a BeamSchemafrom the Pub/Sub schema resource, if exists.- Throws:
java.io.IOException
-
-