public final class PubsubResourceManager
extends java.lang.Object
implements org.apache.beam.it.common.ResourceManager
The class provides an interaction with the real Pub/Sub client, with operations related to management of topics and subscriptions.
Modifier and Type | Class and Description |
---|---|
static class |
PubsubResourceManager.Builder
Builder for
PubsubResourceManager . |
Modifier and Type | Method and Description |
---|---|
static PubsubResourceManager.Builder |
builder(java.lang.String testName,
java.lang.String projectId,
com.google.api.gax.core.CredentialsProvider credentialsProvider) |
void |
cleanupAll()
Delete any topics or subscriptions created by this manager.
|
java.lang.String |
createSchema(com.google.pubsub.v1.Schema.Type schemaType,
java.lang.String schemaDefinition,
com.google.pubsub.v1.Encoding dataEncoding,
com.google.pubsub.v1.TopicName schemaTopic)
Registers a new schema of the given type and definition, then assigns it to the specified
topic.
|
com.google.pubsub.v1.SubscriptionName |
createSubscription(com.google.pubsub.v1.TopicName topicName,
java.lang.String subscriptionName)
Creates a subscription at the specific topic, with a given name.
|
com.google.pubsub.v1.TopicName |
createTopic(java.lang.String topicName)
Creates a topic with the given name on Pub/Sub.
|
com.google.pubsub.v1.TopicName |
createTopicWithoutPrefix(java.lang.String topicName)
Creates a topic with the given name on Pub/Sub.
|
java.lang.String |
getTestId()
Return the test ID this Resource Manager uses to manage Pub/Sub instances.
|
java.lang.String |
publish(com.google.pubsub.v1.TopicName topic,
java.util.Map<java.lang.String,java.lang.String> attributes,
com.google.protobuf.ByteString data)
Publishes a message with the given data to the publisher context's topic.
|
com.google.pubsub.v1.PullResponse |
pull(com.google.pubsub.v1.SubscriptionName subscriptionName,
int maxMessages)
Pulls messages from the given subscription.
|
public static PubsubResourceManager.Builder builder(java.lang.String testName, java.lang.String projectId, com.google.api.gax.core.CredentialsProvider credentialsProvider)
public java.lang.String getTestId()
public com.google.pubsub.v1.TopicName createTopic(java.lang.String topicName)
topicName
- Topic name to create. The underlying implementation may not use the topic name
directly, and can add a prefix or a suffix to identify specific executions.public com.google.pubsub.v1.TopicName createTopicWithoutPrefix(java.lang.String topicName)
topicName
- Topic name to create. The underlying implementation will use the topic name
directly.public com.google.pubsub.v1.SubscriptionName createSubscription(com.google.pubsub.v1.TopicName topicName, java.lang.String subscriptionName)
topicName
- Topic Name reference to add the subscription.subscriptionName
- Name of the subscription to use. Note that the underlying
implementation may not use the subscription name literally, and can use a prefix or a
suffix to identify specific executions.public java.lang.String publish(com.google.pubsub.v1.TopicName topic, java.util.Map<java.lang.String,java.lang.String> attributes, com.google.protobuf.ByteString data) throws org.apache.beam.it.gcp.pubsub.PubsubResourceManagerException
topic
- Reference to the topic to send the message.attributes
- Attributes to send with the message.data
- Byte data to send.org.apache.beam.it.gcp.pubsub.PubsubResourceManagerException
public com.google.pubsub.v1.PullResponse pull(com.google.pubsub.v1.SubscriptionName subscriptionName, int maxMessages)
subscriptionName
- Name of the subscription to use.public java.lang.String createSchema(com.google.pubsub.v1.Schema.Type schemaType, java.lang.String schemaDefinition, com.google.pubsub.v1.Encoding dataEncoding, com.google.pubsub.v1.TopicName schemaTopic)
schemaType
- the type of schema to create (e.g. AVRO, PROTOBUF)schemaDefinition
- the definition of the schema to create in AVRO or Protobuf syntax.dataEncoding
- the encoding of the data in pubsub (e.g. BINARY_ENCODING, JSON)schemaTopic
- the name of the topic to which assign the schema.public void cleanupAll()
cleanupAll
in interface org.apache.beam.it.common.ResourceManager