Add support for Apache Pulsar
Add support for Apache Pulsar using the Spring for Apache Pulsar project. See gh-34763 Co-authored-by: Phillip Webb <pwebb@vmware.com>
This commit is contained in:
@@ -90,6 +90,7 @@
|
||||
:spring-integration: https://spring.io/projects/spring-integration
|
||||
:spring-integration-docs: https://docs.spring.io/spring-integration/docs/{spring-integration-version}/reference/html/
|
||||
:spring-kafka-docs: https://docs.spring.io/spring-kafka/docs/{spring-kafka-version}/reference/html/
|
||||
:spring-pulsar-docs: https://docs.spring.io/spring-pulsar/docs/{spring-pulsar-version}/reference/html/
|
||||
:spring-restdocs: https://spring.io/projects/spring-restdocs
|
||||
:spring-security: https://spring.io/projects/spring-security
|
||||
:spring-security-docs: https://docs.spring.io/spring-security/reference/{spring-security-version}
|
||||
|
||||
@@ -5,5 +5,6 @@ If your application uses any messaging protocol, see one or more of the followin
|
||||
* *JMS:* <<messaging#messaging.jms, Auto-configuration for ActiveMQ and Artemis, Sending and Receiving messages through JMS>>
|
||||
* *AMQP:* <<messaging#messaging.amqp, Auto-configuration for RabbitMQ>>
|
||||
* *Kafka:* <<messaging#messaging.kafka, Auto-configuration for Spring Kafka>>
|
||||
* *Pulsar:* <<messaging#messaging.pulsar, Auto-configuration for Spring Pulsar>>
|
||||
* *RSocket:* <<messaging#messaging.rsocket, Auto-configuration for Spring Framework's RSocket Support>>
|
||||
* *Spring Integration:* <<messaging#messaging.spring-integration, Auto-configuration for Spring Integration>>
|
||||
|
||||
@@ -104,4 +104,3 @@ In addition, the `SslBundle` provides details about the key being used, the prot
|
||||
The following example shows retrieving an `SslBundle` and using it to create an `SSLContext`:
|
||||
|
||||
include::code:MyComponent[]
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ The reference documentation consists of the following sections:
|
||||
<<web#web,Web>> :: Servlet Web, Reactive Web, Embedded Container Support, Graceful Shutdown, and more.
|
||||
<<data#data,Data>> :: SQL and NOSQL data access.
|
||||
<<io#io,IO>> :: Caching, Quartz Scheduler, REST clients, Sending email, Spring Web Services, and more.
|
||||
<<messaging#messaging,Messaging>> :: JMS, AMQP, Apache Kafka, RSocket, WebSocket, and Spring Integration.
|
||||
<<messaging#messaging,Messaging>> :: JMS, AMQP, Apache Kafka, Apache Pulsar, RSocket, WebSocket, and Spring Integration.
|
||||
<<container-images#container-images,Container Images>> :: Efficient container images and Building container images with Dockerfiles and Cloud Native Buildpacks.
|
||||
<<actuator#actuator,Production-ready Features>> :: Monitoring, Metrics, Auditing, and more.
|
||||
<<deployment#deployment,Deploying Spring Boot Applications>> :: Deploying to the Cloud, and Installing as a Unix application.
|
||||
|
||||
@@ -6,7 +6,7 @@ The Spring Framework provides extensive support for integrating with messaging s
|
||||
Spring AMQP provides a similar feature set for the Advanced Message Queuing Protocol.
|
||||
Spring Boot also provides auto-configuration options for `RabbitTemplate` and RabbitMQ.
|
||||
Spring WebSocket natively includes support for STOMP messaging, and Spring Boot has support for that through starters and a small amount of auto-configuration.
|
||||
Spring Boot also has support for Apache Kafka.
|
||||
Spring Boot also has support for Apache Kafka and Apache Pulsar.
|
||||
|
||||
|
||||
include::messaging/jms.adoc[]
|
||||
@@ -15,6 +15,8 @@ include::messaging/amqp.adoc[]
|
||||
|
||||
include::messaging/kafka.adoc[]
|
||||
|
||||
include::messaging/pulsar.adoc[]
|
||||
|
||||
include::messaging/rsocket.adoc[]
|
||||
|
||||
include::messaging/spring-integration.adoc[]
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
[[messaging.pulsar]]
|
||||
== Apache Pulsar Support
|
||||
https://pulsar.apache.org/[Apache Pulsar] is supported by providing auto-configuration of the {spring-pulsar-docs}[Spring for Apache Pulsar] project.
|
||||
|
||||
Spring Boot will auto-configure and register the classic (imperative) Spring Pulsar components when `org.springframework.pulsar:spring-pulsar` is on the classpath.
|
||||
It will do the same for the reactive components when `org.springframework.pulsar:spring-pulsar-reactive` is on the classpath.
|
||||
|
||||
There are `spring-boot-starter-pulsar` and `spring-boot-starter-pulsar-reactive` "`Starters`" for conveniently collecting the dependencies for imperative and reactive use, respectively.
|
||||
|
||||
|
||||
|
||||
[[messaging.pulsar.connecting]]
|
||||
=== Connecting to Pulsar
|
||||
When you use the Pulsar starter, Spring Boot will auto-configure and register a `PulsarClient` bean.
|
||||
|
||||
By default, the application tries to connect to a local Pulsar instance at `pulsar://localhost:6650`.
|
||||
This can be adjusted by setting the configprop:spring.pulsar.client.service-url[] property to a different value.
|
||||
|
||||
NOTE: The value must be a valid https://pulsar.apache.org/docs/client-libraries-java/#connection-urls[Pulsar Protocol] URL
|
||||
|
||||
You can configure the client by specifying any of the `spring.pulsar.client.*` prefixed application properties.
|
||||
|
||||
If you need more control over the configuration, consider registering one or more `PulsarClientBuilderCustomizer` beans.
|
||||
|
||||
|
||||
|
||||
[[messaging.pulsar.connecting.auth]]
|
||||
==== Authentication
|
||||
To connect to a Pulsar cluster that requires authentication, you need to specify which authentication plugin to use by setting the `authPluginClassName` and any parameters required by the plugin.
|
||||
You can set the parameters as a map of parameter names to parameter values.
|
||||
The following example shows how to configure the `AuthenticationOAuth2` plugin.
|
||||
|
||||
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
|
||||
----
|
||||
spring:
|
||||
pulsar:
|
||||
client:
|
||||
authentication:
|
||||
plugin-class-name: org.apache.pulsar.client.impl.auth.oauth2.AuthenticationOAuth2
|
||||
param:
|
||||
issuerUrl: https://auth.server.cloud/
|
||||
privateKey: file:///Users/some-key.json
|
||||
audience: urn:sn:acme:dev:my-instance
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
You need to ensure that names defined under `+spring.pulsar.client.authentication.param.*+` exactly match those expected by your auth plugin (which is typically camel cased).
|
||||
Spring Boot will not attempt any kind of relaxed binding for these entries.
|
||||
|
||||
For example, if you want to configure the issuer url for the `AuthenticationOAuth2` auth plugin you must use `+spring.pulsar.client.authentication.param.issuerUrl+`.
|
||||
If you use other forms, such as `issuerurl` or `issuer-url`, the setting will not be applied to the plugin.
|
||||
====
|
||||
|
||||
For complete details on the client and authentication see the Spring Pulsar {spring-pulsar-docs}#pulsar-client[reference documentation].
|
||||
|
||||
|
||||
|
||||
[[messaging.pulsar.connecting-reactive]]
|
||||
=== Connecting to Pulsar Reactively
|
||||
When the Reactive auto-configuration is activated, Spring Boot will auto-configure and register a `ReactivePulsarClient` bean.
|
||||
|
||||
The `ReactivePulsarClient` adapts an instance of the previously described `PulsarClient`.
|
||||
Therefore, follow the previous section to configure the `PulsarClient` used by the `ReactivePulsarClient`.
|
||||
|
||||
|
||||
|
||||
[[messaging.pulsar.admin]]
|
||||
=== Connecting to Pulsar Administration
|
||||
Spring Pulsar's `PulsarAdministration` client is also auto-configured.
|
||||
|
||||
By default, the application tries to connect to a local Pulsar instance at `\http://localhost:8080`.
|
||||
This can be adjusted by setting the configprop:spring.pulsar.admin.service-url[] property to a different value in the form `(http|https)://<host>:<port>`.
|
||||
|
||||
If you need more control over the configuration, consider registering one or more `PulsarAdminBuilderCustomizer` beans.
|
||||
|
||||
|
||||
[[messaging.pulsar.admin.auth]]
|
||||
==== Authentication
|
||||
When accessing a Pulsar cluster that requires authentication, the admin client requires the same security configuration as the regular Pulsar client.
|
||||
You can use the aforementioned <<pulsar.adoc#messaging.pulsar.connecting.auth,authentication configuration>> by replacing `spring.pulsar.client.authentication` with `spring.pulsar.admin.authentication`.
|
||||
|
||||
TIP: To create a topic on startup, add a bean of type `PulsarTopic`.
|
||||
If the topic already exists, the bean is ignored.
|
||||
|
||||
|
||||
|
||||
[[messaging.pulsar.sending]]
|
||||
=== Sending a Message
|
||||
Spring's `PulsarTemplate` is auto-configured, and you can use it to send messages, as shown in the following example:
|
||||
|
||||
include::code:MyBean[]
|
||||
|
||||
The `PulsarTemplate` relies on a `PulsarProducerFactory` to create the underlying Pulsar producer.
|
||||
Spring Boot auto-configuration also provides this producer factory, which by default, caches the producers that it creates.
|
||||
You can configure the producer factory and cache settings by specifying any of the `spring.pulsar.producer.\*` and `spring.pulsar.producer.cache.*` prefixed application properties.
|
||||
|
||||
If you need more control over the producer factory configuration, consider registering one or more `ProducerBuilderCustomizer` beans.
|
||||
These customizers are applied to all created producers.
|
||||
You can also pass in a `ProducerBuilderCustomizer` when sending a message to only affect the current producer.
|
||||
|
||||
If you need more control over the message being sent, you can pass in a `TypedMessageBuilderCustomizer` when sending a message.
|
||||
|
||||
|
||||
|
||||
[[messaging.pulsar.sending-reactive]]
|
||||
=== Sending a Message Reactively
|
||||
When the Reactive auto-configuration is activated, Spring's `ReactivePulsarTemplate` is auto-configured, and you can use it to send messages, as shown in the following example:
|
||||
|
||||
include::code:MyBean[]
|
||||
|
||||
The `ReactivePulsarTemplate` relies on a `ReactivePulsarSenderFactory` to actually create the underlying sender.
|
||||
Spring Boot auto-configuration also provides this sender factory, which by default, caches the producers that it creates.
|
||||
You can configure the sender factory and cache settings by specifying any of the `spring.pulsar.producer.\*` and `spring.pulsar.producer.cache.*` prefixed application properties.
|
||||
|
||||
If you need more control over the sender factory configuration, consider registering one or more `ReactiveMessageSenderBuilderCustomizer` beans.
|
||||
These customizers are applied to all created senders.
|
||||
You can also pass in a `ReactiveMessageSenderBuilderCustomizer` when sending a message to only affect the current sender.
|
||||
|
||||
If you need more control over the message being sent, you can pass in a `MessageSpecBuilderCustomizer` when sending a message.
|
||||
|
||||
|
||||
|
||||
[[messaging.pulsar.receiving]]
|
||||
=== Receiving a Message
|
||||
When the Apache Pulsar infrastructure is present, any bean can be annotated with `@PulsarListener` to create a listener endpoint.
|
||||
The following component creates a listener endpoint on the `someTopic` topic:
|
||||
|
||||
include::code:MyBean[]
|
||||
|
||||
Spring Boot auto-configuration provides all the components necessary for `PulsarListener`, such as the `PulsarListenerContainerFactory` and the consumer factory it uses to construct the underlying Pulsar consumers.
|
||||
You can configure these components by specifying any of the `spring.pulsar.listener.\*` and `spring.pulsar.consumer.*` prefixed application properties.
|
||||
|
||||
If you need more control over the consumer factory configuration, consider registering one or more `ConsumerBuilderCustomizer` beans.
|
||||
These customizers are applied to all consumers created by the factory, and therefore all `@PulsarListener` instances.
|
||||
You can also customize a single listener by setting the `consumerCustomizer` attribute of the `@PulsarListener` annotation.
|
||||
|
||||
|
||||
|
||||
[[messaging.pulsar.receiving-reactive]]
|
||||
=== Receiving a Message Reactively
|
||||
When the Apache Pulsar infrastructure is present and the Reactive auto-configuration is activated, any bean can be annotated with `@ReactivePulsarListener` to create a reactive listener endpoint.
|
||||
The following component creates a reactive listener endpoint on the `someTopic` topic:
|
||||
|
||||
include::code:MyBean[]
|
||||
|
||||
Spring Boot auto-configuration provides all the components necessary for `ReactivePulsarListener`, such as the `ReactivePulsarListenerContainerFactory` and the consumer factory it uses to construct the underlying reactive Pulsar consumers.
|
||||
You can configure these components by specifying any of the `spring.pulsar.listener.*` and `spring.pulsar.consumer.*` prefixed application properties.
|
||||
|
||||
If you need more control over the consumer factory configuration, consider registering one or more `ReactiveMessageConsumerBuilderCustomizer` beans.
|
||||
These customizers are applied to all consumers created by the factory, and therefore all `@ReactivePulsarListener` instances.
|
||||
You can also customize a single listener by setting the `consumerCustomizer` attribute of the `@ReactivePulsarListener` annotation.
|
||||
|
||||
|
||||
|
||||
[[messaging.pulsar.reading]]
|
||||
=== Reading a Message
|
||||
The Pulsar reader interface enables applications to manually manage cursors.
|
||||
When you use a reader to connect to a topic you need to specify which message the reader begins reading from when it connects to a topic.
|
||||
|
||||
When the Apache Pulsar infrastructure is present, any bean can be annotated with `@PulsarReader` to consume messages using a reader.
|
||||
The following component creates a reader endpoint that starts reading messages from the beginning of the `someTopic` topic:
|
||||
|
||||
include::code:MyBean[]
|
||||
|
||||
The `@PulsarReader` relies on a `PulsarReaderFactory` to create the underlying Pulsar reader.
|
||||
Spring Boot auto-configuration provides this reader factory which can be customized by setting any of the `spring.pulsar.reader.*` prefixed application properties.
|
||||
|
||||
If you need more control over the reader factory configuration, consider registering one or more `ReaderBuilderCustomizer` beans.
|
||||
These customizers are applied to all readers created by the factory, and therefore all `@PulsarReader` instances.
|
||||
You can also customize a single listener by setting the `readerCustomizer` attribute of the `@PulsarReader` annotation.
|
||||
|
||||
|
||||
|
||||
[[messaging.pulsar.reading-reactive]]
|
||||
=== Reading a Message Reactively
|
||||
When the Apache Pulsar infrastructure is present and the Reactive auto-configuration is activated, Spring's `ReactivePulsarReaderFactory` is provided, and you can use it to create a reader in order to read messages in a reactive fashion.
|
||||
The following component creates a reader using the provided factory and reads a single message from 5 minutes ago from the `someTopic` topic:
|
||||
|
||||
include::code:MyBean[]
|
||||
|
||||
Spring Boot auto-configuration provides this reader factory which can be customized by setting any of the `spring.pulsar.reader.*` prefixed application properties.
|
||||
|
||||
If you need more control over the reader factory configuration, consider passing in one or more `ReactiveMessageReaderBuilderCustomizer` instances when using the factory to create a reader.
|
||||
|
||||
If you need more control over the reader factory configuration, consider registering one or more `ReactiveMessageReaderBuilderCustomizer` beans.
|
||||
These customizers are applied to all created readers.
|
||||
You can also pass one or more `ReactiveMessageReaderBuilderCustomizer` when creating a reader to only apply the customizations to the created reader.
|
||||
|
||||
TIP: For more details on any of the above components and to discover other available features, see the Spring for Apache Pulsar {spring-pulsar-docs}[reference documentation].
|
||||
|
||||
|
||||
|
||||
[[messaging.pulsar.additional-properties]]
|
||||
=== Additional Pulsar Properties
|
||||
The properties supported by auto-configuration are shown in the <<application-properties#appendix.application-properties.integration, "`Integration Properties`">> section of the Appendix.
|
||||
Note that, for the most part, these properties (hyphenated or camelCase) map directly to the Apache Pulsar configuration properties.
|
||||
See the Apache Pulsar documentation for details.
|
||||
|
||||
Only a subset of the properties supported by Pulsar are available directly through the `PulsarProperties` class.
|
||||
If you wish to tune the auto-configured components with additional properties that are not directly supported, you can use the customizer supported by each aforementioned component.
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.pulsar.reading;
|
||||
|
||||
import org.springframework.pulsar.annotation.PulsarReader;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
@PulsarReader(topics = "someTopic", startMessageId = "earliest")
|
||||
public void processMessage(String content) {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.pulsar.readingreactive;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.pulsar.client.api.Message;
|
||||
import org.apache.pulsar.client.api.Schema;
|
||||
import org.apache.pulsar.reactive.client.api.StartAtSpec;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.pulsar.reactive.core.ReactiveMessageReaderBuilderCustomizer;
|
||||
import org.springframework.pulsar.reactive.core.ReactivePulsarReaderFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
private final ReactivePulsarReaderFactory<String> pulsarReaderFactory;
|
||||
|
||||
public MyBean(ReactivePulsarReaderFactory<String> pulsarReaderFactory) {
|
||||
this.pulsarReaderFactory = pulsarReaderFactory;
|
||||
}
|
||||
|
||||
public void someMethod() {
|
||||
ReactiveMessageReaderBuilderCustomizer<String> readerBuilderCustomizer = (readerBuilder) -> readerBuilder
|
||||
.topic("someTopic")
|
||||
.startAtSpec(StartAtSpec.ofInstant(Instant.now().minusSeconds(5)));
|
||||
Mono<Message<String>> message = this.pulsarReaderFactory
|
||||
.createReader(Schema.STRING, List.of(readerBuilderCustomizer))
|
||||
.readOne();
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.pulsar.receiving;
|
||||
|
||||
import org.springframework.pulsar.annotation.PulsarListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
@PulsarListener(topics = "someTopic")
|
||||
public void processMessage(String content) {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.pulsar.receivingreactive;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.pulsar.reactive.config.annotation.ReactivePulsarListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
@ReactivePulsarListener(topics = "someTopic")
|
||||
public Mono<Void> processMessage(String content) {
|
||||
// ...
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.pulsar.sending;
|
||||
|
||||
import org.apache.pulsar.client.api.PulsarClientException;
|
||||
|
||||
import org.springframework.pulsar.core.PulsarTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
private final PulsarTemplate<String> pulsarTemplate;
|
||||
|
||||
public MyBean(PulsarTemplate<String> pulsarTemplate) {
|
||||
this.pulsarTemplate = pulsarTemplate;
|
||||
}
|
||||
|
||||
public void someMethod() throws PulsarClientException {
|
||||
this.pulsarTemplate.send("someTopic", "Hello");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.pulsar.sendingreactive;
|
||||
|
||||
import org.springframework.pulsar.reactive.core.ReactivePulsarTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
private final ReactivePulsarTemplate<String> pulsarTemplate;
|
||||
|
||||
public MyBean(ReactivePulsarTemplate<String> pulsarTemplate) {
|
||||
this.pulsarTemplate = pulsarTemplate;
|
||||
}
|
||||
|
||||
public void someMethod() {
|
||||
this.pulsarTemplate.send("someTopic", "Hello").subscribe();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.pulsar.reading
|
||||
|
||||
import org.springframework.pulsar.annotation.PulsarReader
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
@Component
|
||||
class MyBean {
|
||||
|
||||
@PulsarReader(topics = ["someTopic"], startMessageId = "earliest")
|
||||
fun processMessage(content: String?) {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.pulsar.readingreactive
|
||||
|
||||
import org.apache.pulsar.client.api.Schema
|
||||
import org.apache.pulsar.reactive.client.api.ReactiveMessageReaderBuilder
|
||||
import org.apache.pulsar.reactive.client.api.StartAtSpec
|
||||
import org.springframework.pulsar.reactive.core.ReactiveMessageReaderBuilderCustomizer
|
||||
import org.springframework.pulsar.reactive.core.ReactivePulsarReaderFactory
|
||||
import org.springframework.stereotype.Component
|
||||
import java.time.Instant
|
||||
|
||||
@Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE")
|
||||
@Component
|
||||
class MyBean(private val pulsarReaderFactory: ReactivePulsarReaderFactory<String>) {
|
||||
|
||||
fun someMethod() {
|
||||
val readerBuilderCustomizer = ReactiveMessageReaderBuilderCustomizer {
|
||||
readerBuilder: ReactiveMessageReaderBuilder<String> ->
|
||||
readerBuilder
|
||||
.topic("someTopic")
|
||||
.startAtSpec(StartAtSpec.ofInstant(Instant.now().minusSeconds(5)))
|
||||
}
|
||||
val message = pulsarReaderFactory
|
||||
.createReader(Schema.STRING, listOf(readerBuilderCustomizer))
|
||||
.readOne()
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.pulsar.receiving
|
||||
|
||||
import org.springframework.pulsar.annotation.PulsarListener
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
@Component
|
||||
class MyBean {
|
||||
|
||||
@PulsarListener(topics = ["someTopic"])
|
||||
fun processMessage(content: String?) {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.boot.docs.messaging.pulsar.receivingreactive
|
||||
|
||||
import org.springframework.pulsar.reactive.config.annotation.ReactivePulsarListener
|
||||
import org.springframework.stereotype.Component
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Component
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
class MyBean {
|
||||
|
||||
@ReactivePulsarListener(topics = ["someTopic"])
|
||||
fun processMessage(content: String?): Mono<Void> {
|
||||
// ...
|
||||
return Mono.empty()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.messaging.pulsar.sending
|
||||
|
||||
import org.apache.pulsar.client.api.PulsarClientException
|
||||
import org.springframework.kafka.core.KafkaTemplate
|
||||
import org.springframework.pulsar.core.PulsarTemplate
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class MyBean(private val pulsarTemplate: PulsarTemplate<String>) {
|
||||
|
||||
@Throws(PulsarClientException::class)
|
||||
fun someMethod() {
|
||||
pulsarTemplate.send("someTopic", "Hello")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.boot.docs.messaging.pulsar.sendingreactive
|
||||
|
||||
import org.springframework.pulsar.reactive.core.ReactivePulsarTemplate
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class MyBean(private val pulsarTemplate: ReactivePulsarTemplate<String>) {
|
||||
|
||||
fun someMethod() {
|
||||
pulsarTemplate.send("someTopic", "Hello").subscribe()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user