aisofhaoisfh / pulsar-java-spring-boot-starter

Simple pulsar spring boot starter with annotation based consumer/producer registration.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring boot starter for Apache Pulsar

Release Build Status Test Coverage License: MIT Join the chat at https://gitter.im/pulsar-java-spring-boot-starter/community

Quick Start

Simple start consist only from 3 simple steps.

1. Add Maven dependency

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependency>
  <groupId>io.github.majusko</groupId>
  <artifactId>pulsar-java-spring-boot-starter</artifactId>
  <version>${version}</version>
</dependency>

2. Configure Producer

Create your configuration class with all producers you would like to register.

@Configuration
public class TestProducerConfiguration {

    @Bean
    public ProducerFactory producerFactory() {
        return new ProducerFactory()
            .addProducer("my-topic", MyMsg.class)
            .addProducer("other-topic", String.class);
    }
}

Use registered producers by simply injecting the PulsarTemplate into your service.

@Service
class MyProducer {

	@Autowired
	private PulsarTemplate<MyMsg> producer;

	void send(MyMsg msg) {
		producer.send("my-topic", msg);
	}
}

3. Configure Consumer

Annotate your service method with @PulsarConsumer annotation.

@Service
class MyConsumer {
    
    @PulsarConsumer(topic="my-topic", clazz=MyMsg.class)
    void consume(MyMsg msg) { 
        producer.send(TOPIC, msg); 
    }
}

Documentation

Configuration

Default configuration:

pulsar.serviceUrl=pulsar://localhost:6650
pulsar.ioThreads=10
pulsar.listenerThreads=10
pulsar.isEnableTcpNoDelay=false
pulsar.keepAliveIntervalSec=20
pulsar.connectionTimeoutSec=10
pulsar.operationTimeoutSec=15
pulsar.startingBackoffIntervalMs=100
pulsar.maxBackoffIntervalSec=10

Properties explained:

  • pulsar.serviceUrl - URL used to connect to pulsar cluster.
  • pulsar.ioThreads - Number of threads to be used for handling connections to brokers.
  • pulsar.listenerThreads - Set the number of threads to be used for message listeners/subscribers.
  • pulsar.isEnableTcpNoDelay - Whether to use TCP no-delay flag on the connection, to disable Nagle algorithm.
  • pulsar.keepAliveInterval - Keep alive interval for each client-broker-connection.
  • pulsar.connectionTimeoutSec - duration of time to wait for a connection to a broker to be established. If the duration passes without a response from the broker, the connection attempt is dropped.
  • pulsar.operationTimeoutSec - Operation timeout.
  • pulsar.startingBackoffIntervalMs - Duration of time for a backoff interval (Retry algorithm).
  • pulsar.maxBackoffIntervalSec - The maximum duration of time for a backoff interval (Retry algorithm).

Contributing

All contributors are welcome. If you never contributed to the open-source, start with reading the Github Flow.

Roadmap task

  1. Pick a task from simple roadmap in Projects section.
  2. Create a pull request with reference (url) to the task inside the Projects section.
  3. Rest and enjoy the great feeling of being a contributor.

Hotfix

  1. Create an issue
  2. Create a pull request with reference to the issue
  3. Rest and enjoy the great feeling of being a contributor.

About

Simple pulsar spring boot starter with annotation based consumer/producer registration.

License:Other


Languages

Language:Java 100.0%