### Instantiate DefaultPulsarMessageListenerContainer (Java) Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption Provides an example of how to instantiate and configure a `DefaultPulsarMessageListenerContainer`. It shows setting up the consumer factory, properties, and the message listener. ```java Map config = new HashMap<>(); config.put("topics", "my-topic"); PulsarConsumerFactory pulsarConsumerFactorY = DefaultPulsarConsumerFactory<>(pulsarClient, config); PulsarContainerProperties pulsarContainerProperties = new PulsarContainerProperties(); pulsarContainerProperties.setMessageListener((PulsarRecordMessageListener) (consumer, msg) -> { }); DefaultPulsarMessageListenerContainer pulsarListenerContainer = new DefaultPulsarMessageListenerContainer(pulsarConsumerFacotyr, pulsarContainerProperties); return pulsarListenerContainer; ``` -------------------------------- ### Consumer Start Timeout and Retry Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/listener/PulsarContainerProperties Configure the timeout for consumer startup and retry mechanisms. ```APIDOC ## Consumer Start Timeout and Retry ### getConsumerStartTimeout() Returns the maximum duration to wait for the consumer thread to start. ### determineConsumerStartTimeout() Determines the consumer start timeout, potentially using defaults. ### setConsumerStartTimeout(Duration consumerStartTimeout) Sets the maximum duration to wait for the consumer thread to start before logging an error. The default is 30 seconds. Parameters: `consumerStartTimeout` - the consumer start timeout ### getStartupFailureRetryTemplate() Returns the retry template for handling startup failures. ### getDefaultStartupFailureRetryTemplate() Get the default template to use to retry startup when no custom retry template has been specified. Returns: the default retry template that will retry 3 times with a fixed delay of 10 seconds between each attempt. Since: 1.2.0 ### setStartupFailureRetryTemplate(RetryTemplate startupFailureRetryTemplate) Sets the retry template for handling startup failures. ``` -------------------------------- ### PulsarListener with Concurrency (Java) Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption Demonstrates using the `@PulsarListener` annotation with `concurrency` enabled for a `Failover` subscription. This example shows how to configure multiple consumers for a partitioned topic. ```java @PulsarListener(topics = "my-topic", subscriptionName = "subscription-1", subscriptionType = SubscriptionType.Failover, concurrency = "3") void listen(String message, Consumer consumer) { ... System.out.println("Current Thread: " + Thread.currentThread().getName()); System.out.println("Current Consumer: " + consumer.getConsumerName()); } ``` -------------------------------- ### Basic Pulsar Listener with Subscription and Topic Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption A basic example of a Pulsar listener that specifies both subscription name and topics. It consumes messages as Strings and prints them to the console. The framework infers the String schema automatically. ```java @PulsarListener(subscriptionName = "hello-pulsar-subscription", topics = "hello-pulsar") public void listen(String message) { System.out.println("Message Received: " + message); } ``` -------------------------------- ### Get Pulsar Client from Factory (Java) Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/core/DefaultPulsarProducerFactory The `getPulsarClient` method returns the `PulsarClient` instance that the `DefaultPulsarProducerFactory` uses to create producers. This allows access to the underlying Pulsar client for further operations. ```java public org.apache.pulsar.client.api.PulsarClient getPulsarClient() ``` -------------------------------- ### Configure PulsarReader Annotation for Topic Consumption Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption Illustrates the usage of the @PulsarReader annotation to quickly read messages from a Pulsar topic. It shows how to specify the topic, a unique ID for the reader, and the starting message ID (earliest or latest). This simplifies reader setup compared to direct use of PulsarReaderFactory. ```java @PulsarReader(id = "reader-demo-id", topics = "reader-demo-topic", startMessageId = "earliest") void read(String message) { //... } ``` -------------------------------- ### CacheProviderFactory.create with EvictionListener Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/cache/provider/class-use/CacheProviderFactory.EvictionListener Demonstrates the creation of a cache provider instance using `CacheProviderFactory.create`, which accepts an `EvictionListener`. ```APIDOC ## POST /api/cache/provider ### Description Creates a cache provider instance with specified options, including an eviction listener. ### Method POST ### Endpoint /api/cache/provider ### Parameters #### Query Parameters - **cacheExpireAfterAccess** (Duration) - Optional - The duration after which cache entries expire. - **cacheMaximumSize** (Long) - Optional - The maximum size of the cache. - **cacheInitialCapacity** (Integer) - Optional - The initial capacity of the cache. #### Request Body - **evictionListener** (CacheProviderFactory.EvictionListener) - Required - A listener for cache eviction events. ### Request Example ```json { "evictionListener": "" } ``` ### Response #### Success Response (200) - **CacheProvider** (CacheProvider) - The created cache provider instance. #### Response Example ```json { "cacheProviderInstance": "" } ``` ``` -------------------------------- ### PulsarReaderContainerProperties: Reader Start Timeout Configuration Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/reader/PulsarReaderContainerProperties Methods for setting and getting the timeout duration for starting a Pulsar reader thread. If the reader thread does not start within this duration, an error will be logged. The default timeout is 30 seconds. ```java public Duration getReaderStartTimeout() public void setReaderStartTimeout(Duration readerStartTimeout) ``` -------------------------------- ### Add Dependencies for Spring Boot Zipkin Tracing (Gradle) Source: https://docs.spring.io/spring-pulsar/reference/reference/observability This snippet outlines the Gradle dependencies needed for integrating Micrometer Tracing with Zipkin and Brave in a Spring Boot project. It covers the actuator starter, Brave tracing bridge, and necessary Zipkin reporter artifacts. ```gradle dependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'io.micrometer:micrometer-tracing-bridge-brave' implementation 'io.zipkin.reporter2:zipkin-reporter-brave' implementation 'io.zipkin.reporter2:zipkin-sender-urlconnection' } ``` -------------------------------- ### PulsarReaderContainerProperties: Start Message ID Configuration Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/reader/PulsarReaderContainerProperties Methods for setting and getting the starting message ID for the Pulsar reader. This allows the reader to begin consuming messages from a specific point in a topic's history. ```java public @Nullable org.apache.pulsar.client.api.MessageId getStartMessageId() public void setStartMessageId(org.apache.pulsar.client.api.MessageId startMessageId) ``` -------------------------------- ### Customize Pulsar ReaderBuilder with Customizer Bean (Java) Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption Demonstrates how to customize the Pulsar ReaderBuilder by providing a `@Bean` of type `PulsarReaderReaderBuilderCustomizer`. This customizer allows setting specific message IDs to start reading from or applying other reader configurations. If only one reader and customizer exist, it's applied automatically. ```java @PulsarReader(id = "reader-customizer-demo-id", topics = "reader-customizer-demo-topic", readerCustomizer = "myCustomizer") void read(String message) { //... } @Bean public PulsarReaderReaderBuilderCustomizer myCustomizer() { return readerBuilder -> { readerBuilder.startMessageId(messageId); // the first message read is after this message id. // Any other customizations on the readerBuilder }; } ``` -------------------------------- ### HandlerAdapter Class Documentation Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/listener/adapter/HandlerAdapter Provides details on the HandlerAdapter class, including its constructors and methods for invoking handlers. ```APIDOC ## Class: HandlerAdapter ### Description A wrapper for either an `InvocableHandlerMethod` or `DelegatingInvocableHandler`. All methods delegate to the underlying handler. ### Author Soby Chacko ## Constructor Summary ### `HandlerAdapter(InvocableHandlerMethod invokerHandlerMethod)` Construct an instance with the provided method. ### `HandlerAdapter(DelegatingInvocableHandler delegatingHandler)` Construct an instance with the provided delegating handler. ## Method Summary ### `Object getBean()` Returns the bean associated with the handler. ### `@Nullable InvocableHandlerMethod getInvokerHandlerMethod()` Returns the `InvocableHandlerMethod` if the handler is of that type, otherwise null. ### `String getMethodAsString(Object payload)` Returns a string representation of the method, potentially using the payload. ### `@Nullable Object invoke(Message message, @Nullable Object... providedArgs) throws Exception` Invokes the handler with the given message and arguments. Can throw an Exception. ### `InvocableHandlerMethod requireNonNullInvokerHandlerMethod()` Returns the `InvocableHandlerMethod`, throwing an exception if it's not present. ## Constructor Details ### `HandlerAdapter(InvocableHandlerMethod invokerHandlerMethod)` **Parameters:** - `invokerHandlerMethod` (InvocableHandlerMethod) - the method. ### `HandlerAdapter(DelegatingInvocableHandler delegatingHandler)` **Parameters:** - `delegatingHandler` (DelegatingInvocableHandler) - the handler. ## Method Details ### `invoke` **Signature:** `public @Nullable Object invoke(Message message, @Nullable Object... providedArgs) throws Exception` **Throws:** - `Exception` ### `getMethodAsString` **Signature:** `public String getMethodAsString(Object payload)` ### `getBean` **Signature:** `public Object getBean()` ### `getInvokerHandlerMethod` **Signature:** `public @Nullable InvocableHandlerMethod getInvokerHandlerMethod()` ### `requireNonNullInvokerHandlerMethod` **Signature:** `public InvocableHandlerMethod requireNonNullInvokerHandlerMethod()` ## Inherited Methods from Object `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait` ``` -------------------------------- ### Add Dependencies for Spring Boot Zipkin Tracing (Maven) Source: https://docs.spring.io/spring-pulsar/reference/reference/observability This snippet shows the Maven dependencies required to enable Micrometer Tracing with Zipkin and Brave in a Spring Boot application. It includes the actuator starter, the Brave tracing bridge, and Zipkin reporter components. ```xml org.springframework.boot spring-boot-starter-actuator io.micrometer micrometer-tracing-bridge-brave io.zipkin.reporter2 zipkin-reporter-brave io.zipkin.reporter2 zipkin-sender-urlconnection ``` -------------------------------- ### Get PulsarTopic Number of Partitions Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/core/PulsarTopic Provides the method to get the number of partitions for a PulsarTopic. It returns the value of the numberOfPartitions record component. ```java public int numberOfPartitions() ``` -------------------------------- ### DefaultPulsarClientFactory Methods Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/core/DefaultPulsarClientFactory Documentation for the methods available in DefaultPulsarClientFactory, including creating a Pulsar client and setting the environment. ```APIDOC ## createClient() ### Description Create a Pulsar client instance. ### Method GET ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **org.apache.pulsar.client.api.PulsarClient** - The created client instance. #### Response Example { "example": "PulsarClient instance" } --- ## setEnvironment(Environment environment) ### Description Sets the `Environment` for this application context. ### Method POST ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **environment** (Environment) - The environment to set. ### Request Example N/A ### Response #### Success Response (200) void #### Response Example N/A ``` -------------------------------- ### PulsarAdministration Constructors Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/core/PulsarAdministration Details on how to instantiate the PulsarAdministration class with different configurations. ```APIDOC ## PulsarAdministration Constructors ### Description Constructors for creating instances of `PulsarAdministration`. ### Constructor Details #### `PulsarAdministration(String serviceHttpUrl)` * **Description**: Constructs a default instance using the specified Pulsar service HTTP URL. * **Parameters**: * `serviceHttpUrl` (String) - Required - The admin HTTP service URL for Pulsar. #### `PulsarAdministration(PulsarAdminBuilderCustomizer adminCustomizer)` * **Description**: Constructs an instance with specified customizations for the PulsarAdmin builder. * **Parameters**: * `adminCustomizer` (PulsarAdminBuilderCustomizer) - Optional - The customizer to apply to the builder, or null to use the default admin builder. #### `PulsarAdministration(List adminCustomizers)` * **Description**: Constructs an instance with a list of specified customizations. * **Parameters**: * `adminCustomizers` (List) - Required - The list of customizers to apply to the builder. ``` -------------------------------- ### Pulsar Listener for Batch Consumption of POJOs Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption An example of consuming messages in batches as a list of POJOs. The `batch` property is set to `true`, and `schemaType` is specified for complex types. ```java @PulsarListener(subscriptionName = "hello-batch-subscription", topics = "hello-batch", schemaType = SchemaType.JSON, batch = true) public void listen(List messages) { System.out.println("records received :" + messages.size()); messages.forEach((message) -> System.out.println("record : " + message)); } ``` -------------------------------- ### CaffeineCacheProviderFactory.create with EvictionListener Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/cache/provider/class-use/CacheProviderFactory.EvictionListener Illustrates the creation of a `CaffeineCacheProviderFactory` instance, which also utilizes `CacheProviderFactory.EvictionListener`. ```APIDOC ## POST /api/cache/provider/caffeine ### Description Creates a cache provider instance using the Caffeine cache implementation, accepting an `EvictionListener`. ### Method POST ### Endpoint /api/cache/provider/caffeine ### Parameters #### Query Parameters - **cacheExpireAfterAccess** (Duration) - Optional - The duration after which cache entries expire. - **cacheMaximumSize** (Long) - Optional - The maximum size of the cache. - **cacheInitialCapacity** (Integer) - Optional - The initial capacity of the cache. #### Request Body - **evictionListener** (CacheProviderFactory.EvictionListener) - Required - A listener for cache eviction events. ### Request Example ```json { "evictionListener": "" } ``` ### Response #### Success Response (200) - **CacheProvider** (CacheProvider) - The created Caffeine cache provider instance. #### Response Example ```json { "cacheProviderInstance": "" } ``` ``` -------------------------------- ### Interfaces Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/config/package-tree Documentation for core Pulsar configuration interfaces. ```APIDOC ## ListenerEndpoint ### Description Represents a generic listener endpoint. ### Method N/A (Interface) ### Endpoint N/A (Interface) ### Parameters N/A (Interface) ### Request Example N/A (Interface) ### Response N/A (Interface) ### Response Example N/A (Interface) ## PulsarListenerEndpoint ### Description Extends `ListenerEndpoint` to define a Pulsar-specific listener endpoint. ### Method N/A (Interface) ### Endpoint N/A (Interface) ### Parameters N/A (Interface) ### Request Example N/A (Interface) ### Response N/A (Interface) ### Response Example N/A (Interface) ## PulsarContainerFactory ### Description An interface for Pulsar container factories. ### Method N/A (Interface) ### Endpoint N/A (Interface) ### Parameters N/A (Interface) ### Request Example N/A (Interface) ### Response N/A (Interface) ### Response Example N/A (Interface) ## ListenerContainerFactory ### Description An interface for listener container factories. ### Method N/A (Interface) ### Endpoint N/A (Interface) ### Parameters N/A (Interface) ### Request Example N/A (Interface) ### Response N/A (Interface) ### Response Example N/A (Interface) ## PulsarListenerContainerFactory ### Description Extends `ListenerContainerFactory` for Pulsar listener containers. ### Method N/A (Interface) ### Endpoint N/A (Interface) ### Parameters N/A (Interface) ### Request Example N/A (Interface) ### Response N/A (Interface) ### Response Example N/A (Interface) ## ReaderContainerFactory ### Description An interface for reader container factories. ### Method N/A (Interface) ### Endpoint N/A (Interface) ### Parameters N/A (Interface) ### Request Example N/A (Interface) ### Response N/A (Interface) ### Response Example N/A (Interface) ## PulsarReaderContainerFactory ### Description Extends `ReaderContainerFactory` for Pulsar reader containers. ### Method N/A (Interface) ### Endpoint N/A (Interface) ### Parameters N/A (Interface) ### Request Example N/A (Interface) ### Response N/A (Interface) ### Response Example N/A (Interface) ## PulsarReaderEndpoint ### Description Represents a Pulsar-specific reader endpoint. ### Method N/A (Interface) ### Endpoint N/A (Interface) ### Parameters N/A (Interface) ### Request Example N/A (Interface) ### Response N/A (Interface) ### Response Example N/A (Interface) ``` -------------------------------- ### Pulsar Listener Consuming Integer Messages Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption An example demonstrating how to consume messages of an Integer type. The framework infers the schema type based on the expected Integer type. ```java @PulsarListener(subscriptionName = "my-subscription-1", topics = "my-topic-1") public void listen(Integer message) { System.out.println(message); } ``` -------------------------------- ### Batch Listener with Manual Acknowledgement in Java Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption Example of a batch message listener in Spring for Apache Pulsar that uses the Acknowledgment object to manually acknowledge or negatively acknowledge messages. ```java @PulsarListener(subscriptionName = "hello-pulsar-subscription", topics = "hello-pulsar") public void listen(List> messgaes, Acknowlegement acknowledgment) { for (Message message : messages) { try { ... acknowledgment.acknowledge(message.getMessageId()); } catch (Exception e) { acknowledgment.nack(message.getMessageId()); } } } ``` -------------------------------- ### Create Pulsar Producer with Encryption Keys and Customizers (Java) Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/core/DefaultPulsarProducerFactory This `createProducer` method provides advanced options for creating a Pulsar producer, including schema, topic, encryption keys, and a list of customizers. It allows for fine-grained control over producer configuration, including security settings. ```java public org.apache.pulsar.client.api.Producer createProducer(org.apache.pulsar.client.api.Schema schema, @Nullable String topic, @Nullable Collection encryptionKeys, @Nullable List> customizers) ``` -------------------------------- ### Pulsar Configuration and Annotations Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/index-files/index-17 Configuration classes and annotations for setting up Pulsar listeners and readers. ```APIDOC ## Pulsar Configuration and Annotations ### PulsarListenerEndpointRegistrar #### Description Registrar for Pulsar listener endpoints. #### Methods - `registerAllEndpoints()` ### PulsarReaderEndpointRegistrar #### Description Registrar for Pulsar reader endpoints. #### Methods - `registerAllEndpoints()` ### PulsarBootstrapConfiguration #### Description Bootstrap configuration class for Pulsar. #### Methods - `registerBeanDefinitions(AnnotationMetadata, BeanDefinitionRegistry)` ### @PulsarReader #### Description Annotation for configuring Pulsar readers. #### Element - `readerCustomizer()`: Bean name or SpEL expression for `PulsarReaderReaderBuilderCustomizer`. ``` -------------------------------- ### PulsarListener with Shared Subscription and Concurrency (Java) Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption Shows an example of the `@PulsarListener` annotation configured for a `Shared` subscription with `concurrency` enabled. This allows for multiple consumers to process messages from the same topic. ```java @PulsarListener(topics = "my-topic", subscriptionName = "subscription-1", subscriptionType = SubscriptionType.Shared, concurrency = "5") void listen(String message) { ... } ``` -------------------------------- ### Pulsar Listener Consuming JSON Complex Types Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption This example shows how to consume complex types, specifically JSON, from a Pulsar topic. The `schemaType` property is explicitly set to `SchemaType.JSON`. ```java @PulsarListener(subscriptionName = "my-subscription-2", topics = "my-topic-2", schemaType = SchemaType.JSON) public void listen(Foo message) { System.out.println(message); } ``` -------------------------------- ### Start Pulsar Listener Container Lifecycle (Java) Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/config/GenericListenerEndpointRegistry Starts the lifecycle of the listener container registry. This method is part of the Lifecycle interface and is responsible for initiating the listener containers. It's typically called by the Spring application context during startup. ```java public void start() Specified by: start in interface Lifecycle ``` -------------------------------- ### Create Pulsar Producer with Customizer (Java) Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/core/DefaultPulsarProducerFactory This overloaded `createProducer` method allows for the creation of a Pulsar producer with a specified schema, topic, and an optional `ProducerBuilderCustomizer`. The customizer can be used to apply specific configurations to the producer builder. ```java public org.apache.pulsar.client.api.Producer createProducer(org.apache.pulsar.client.api.Schema schema, @Nullable String topic, @Nullable ProducerBuilderCustomizer customizer) ``` -------------------------------- ### PulsarBootstrapConfiguration Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/index-files/index-16 Configuration class for bootstrapping Pulsar listener annotations. ```APIDOC ## PulsarBootstrapConfiguration ### Description This `ImportBeanDefinitionRegistrar` is responsible for registering the `PulsarListenerAnnotationBeanPostProcessor`, which enables the processing of the `@PulsarListener` annotation within a Spring application context. ### Constructor `PulsarBootstrapConfiguration()` ``` -------------------------------- ### TopicResolver resolveTopic Method Implementation Example Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/core/TopicResolver Provides an example implementation of the resolveTopic method from the TopicResolver interface. This method resolves the topic name to use for a given message, considering user-specified topics and a default topic supplier. ```java Resolved resolveTopic(@Nullable String userSpecifiedTopic, @Nullable T message, Supplier defaultTopicSupplier) { // Implementation details for resolving the topic return null; // Placeholder } ``` -------------------------------- ### Pulsar Bootstrap Configuration Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/annotation/PulsarBootstrapConfiguration Configuration class for enabling Pulsar listeners and registering necessary beans. ```APIDOC ## PulsarBootstrapConfiguration ### Description An `ImportBeanDefinitionRegistrar` class that registers a `PulsarListenerAnnotationBeanPostProcessor` bean capable of processing Spring's @`PulsarListener` annotation. Also registers a default `PulsarListenerEndpointRegistry`. This configuration class is automatically imported when using the @`EnablePulsar` annotation. ### Method `registerBeanDefinitions` ### Endpoint N/A (Configuration Class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example N/A ### Response #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### PulsarAnnotationsConfigurationSelector Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/index-files/index-16 Selects Pulsar bootstrap configuration for annotation-driven setups. ```APIDOC ## PulsarAnnotationsConfigurationSelector ### Description A `DeferredImportSelector` that ensures `PulsarBootstrapConfiguration` is imported late in the application context loading process, typically for annotation-based Pulsar configurations. ### Constructor `PulsarAnnotationsConfiguration`() ``` -------------------------------- ### Spring Boot Application for Pulsar Production and Consumption Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/quick-tour This is a complete Spring Boot application example that produces a message to a Pulsar topic using `PulsarTemplate` and consumes messages from the same topic using `@PulsarListener`. It relies on Spring Boot auto-configuration for Pulsar components. ```java @SpringBootApplication public class PulsarBootHelloWorld { public static void main(String[] args) { SpringApplication.run(PulsarBootHelloWorld.class, args); } @Bean ApplicationRunner runner(PulsarTemplate pulsarTemplate) { return (args) -> pulsarTemplate.send("hello-pulsar-topic", "Hello Pulsar World!"); } @PulsarListener(subscriptionName = "hello-pulsar-sub", topics = "hello-pulsar-topic") void listen(String message) { System.out.println("Message Received: " + message); } } ``` -------------------------------- ### Listener Endpoints Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/config/package-tree Documentation for abstract and concrete Pulsar listener endpoint configurations. ```APIDOC ## AbstractPulsarListenerEndpoint ### Description An abstract base class for Pulsar listener endpoints, providing common functionality and implementing BeanFactoryAware and InitializingBean. ### Method N/A (Class) ### Endpoint N/A (Class) ### Parameters N/A (Class) ### Request Example N/A (Class) ### Response N/A (Class) ### Response Example N/A (Class) ## MethodPulsarListenerEndpoint ### Description A concrete implementation of `AbstractPulsarListenerEndpoint` for method-based Pulsar listeners. ### Method N/A (Class) ### Endpoint N/A (Class) ### Parameters N/A (Class) ### Request Example N/A (Class) ### Response N/A (Class) ### Response Example N/A (Class) ``` -------------------------------- ### Consume Batch Records with PulsarListener (Java) Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption This example shows how to configure a Spring `@PulsarListener` to consume messages in batches from a Pulsar topic. The `batch = true` attribute enables batch consumption, and the listener method receives a `List` of messages. ```java @PulsarListener(subscriptionName = "hello-batch-subscription", topics = "hello-batch", schemaType = SchemaType.JSON, batch = true) public void listen4(List messages) { System.out.println("records received :" + messages.size()); messages.forEach((message) -> System.out.println("record : " + message)); } ``` -------------------------------- ### Access Pulsar Headers in Batch Record Consumer (Java) Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption This example demonstrates accessing Pulsar message headers when consuming messages in batches using Spring's `@PulsarListener`. Both the message payload and the corresponding headers are received as `List`s, ensuring synchronization. ```java @PulsarListener(topics = "simpleBatchListenerWithHeaders", batch = true) void simpleBatchListenerWithHeaders(List data, @Header(PulsarHeaders.MESSAGE_ID) List messageIds, @Header(PulsarHeaders.TOPIC_NAME) List topicNames, @Header("foo") List fooValues) { } ``` -------------------------------- ### ConsumerStartingEvent API Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/event/ConsumerStartingEvent Details about the ConsumerStartingEvent class, including its inheritance, constructors, and methods. ```APIDOC ## ConsumerStartingEvent ### Description Event to publish while the consumer is starting. ### Class Hierarchy `java.lang.Object` `java.util.EventObject` `org.springframework.context.ApplicationEvent` `org.springframework.pulsar.event.PulsarEvent` `org.springframework.pulsar.event.ConsumerStartingEvent` ### Implemented Interfaces `Serializable` ### Constructor Summary #### `ConsumerStartingEvent(Object source, Object container)` Construct an instance with the provided source and container. * **source** (`Object`) - The container instance that generated the event. * **container** (`Object`) - The container or the parent container if the container is a child. ### Method Summary #### `String toString()` Overrides: `toString` in class `EventObject` ### Methods Inherited * **From class `PulsarEvent`**: `getContainer`, `getSource` * **From class `ApplicationEvent`**: `getTimestamp` * **From class `EventObject`**: `getSource` * **From class `Object`**: `clone`, `equals`, `finalize`, `getClass`, `hashCode`, `notify`, `notifyAll`, `wait`, `wait`, `wait` ``` -------------------------------- ### Concurrency and Batching Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/listener/PulsarContainerProperties Configure concurrency and batch processing settings. ```APIDOC ## Concurrency and Batching ### getConcurrency() Returns the concurrency level for message consumption. ### setConcurrency(int concurrency) Sets the concurrency level for message consumption. ### getMaxNumMessages() Returns the maximum number of messages to be received in a single batch. ### setMaxNumMessages(int maxNumMessages) Sets the maximum number of messages to be received in a single batch. ### getMaxNumBytes() Returns the maximum number of bytes to be received in a single batch. ### setMaxNumBytes(int maxNumBytes) Sets the maximum number of bytes to be received in a single batch. ### getBatchTimeoutMillis() Returns the timeout in milliseconds for batch reception. ### setBatchTimeoutMillis(int batchTimeoutMillis) Sets the timeout in milliseconds for batch reception. ### isBatchListener() Checks if batch listener mode is enabled. ### setBatchListener(boolean batchListener) Enables or disables batch listener mode. ``` -------------------------------- ### Configure PulsarConsumerErrorHandler for DLT in Spring Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/message-consumption This Java configuration sets up a `PulsarConsumerErrorHandler` for handling message processing failures. It uses `DefaultPulsarConsumerErrorHandler` with `PulsarDeadLetterPublishingRecoverer` to send messages to a Dead Letter Topic (DLT) after a specified number of retries defined by `FixedBackOff`. The example also includes Pulsar listener methods for both the main topic and the DLT. ```java @EnablePulsar @Configuration class PulsarConsumerErrorHandlerConfig { @Bean PulsarConsumerErrorHandler pulsarConsumerErrorHandler( PulsarTemplate pulsarTemplate) { return new DefaultPulsarConsumerErrorHandler<>( new PulsarDeadLetterPublishingRecoverer<>(pulsarTemplate, (c, m) -> "my-foo-dlt"), new FixedBackOff(100, 10)); } @PulsarListener(id = "pulsarConsumerErrorHandler-id", subscriptionName = "pulsatConsumerErrorHandler-subscription", topics = "pulsarConsumerErrorHandler-topic", pulsarConsumerErrorHandler = "pulsarConsumerErrorHandler") void listen(String msg) { throw new RuntimeException("fail " + msg); } @PulsarListener(id = "pceh-dltListener", topics = "my-foo-dlt") void listenDlt(String msg) { System.out.println("From DLT: " + msg); } } ``` -------------------------------- ### StartupFailurePolicy Enum Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/index-files/index-21 Documentation for the StartupFailurePolicy enum, including valueOf and values methods. ```APIDOC ## StartupFailurePolicy Enum ### Description Defines policies for handling startup failures. ### Methods - **valueOf(String name)**: Returns the enum constant of this class with the specified name. - **values()**: Returns an array containing the constants of this enum class, in the order they are declared. ### Endpoint N/A (Enum) ### Parameters - **name** (String) - Required - The name of the enum constant to return. ### Request Body None ### Response - **enum constant** (StartupFailurePolicy) - The enum constant matching the name, or an exception if not found. - **enum array** (StartupFailurePolicy[]) - An array of all enum constants. ### Request Example ```json { "method": "valueOf", "parameter": "RETRY" } ``` ### Response Example ```json { "result": "RETRY" } ``` ``` -------------------------------- ### PulsarFunctionAdministration Lifecycle Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/function/PulsarFunctionAdministration Manages the lifecycle of Pulsar functions, sinks, and sources, including starting and stopping the administration process. ```APIDOC ## PulsarFunctionAdministration Lifecycle ### Description Manages the lifecycle of Pulsar functions, sinks, and sources. This includes starting the administration process to create or update functions and stopping it to enforce stop policies. ### Methods - **start()**: Starts the PulsarFunctionAdministration process. This typically involves creating or updating user-defined functions. - **stop()**: Stops the PulsarFunctionAdministration process. This involves enforcing the stop policy on functions that were processed during startup. - **isRunning()**: Checks if the PulsarFunctionAdministration process is currently running. ``` -------------------------------- ### Create Pulsar Producer with Schema and Topic (Java) Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/core/DefaultPulsarProducerFactory The `createProducer` method facilitates the creation of a Pulsar producer. It accepts a message schema and an optional topic name. If the topic is null, the default topic configured in the factory will be used. ```java public org.apache.pulsar.client.api.Producer createProducer(org.apache.pulsar.client.api.Schema schema, @Nullable String topic) ``` -------------------------------- ### Message Listener Configuration Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/listener/PulsarContainerProperties Configure the message listener and its executor. ```APIDOC ## Message Listener ### getMessageListener() Returns the configured message listener. ### setMessageListener(Object messageListener) Sets the message listener. ### getConsumerTaskExecutor() Returns the task executor for consumer operations. ### setConsumerTaskExecutor(AsyncTaskExecutor consumerExecutor) Sets the task executor for consumer operations. ``` -------------------------------- ### Pulsar Reader Endpoint Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/index-files/index-7 Provides methods for Pulsar reader endpoints, including retrieving topics and start message ID. ```APIDOC ## GET /websites/spring_io_spring-pulsar/api/reader/endpoint ### Description Retrieves details about a Pulsar reader endpoint. ### Method GET ### Endpoint /websites/spring_io_spring-pulsar/api/reader/endpoint ### Parameters #### Query Parameters - **topics** (array[string]) - Optional - The topics for this endpoint's container. - **startMessageId** (string) - Optional - The start message ID for the reader. ### Response #### Success Response (200) - **topics** (array[string]) - The topics for this endpoint's container. - **startMessageId** (string) - The start message ID for the reader. #### Response Example ```json { "topics": ["topicA", "topicB"], "startMessageId": "1234567890:1:1:0" } ``` ``` -------------------------------- ### PulsarFunctionAdministration - Create/Update Functions Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/function/PulsarFunctionAdministration Handles the creation and updating of user-defined Pulsar functions, sinks, and sources during server startup. ```APIDOC ## POST /functions/createOrUpdateUserDefinedFunctions ### Description Called during server startup, this method creates or updates any Pulsar functions, sinks, or sources registered by the application. Operations are performed serially, and the `failFast` property controls whether processing stops on failure. Failures can be logged or propagated based on the `propagateFailures` setting. ### Method POST ### Endpoint /functions/createOrUpdateUserDefinedFunctions ### Parameters #### Query Parameters - **failFast** (boolean) - Optional - Whether to stop processing when a failure occurs. - **propagateFailures** (boolean) - Optional - Whether to throw an exception when a failure occurs during server startup while creating/updating functions. ### Request Body This endpoint does not require a request body. The functions, sinks, and sources are determined by the `ObjectProvider` beans configured in the application context. ### Response #### Success Response (200) - **status** (string) - Indicates the operation was successful. #### Response Example ```json { "status": "Functions, sinks, and sources created or updated successfully." } ``` #### Error Response (e.g., 500) - **error** (string) - Description of the error. - **details** (string) - Specific details about the failure. #### Error Response Example ```json { "error": "Failed to create or update Pulsar functions.", "details": "PulsarFunctionAdministration.PulsarFunctionException: One or more function operations failed." } ``` ``` -------------------------------- ### org.springframework.pulsar.config Package Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/listener/package-use This package provides Spring configuration classes for the Pulsar framework, enabling easy integration and setup of Pulsar-related beans. ```APIDOC ## Package: org.springframework.pulsar.config ### Description Package containing Spring configuration classes for the framework. ### Usage This package facilitates the configuration of Pulsar components within a Spring application context, allowing for declarative setup of Pulsar producers, consumers, and listener containers. ``` -------------------------------- ### ReaderStartingEvent Constructor Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/event/ReaderStartingEvent Constructs a new ReaderStartingEvent with the provided source and container. ```APIDOC ## ReaderStartingEvent Constructor ### Description Construct an instance with the provided source and container. ### Method `ReaderStartingEvent(Object source, Object container)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "source": "", "container": "" } ``` ### Response #### Success Response (200) ReaderStartingEvent instance #### Response Example ```json { "source": "", "container": "" } ``` ``` -------------------------------- ### PulsarTransactionManager Transaction State Retrieval Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/transaction/PulsarTransactionManager Methods to get the current transaction and check for its existence. These are crucial for managing the transaction lifecycle. ```java protected Object doGetTransaction() { // ... implementation ... } protected boolean isExistingTransaction(Object transaction) { // ... implementation ... } ``` -------------------------------- ### Listener Adapters Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/serialized-form Documentation for adapters used to bridge Pulsar messages to Spring message listeners. ```APIDOC ## Class org.springframework.pulsar.listener.adapter.PulsarBatchMessagesToSpringMessageListenerAdapter ### Description An adapter that converts Pulsar batch messages into Spring messages for listener consumption. ### Method N/A (Class Definition) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## Class org.springframework.pulsar.listener.adapter.PulsarRecordMessageToSpringMessageListenerAdapter ### Description An adapter that converts a single Pulsar record message into a Spring message for listener consumption. ### Method N/A (Class Definition) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## Class org.springframework.pulsar.listener.adapter.PulsarRecordMessageToSpringMessageReaderAdapter ### Description An adapter that converts a Pulsar record message into a Spring message for reader consumption. ### Method N/A (Class Definition) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### PulsarReaderContainerProperties: Schema Resolver Configuration Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/reader/PulsarReaderContainerProperties Methods for setting and getting the schema resolver for Pulsar. This is used when dynamic schema resolution is required for messages. ```java public SchemaResolver getSchemaResolver() public void setSchemaResolver(SchemaResolver schemaResolver) ``` -------------------------------- ### PulsarFunctionAdministration Constructor Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/function/PulsarFunctionAdministration Constructs a PulsarFunctionAdministration instance with specified configurations. ```APIDOC ## PulsarFunctionAdministration Constructor ### Description Constructs a `PulsarFunctionAdministration` instance. This constructor is used internally by the Spring framework to initialize the administration service with necessary dependencies and configuration. ### Parameters - **pulsarAdministration** (PulsarAdministration) - Required - The Pulsar administration client to make API calls with. - **pulsarFunctions** (ObjectProvider) - Required - A provider for Pulsar functions to be created or updated. - **pulsarSinks** (ObjectProvider) - Required - A provider for Pulsar sinks to be created or updated. - **pulsarSources** (ObjectProvider) - Required - A provider for Pulsar sources to be created or updated. - **failFast** (boolean) - Required - Determines if processing should stop immediately upon encountering a failure. - **propagateFailures** (boolean) - Required - Determines if exceptions during function creation/update should be thrown to the caller. - **propagateStopFailures** (boolean) - Required - Determines if exceptions during stop policy enforcement should be thrown to the caller. ``` -------------------------------- ### PulsarReaderContainerProperties: Topics Configuration Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/reader/PulsarReaderContainerProperties Methods for setting and getting the list of topics the Pulsar reader should subscribe to. This allows specifying multiple topics for consumption. ```java public @Nullable List getTopics() public void setTopics(List topics) ``` -------------------------------- ### Pulsar Listener Interfaces and Adapters Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/index-files/index-17 Documentation for Pulsar message listener interfaces and their adapter implementations. ```APIDOC ## Pulsar Listener Interfaces and Adapters ### PulsarBatchAcknowledgingMessageListener #### Description Listener for batch messages with acknowledgment support. #### Methods - `received(Consumer, List)` - `received(Consumer, List, Acknowledgement)` ### PulsarBatchMessageListener #### Description Listener for batch messages. #### Methods - `received(Consumer, List)` - `received(Consumer, List, Acknowledgement)` ### PulsarAcknowledgingMessageListener #### Description Listener for individual messages with acknowledgment support. #### Methods - `received(Consumer, Message)` - `received(Consumer, Message, Acknowledgement)` ### PulsarRecordMessageListener #### Description Listener for individual messages. #### Methods - `received(Consumer, Message, Acknowledgement)` ### PulsarBatchMessagesToSpringMessageListenerAdapter #### Description Adapter for converting batch Pulsar messages to Spring messages. #### Methods - `received(Consumer, List, Acknowledgement)` ### PulsarRecordMessageToSpringMessageListenerAdapter #### Description Adapter for converting individual Pulsar messages to Spring messages. #### Methods - `received(Consumer, Message, Acknowledgement)` ### PulsarRecordMessageToSpringMessageReaderAdapter #### Description Adapter for converting individual Pulsar messages to Spring messages for readers. #### Methods - `received(Reader, Message)` ``` -------------------------------- ### Get Pulsar Function Type Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/function/PulsarSink Retrieves the type of the Pulsar function. This method is inherited from the PulsarFunctionOperations interface. ```java public PulsarFunctionOperations.FunctionType type() Description copied from interface: PulsarFunctionOperations Gets the type of function the operations handles. Specified by: `type` in interface `PulsarFunctionOperations` Returns: the type of the function ``` -------------------------------- ### Get Pulsar Function Name Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/function/PulsarSink Retrieves the name of the Pulsar function. This method is inherited from the PulsarFunctionOperations interface. ```java public String name() Description copied from interface: PulsarFunctionOperations Gets the name of the function. Specified by: `name` in interface `PulsarFunctionOperations` Returns: the name of the function ``` -------------------------------- ### Using TypedMessageBuilderCustomizer with PulsarOperations Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/core/class-use/TypedMessageBuilderCustomizer This section explains how to use the `withMessageCustomizer` method on `PulsarOperations.SendMessageBuilder` to apply custom configurations to messages before they are sent. ```APIDOC ## POST /send/message ### Description Sends a message with custom configurations applied using `TypedMessageBuilderCustomizer`. ### Method POST ### Endpoint `/send/message` ### Parameters #### Query Parameters - **topic** (string) - Required - The topic to send the message to. #### Request Body - **payload** (object) - Required - The message payload. - **messageCustomizer** (TypedMessageBuilderCustomizer) - Optional - A customizer to configure the message builder. ### Request Example ```json { "payload": { "data": "Hello Pulsar!" }, "messageCustomizer": { "//": "This is a placeholder for a TypedMessageBuilderCustomizer implementation" } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "Message sent successfully" } ``` ``` -------------------------------- ### DefaultPulsarProducerFactory Constructors (Java) Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/core/DefaultPulsarProducerFactory Provides constructors for the DefaultPulsarProducerFactory, allowing initialization with a PulsarClient, optional default topic, customizers, and a topic resolver. These constructors enable flexible configuration of producer creation. ```java public DefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient) public DefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient, @Nullable String defaultTopic) public DefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient, @Nullable String defaultTopic, @Nullable List> defaultConfigCustomizers) public DefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient, @Nullable String defaultTopic, @Nullable List> defaultConfigCustomizers, TopicResolver topicResolver) ``` -------------------------------- ### Get Pulsar Function Type Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/function/PulsarSource Retrieves the type of the Pulsar function. This method is inherited from the PulsarFunctionOperations interface. ```java public PulsarFunctionOperations.FunctionType type() ``` -------------------------------- ### Add Spring Boot Pulsar Dependency for Gradle Source: https://docs.spring.io/spring-pulsar/reference/reference/pulsar/quick-tour This snippet demonstrates how to include the `spring-boot-starter-pulsar` dependency in a Gradle project. This dependency enables Spring Boot integration with Apache Pulsar. ```gradle dependencies { implementation 'org.springframework.boot:spring-boot-starter-pulsar:4.0.3-SNAPSHOT' } ``` -------------------------------- ### Get Pulsar Function Name Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/function/PulsarSource Retrieves the name of the Pulsar function. This method is inherited from the PulsarFunctionOperations interface. ```java public String name() ``` -------------------------------- ### PulsarReaderContainerProperties: Schema Configuration Source: https://docs.spring.io/spring-pulsar/docs/2.0.3-SNAPSHOT/api/org/springframework/pulsar/reader/PulsarReaderContainerProperties Methods for setting and getting the Pulsar schema for message deserialization. This ensures that messages are correctly interpreted based on their defined schema. ```java public @Nullable org.apache.pulsar.client.api.Schema getSchema() public void setSchema(@Nullable org.apache.pulsar.client.api.Schema schema) ```