Window Functions Context
Java SDK provides access to a window context object that can be used by a window function. This context object provides a wide variety of information and functionality for Pulsar window functions as below.
-
- Names of all input topics and the output topic associated with the function.
- Tenant and namespace associated with the function.
- Pulsar window function name, ID, and version.
- ID of the Pulsar function instance running the window function.
- Number of instances that invoke the window function.
- Built-in type or custom class name of the output schema.
-
- Logger object used by the window function, which can be used to create window function log messages.
-
- Access to arbitrary user configuration values.
-
- Routing is supported in Pulsar window functions. Pulsar window functions send messages to arbitrary topics as per the
publish
interface.
- Routing is supported in Pulsar window functions. Pulsar window functions send messages to arbitrary topics as per the
-
- Interface for recording metrics.
-
- Interface for storing and retrieving state in state storage.
Spec
Spec contains the basic information of a function.
Get input topics
The getInputTopics
method gets the name list of all input topics.
This example demonstrates how to get the name list of all input topics in a Java window function.
public class GetInputTopicsWindowFunction implements WindowFunction<String, Void> {
@Override
public Void process(Collection<Record<String>> inputs, WindowContext context) throws Exception {
Collection<String> inputTopics = context.getInputTopics();
System.out.println(inputTopics);
return null;
}
}
Get output topic
The getOutputTopic
method gets the name of a topic to which the message is sent.
This example demonstrates how to get the name of an output topic in a Java window function.
public class GetOutputTopicWindowFunction implements WindowFunction<String, Void> {
@Override
public Void process(Collection<Record<String>> inputs, WindowContext context) throws Exception {
String outputTopic = context.getOutputTopic();
System.out.println(outputTopic);
return null;
}
}
Get tenant
The getTenant
method gets the tenant name associated with the window function.
This example demonstrates how to get the tenant name in a Java window function.
public class GetTenantWindowFunction implements WindowFunction<String, Void> {
@Override
public Void process(Collection<Record<String>> inputs, WindowContext context) throws Exception {
String tenant = context.getTenant();
System.out.println(tenant);
return null;
}
}