# spring-boot-starter-data-pulsar **Repository Path**: mrxangel/spring-boot-starter-data-pulsar ## Basic Information - **Project Name**: spring-boot-starter-data-pulsar - **Description**: Spring boot integrates pulsar to simplify the definition and provide convenient, fast and convenient operation - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2021-06-01 - **Last Updated**: 2021-12-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 1. Add Maven dependency ```xml io.gitee.mrxangel spring-boot-starter-data-pulsar 1.2.0 ``` 2. Configure Producer Code examples: ```java @Component public class AlarmPulsarProducer { @PulsarProducer(topic = "persistent://pulsar-9r8ar7mn39/Test/topic1") public String videoProducerTopic1; @PulsarProducer(topic = "persistent://pulsar-9r8ar7mn39/Test/topic2") public String videoProducerTopic2; } ``` 3.Configure Consumer Code examples: ```java @Component public class AlarmPulsarConsumer { @PulsarConsumerListener(destination = "persistent://pulsar-9r8ar7mn39/Test/topic1",subscriptionType = SubscriptionType.Exclusive) public void getMsg(Message message ){ String key = message.getKey(); log.info("=key1=====>{}", key); String topicName = message.getTopicName(); log.info("=topicName1=====>{}", topicName); String jsons = new String(message.getData()); log.info("=getData1=====>{}", jsons); } @PulsarConsumerListener(destination = "persistent://pulsar-9r8ar7mn39/Test/topic2",subscriptionType = SubscriptionType.Exclusive) public void getMsg2(Message message ){ String key = message.getKey(); log.info("=key2=====>{}", key); String topicName = message.getTopicName(); log.info("=topicName2=====>{}", topicName); String jsons = new String(message.getData()); log.info("=getData2=====>{}", jsons); } } ``` 4.PulsarTemplate ```java public class PulsarTests { @Autowired private PulsarTemplate pulsarTemplate; @org.junit.Test public void testProducerSendMethod() throws PulsarClientException { pulsarTemplate.send("persistent://pulsar-9r8ar7mn39/Test/topic1", "test"); pulsarTemplate.sendDelay("persistent://pulsar-9r8ar7mn39/Test/topic2", "test-1",1, TimeUnit.SECONDS); } } ``` 5.Configure Properties Quick configuration ```xml pulsar.serviceUrl=pulsar://192.168.0.238:6650/ ``` Optional configuration ```xml pulsar.listenerName= pulsar.jwtKey= #proucer pulsar.enableBatching=true #消息压缩(四种压缩方式:0:NONE 1:LZ4:2:ZLIB:3:ZSTD:4:SNAPPY) pulsar.compressionType=1 pulsar.batchingMaxPublishDelay=10 pulsar.sendTimeout=0 pulsar.batchingMaxMessages=1000 pulsar.maxPendingMessages=1000 pulsar.blockIfQueueFull=true pulsar.roundRobinRouterBatchingPartitionSwitchFrequency=10 #0:DEFAULT 1:KEY_BASED pulsar.batcherBuilder=0 #consumer pulsar.subscription=topicGroup #0:Latest 1:Earliest pulsar.subscriptionInitialPosition=1 pulsar.negativeAckRedeliveryDelay=60 ```