Skip to main content

Manage Functions

Important

This page only shows some frequently used operations.

  • For the latest and complete information about Pulsar admin, including commands, flags, descriptions, and more, see Pulsar admin doc

  • For the latest and complete information about REST API, including parameters, responses, samples, and more, see REST API doc.

  • For the latest and complete information about Java admin API, including classes, methods, descriptions, and more, see Java admin API doc.

Pulsar Functions are lightweight compute processes that

  • consume messages from one or more Pulsar topics
  • apply a user-supplied processing logic to each message
  • publish the results of the computation to another topic

Functions can be managed via the following methods.

MethodDescription
Admin CLIThe functions command of the pulsar-admin tool.
REST APIThe /admin/v3/functions endpoint of the admin REST API.
Java Admin APIThe functions method of the PulsarAdmin object in the Java API.

Function resources

You can perform the following operations on functions.

Create a function

You can create a Pulsar function in cluster mode (deploy it on a Pulsar cluster) using Admin CLI, REST API or Java Admin API.

Use the create subcommand.

Example


$ pulsar-admin functions create \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \
--inputs test-input-topic \
--output persistent://public/default/test-output-topic \
--classname org.apache.pulsar.functions.api.examples.ExclamationFunction \
--jar /examples/api-examples.jar

Update a function

You can update a Pulsar function that has been deployed to a Pulsar cluster using Admin CLI, REST API or Java Admin API.

Use the update subcommand.

Example


$ pulsar-admin functions update \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \
--output persistent://public/default/update-output-topic \
# other options

Start an instance of a function

You can start a stopped function instance with instance-id using Admin CLI, REST API or Java Admin API.

Use the start subcommand.


$ pulsar-admin functions start \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \
--instance-id 1

Start all instances of a function

You can start all stopped function instances using Admin CLI, REST API or Java Admin API.

Use the start subcommand.

Example


$ pulsar-admin functions start \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \

Stop an instance of a function

You can stop a function instance with instance-id using Admin CLI, REST API or Java Admin API.

Use the stop subcommand.

Example


$ pulsar-admin functions stop \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \
--instance-id 1

Stop all instances of a function

You can stop all function instances using Admin CLI, REST API or Java Admin API.

Use the stop subcommand.

Example


$ pulsar-admin functions stop \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \

Restart an instance of a function

Restart a function instance with instance-id using Admin CLI, REST API or Java Admin API.

Use the restart subcommand.

Example


$ pulsar-admin functions restart \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \
--instance-id 1

Restart all instances of a function

You can restart all function instances using Admin CLI, REST API or Java admin API.

Use the restart subcommand.

Example


$ pulsar-admin functions restart \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \

List all functions

You can list all Pulsar functions running under a specific tenant and namespace using Admin CLI, REST API or Java Admin API.

Use the list subcommand.

Example


$ pulsar-admin functions list \
--tenant public \
--namespace default

Delete a function

You can delete a Pulsar function that is running on a Pulsar cluster using Admin CLI, REST API or Java Admin API.

Use the delete subcommand.

Example


$ pulsar-admin functions delete \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions)

Get info about a function

You can get information about a Pulsar function currently running in cluster mode using Admin CLI, REST API or Java Admin API.

Use the get subcommand.

Example


$ pulsar-admin functions get \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions)

Get status of an instance of a function

You can get the current status of a Pulsar function instance with instance-id using Admin CLI, REST API or Java Admin API.

Use the status subcommand.

Example


$ pulsar-admin functions status \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \
--instance-id 1

Get status of all instances of a function

You can get the current status of a Pulsar function instance using Admin CLI, REST API or Java Admin API.

Use the status subcommand.

Example


$ pulsar-admin functions status \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions)

Get stats of an instance of a function

You can get the current stats of a Pulsar Function instance with instance-id using Admin CLI, REST API or Java admin API.

Use the stats subcommand.

Example


$ pulsar-admin functions stats \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \
--instance-id 1

Get stats of all instances of a function

You can get the current stats of a Pulsar function using Admin CLI, REST API or Java admin API.

Use the stats subcommand.

Example


$ pulsar-admin functions stats \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions)

Trigger a function

You can trigger a specified Pulsar function with a supplied value using Admin CLI, REST API or Java admin API.

Use the trigger subcommand.

Example


$ pulsar-admin functions trigger \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \
--topic (the name of input topic) \
--trigger-value \"hello pulsar\"
# or --trigger-file (the path of trigger file)

Put state associated with a function

You can put the state associated with a Pulsar function using Admin CLI, REST API or Java admin API.

Use the putstate subcommand.

Example


$ pulsar-admin functions putstate \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \
--state "{\"key\":\"pulsar\", \"stringValue\":\"hello pulsar\"}"

Fetch state associated with a function

You can fetch the current state associated with a Pulsar function using Admin CLI, REST API or Java admin API.

Use the querystate subcommand.

Example


$ pulsar-admin functions querystate \
--tenant public \
--namespace default \
--name (the name of Pulsar Functions) \
--key (the key of state)