Package org.apache.pulsar.functions.api
Interface Context
- All Superinterfaces:
BaseContext
Context provides contextual information to the executing function.
Features like which message id we are handling, whats the topic name of the
message, what are our operating constraints, etc can be accessed by the
executing function
-
Method Summary
Modifier and TypeMethodDescriptionRecord<?>
Access the record associated with the current input value.The id of the function that we are executing.The name of the function that we are executing.The version of the function that we are executing.Get a list of all input topics.Get output schema builtin type or custom class name.Get the output topic of the source.org.apache.pulsar.client.admin.PulsarAdmin
Get the pulsar admin client.Get a map of all user-defined key/value configs for the function.getUserConfigValue
(String key) Get any user-defined key/value.getUserConfigValueOrDefault
(String key, Object defaultValue) Get any user-defined key/value or a default value if none is present.<X> org.apache.pulsar.client.api.ConsumerBuilder<X>
newConsumerBuilder
(org.apache.pulsar.client.api.Schema<X> schema) Create a ConsumerBuilder with the schema.<X> org.apache.pulsar.client.api.TypedMessageBuilder<X>
newOutputMessage
(String topicName, org.apache.pulsar.client.api.Schema<X> schema) New output message using schema for serializing to the topic.newOutputRecordBuilder
(org.apache.pulsar.client.api.Schema<X> schema) Creates a FunctionRecordBuilder initialized with values from this Context.<X> CompletableFuture<Void>
Deprecated.<X> CompletableFuture<Void>
Deprecated.in favor of usingnewOutputMessage(String, Schema)
Methods inherited from interface org.apache.pulsar.functions.api.BaseContext
deleteState, deleteStateAsync, getCounter, getCounterAsync, getInstanceId, getLogger, getNamespace, getNumInstances, getPulsarClient, getPulsarClientBuilder, getSecret, getState, getStateAsync, getStateStore, getStateStore, getTenant, incrCounter, incrCounterAsync, putState, putStateAsync, recordMetric
-
Method Details
-
getInputTopics
Collection<String> getInputTopics()Get a list of all input topics.- Returns:
- a list of all input topics
-
getOutputTopic
String getOutputTopic()Get the output topic of the source.- Returns:
- output topic name
-
getCurrentRecord
Record<?> getCurrentRecord()Access the record associated with the current input value.- Returns:
- the current record
-
getOutputSchemaType
String getOutputSchemaType()Get output schema builtin type or custom class name.- Returns:
- output schema builtin type or custom class name
-
getFunctionName
String getFunctionName()The name of the function that we are executing.- Returns:
- The Function name
-
getFunctionId
String getFunctionId()The id of the function that we are executing.- Returns:
- The function id
-
getFunctionVersion
String getFunctionVersion()The version of the function that we are executing.- Returns:
- The version id
-
getUserConfigMap
Get a map of all user-defined key/value configs for the function.- Returns:
- The full map of user-defined config values
-
getUserConfigValue
Get any user-defined key/value.- Parameters:
key
- The key- Returns:
- The Optional value specified by the user for that key.
-
getUserConfigValueOrDefault
Get any user-defined key/value or a default value if none is present.- Parameters:
key
- the config key to retrievedefaultValue
- value returned if the key is not found- Returns:
- Either the user config value associated with a given key or a supplied default value
-
getPulsarAdmin
org.apache.pulsar.client.admin.PulsarAdmin getPulsarAdmin()Get the pulsar admin client.- Returns:
- The instance of pulsar admin client
-
publish
@Deprecated <X> CompletableFuture<Void> publish(String topicName, X object, String schemaOrSerdeClassName) Deprecated.in favor of usingnewOutputMessage(String, Schema)
Publish an object using serDe or schema class for serializing to the topic.- Parameters:
topicName
- The name of the topic for publishingobject
- The object that needs to be publishedschemaOrSerdeClassName
- Either a builtin schema type (eg: "avro", "json", "protobuf") or the class name of the custom schema class- Returns:
- A future that completes when the framework is done publishing the message
-
publish
Deprecated.in favor of usingnewOutputMessage(String, Schema)
Publish an object to the topic using default schemas.- Parameters:
topicName
- The name of the topic for publishingobject
- The object that needs to be published- Returns:
- A future that completes when the framework is done publishing the message
-
newOutputMessage
<X> org.apache.pulsar.client.api.TypedMessageBuilder<X> newOutputMessage(String topicName, org.apache.pulsar.client.api.Schema<X> schema) throws org.apache.pulsar.client.api.PulsarClientException New output message using schema for serializing to the topic.- Type Parameters:
X
- the type of message- Parameters:
topicName
- The name of the topic for output messageschema
- provide a way to convert between serialized data and domain objects- Returns:
- the message builder instance
- Throws:
org.apache.pulsar.client.api.PulsarClientException
- if an error occurs
-
newConsumerBuilder
<X> org.apache.pulsar.client.api.ConsumerBuilder<X> newConsumerBuilder(org.apache.pulsar.client.api.Schema<X> schema) throws org.apache.pulsar.client.api.PulsarClientException Create a ConsumerBuilder with the schema.- Type Parameters:
X
- the message type of the consumer- Parameters:
schema
- provide a way to convert between serialized data and domain objects- Returns:
- the consumer builder instance
- Throws:
org.apache.pulsar.client.api.PulsarClientException
- if an error occurs
-
newOutputRecordBuilder
<X> FunctionRecord.FunctionRecordBuilder<X> newOutputRecordBuilder(org.apache.pulsar.client.api.Schema<X> schema) Creates a FunctionRecordBuilder initialized with values from this Context. It can be used in Functions to prepare a Record to return with default values taken from the Context and the input Record.- Type Parameters:
X
- the message type of record builder- Parameters:
schema
- provide a way to convert between serialized data and domain objects- Returns:
- the record builder instance
-
newOutputMessage(String, Schema)