{"id":15330301,"url":"https://github.com/wolfstudy/pulsar-cpp-examples","last_synced_at":"2025-10-27T07:12:09.884Z","repository":{"id":73616440,"uuid":"286494785","full_name":"wolfstudy/pulsar-cpp-examples","owner":"wolfstudy","description":null,"archived":false,"fork":false,"pushed_at":"2020-08-11T06:42:06.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-19T20:56:22.165Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wolfstudy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-10T14:17:21.000Z","updated_at":"2020-08-11T06:42:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"4779d5d4-f380-4f0e-ab91-524cbef94ced","html_url":"https://github.com/wolfstudy/pulsar-cpp-examples","commit_stats":{"total_commits":6,"total_committers":2,"mean_commits":3.0,"dds":"0.16666666666666663","last_synced_commit":"55cfaff8f3f89e4ff49f670a5adf590ba302d821"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfstudy%2Fpulsar-cpp-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfstudy%2Fpulsar-cpp-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfstudy%2Fpulsar-cpp-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfstudy%2Fpulsar-cpp-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wolfstudy","download_url":"https://codeload.github.com/wolfstudy/pulsar-cpp-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243332316,"owners_count":20274454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T09:52:35.662Z","updated_at":"2025-10-27T07:12:04.835Z","avatar_url":"https://github.com/wolfstudy.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pulsar-cpp-examples\n\n\n- Broker version: 2.6.1\n- Pulsar Client lib version: 2.6.1\n\n## How to use TestExclusiveMessage\n\n1. Run Pulsar standalone\n\n```bash\n$ bin/pulsar standalone\n```\n\n2. Install pulsar-client-cpp lib\n\n**MacOS**\n\n```bash\n$ brew install libpulsar\n```\n\nYou can also choose to build from pulsar-client-cpp, as follows:\n\n```bash\n$ cmake . \u0026\u0026 make \u0026\u0026 make install\n```\n\n\u003e Please refer to [here](https://pulsar.apache.org/docs/en/develop-cpp/) how to install related dependencies of pulsar-client-cpp\n\n3. Run TestExclusiveMessage.cc\n\n```bash\n$ g++ --std=c++11 TestExclusiveMessage.cc -o testExclusiveMsg -I$HOME/github.com/apache/pulsar/pulsar-client-cpp/include -lpulsar -L$HOME/github.com/apache/pulsar/pulsar-client-cpp/lib\n$ ./testExclusiveMsg\n```\n\n4. Output as follows:\n\n```text\n2020-08-10 22:16:11.241 INFO  [0x116a555c0] Client:88 | Subscribing on Topic :test-exclusive-topic-4\n2020-08-10 22:16:11.245 INFO  [0x116a555c0] ConnectionPool:85 | Created connection for pulsar://localhost:6650\n2020-08-10 22:16:11.255 INFO  [0x70000c1b9000] ClientConnection:343 | [127.0.0.1:50580 -\u003e 127.0.0.1:6650] Connected to broker\n2020-08-10 22:16:11.275 INFO  [0x70000c1b9000] HandlerBase:53 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 0] Getting connection from pool\n2020-08-10 22:16:11.490 INFO  [0x70000c1b9000] ConsumerImpl:199 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 0] Created consumer on broker [127.0.0.1:50580 -\u003e 127.0.0.1:6650] \n2020-08-10 22:16:11.497 INFO  [0x70000c1b9000] BatchMessageContainer:43 | { BatchContainer [size = 0] [batchSizeInBytes_ = 0] [maxAllowedMessageBatchSizeInBytes_ = 131072] [maxAllowedNumMessagesInBatch_ = 1000] [topicName = persistent://public/default/test-exclusive-topic-4] [producerName_ = ] [batchSizeInBytes_ = 0] [numberOfBatchesSent = 0] [averageBatchSize = 0]} BatchMessageContainer constructed\n2020-08-10 22:16:11.497 INFO  [0x70000c1b9000] HandlerBase:53 | [persistent://public/default/test-exclusive-topic-4, ] Getting connection from pool\n2020-08-10 22:16:11.519 INFO  [0x70000c1b9000] ProducerImpl:165 | [persistent://public/default/test-exclusive-topic-4, ] Created producer on broker [127.0.0.1:50580 -\u003e 127.0.0.1:6650] \nMessage sent: Ok and payload is: msg-exclusive-0\nMessage sent: Ok and payload is: msg-exclusive-1\nMessage sent: Ok and payload is: msg-exclusive-2\nMessage sent: Ok and payload is: msg-exclusive-3\nMessage sent: Ok and payload is: msg-exclusive-4\nMessage sent: Ok and payload is: msg-exclusive-5\nMessage sent: Ok and payload is: msg-exclusive-6\nMessage sent: Ok and payload is: msg-exclusive-7\nMessage sent: Ok and payload is: msg-exclusive-8\nMessage sent: Ok and payload is: msg-exclusive-9\nReceived: Message(prod=standalone-0-8, seq=0, publish_time=1597068971519, payload_size=15, msg_id=(52,0,-1,0), props={})  with payload 'msg-exclusive-0'\nLast message ID: (52,0,-1,0)\nReceived: Message(prod=standalone-0-8, seq=1, publish_time=1597068971528, payload_size=15, msg_id=(52,1,-1,0), props={})  with payload 'msg-exclusive-1'\nLast message ID: (52,1,-1,0)\nReceived: Message(prod=standalone-0-8, seq=2, publish_time=1597068971538, payload_size=15, msg_id=(52,2,-1,0), props={})  with payload 'msg-exclusive-2'\nLast message ID: (52,2,-1,0)\nReceived: Message(prod=standalone-0-8, seq=3, publish_time=1597068971541, payload_size=15, msg_id=(52,3,-1,0), props={})  with payload 'msg-exclusive-3'\nLast message ID: (52,3,-1,0)\nReceived: Message(prod=standalone-0-8, seq=4, publish_time=1597068971544, payload_size=15, msg_id=(52,4,-1,0), props={})  with payload 'msg-exclusive-4'\nLast message ID: (52,4,-1,0)\nReceived: Message(prod=standalone-0-8, seq=5, publish_time=1597068971548, payload_size=15, msg_id=(52,5,-1,0), props={})  with payload 'msg-exclusive-5'\nLast message ID: (52,5,-1,0)\nReceived: Message(prod=standalone-0-8, seq=6, publish_time=1597068971551, payload_size=15, msg_id=(52,6,-1,0), props={})  with payload 'msg-exclusive-6'\nLast message ID: (52,6,-1,0)\nReceived: Message(prod=standalone-0-8, seq=7, publish_time=1597068971554, payload_size=15, msg_id=(52,7,-1,0), props={})  with payload 'msg-exclusive-7'\nLast message ID: (52,7,-1,0)\nReceived: Message(prod=standalone-0-8, seq=8, publish_time=1597068971561, payload_size=15, msg_id=(52,8,-1,0), props={})  with payload 'msg-exclusive-8'\nLast message ID: (52,8,-1,0)\nReceived: Message(prod=standalone-0-8, seq=9, publish_time=1597068971565, payload_size=15, msg_id=(52,9,-1,0), props={})  with payload 'msg-exclusive-9'\nLast message ID: (52,9,-1,0)\n2020-08-10 22:16:11.572 INFO  [0x116a555c0] ConsumerImpl:866 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 0] Closing consumer for topic persistent://public/default/test-exclusive-topic-4\n2020-08-10 22:16:11.575 INFO  [0x70000c1b9000] ConsumerImpl:920 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 0] Closed consumer 0\nMessage sent: Ok and payload is: msg-exclusive-10\nMessage sent: Ok and payload is: msg-exclusive-11\nMessage sent: Ok and payload is: msg-exclusive-12\nMessage sent: Ok and payload is: msg-exclusive-13\nMessage sent: Ok and payload is: msg-exclusive-14\nMessage sent: Ok and payload is: msg-exclusive-15\nMessage sent: Ok and payload is: msg-exclusive-16\nMessage sent: Ok and payload is: msg-exclusive-17\nMessage sent: Ok and payload is: msg-exclusive-18\nMessage sent: Ok and payload is: msg-exclusive-19\n2020-08-10 22:16:11.608 INFO  [0x116a555c0] Client:88 | Subscribing on Topic :test-exclusive-topic-4\n2020-08-10 22:16:11.610 INFO  [0x70000c1b9000] HandlerBase:53 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 1] Getting connection from pool\n2020-08-10 22:16:11.636 INFO  [0x70000c1b9000] ConsumerImpl:199 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 1] Created consumer on broker [127.0.0.1:50580 -\u003e 127.0.0.1:6650] \n2020-08-10 22:16:11.636 INFO  [0x70000c1b9000] ConsumerImpl:845 | Broker notification of Closed consumer: 1\n2020-08-10 22:16:11.636 INFO  [0x70000c1b9000] HandlerBase:130 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 1] Schedule reconnection in 0.1 s\n2020-08-10 22:16:11.642 INFO  [0x70000c1b9000] ConsumerImpl:1068 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 1] Seek successfully\n2020-08-10 22:16:11.741 INFO  [0x70000c1b9000] HandlerBase:53 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 1] Getting connection from pool\n2020-08-10 22:16:11.776 INFO  [0x70000c1b9000] ConsumerImpl:199 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 1] Created consumer on broker [127.0.0.1:50580 -\u003e 127.0.0.1:6650] \nSlept 2 seconds and open a new consumer to seek it to: (52,9,-1,0)\nReceived again: Message(prod=standalone-0-8, seq=9, publish_time=1597068971565, payload_size=15, msg_id=(52,9,-1,0), props={})  with payload 'msg-exclusive-9'\nReceived again: Message(prod=standalone-0-8, seq=10, publish_time=1597068971575, payload_size=16, msg_id=(52,10,-1,0), props={})  with payload 'msg-exclusive-10'\nReceived again: Message(prod=standalone-0-8, seq=11, publish_time=1597068971578, payload_size=16, msg_id=(52,11,-1,0), props={})  with payload 'msg-exclusive-11'\nReceived again: Message(prod=standalone-0-8, seq=12, publish_time=1597068971581, payload_size=16, msg_id=(52,12,-1,0), props={})  with payload 'msg-exclusive-12'\nReceived again: Message(prod=standalone-0-8, seq=13, publish_time=1597068971584, payload_size=16, msg_id=(52,13,-1,0), props={})  with payload 'msg-exclusive-13'\nReceived again: Message(prod=standalone-0-8, seq=14, publish_time=1597068971588, payload_size=16, msg_id=(52,14,-1,0), props={})  with payload 'msg-exclusive-14'\nReceived again: Message(prod=standalone-0-8, seq=15, publish_time=1597068971591, payload_size=16, msg_id=(52,15,-1,0), props={})  with payload 'msg-exclusive-15'\nReceived again: Message(prod=standalone-0-8, seq=16, publish_time=1597068971596, payload_size=16, msg_id=(52,16,-1,0), props={})  with payload 'msg-exclusive-16'\nReceived again: Message(prod=standalone-0-8, seq=17, publish_time=1597068971599, payload_size=16, msg_id=(52,17,-1,0), props={})  with payload 'msg-exclusive-17'\nReceived again: Message(prod=standalone-0-8, seq=18, publish_time=1597068971602, payload_size=16, msg_id=(52,18,-1,0), props={})  with payload 'msg-exclusive-18'\n2020-08-10 22:16:13.647 INFO  [0x116a555c0] ConsumerImpl:866 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 1] Closing consumer for topic persistent://public/default/test-exclusive-topic-4\n2020-08-10 22:16:13.649 INFO  [0x70000c1b9000] ConsumerImpl:920 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 1] Closed consumer 1\nMessage sent: Ok and payload is: msg-exclusive-20\nMessage sent: Ok and payload is: msg-exclusive-21\nMessage sent: Ok and payload is: msg-exclusive-22\nMessage sent: Ok and payload is: msg-exclusive-23\nMessage sent: Ok and payload is: msg-exclusive-24\nMessage sent: Ok and payload is: msg-exclusive-25\nMessage sent: Ok and payload is: msg-exclusive-26\nMessage sent: Ok and payload is: msg-exclusive-27\nMessage sent: Ok and payload is: msg-exclusive-28\nMessage sent: Ok and payload is: msg-exclusive-29\n2020-08-10 22:16:13.773 INFO  [0x116a555c0] Client:88 | Subscribing on Topic :test-exclusive-topic-4\n2020-08-10 22:16:13.774 INFO  [0x70000c1b9000] HandlerBase:53 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 2] Getting connection from pool\n2020-08-10 22:16:13.789 INFO  [0x70000c1b9000] ConsumerImpl:199 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 2] Created consumer on broker [127.0.0.1:50580 -\u003e 127.0.0.1:6650] \n2020-08-10 22:16:13.790 INFO  [0x70000c1b9000] ConsumerImpl:845 | Broker notification of Closed consumer: 2\n2020-08-10 22:16:13.790 INFO  [0x70000c1b9000] HandlerBase:130 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 2] Schedule reconnection in 0.1 s\n2020-08-10 22:16:13.834 INFO  [0x70000c1b9000] ConsumerImpl:1068 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 2] Seek successfully\n2020-08-10 22:16:13.892 INFO  [0x70000c1b9000] HandlerBase:53 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 2] Getting connection from pool\n2020-08-10 22:16:13.905 INFO  [0x70000c1b9000] ConsumerImpl:199 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 2] Created consumer on broker [127.0.0.1:50580 -\u003e 127.0.0.1:6650] \nSlept 2 seconds and open a new new consumer to seek it to: (52,18,-1,0)\nReceived again: Message(prod=standalone-0-8, seq=18, publish_time=1597068971602, payload_size=16, msg_id=(52,18,-1,0), props={})  with payload 'msg-exclusive-18'\nReceived again: Message(prod=standalone-0-8, seq=19, publish_time=1597068971605, payload_size=16, msg_id=(52,19,-1,0), props={})  with payload 'msg-exclusive-19'\nReceived again: Message(prod=standalone-0-8, seq=20, publish_time=1597068973650, payload_size=16, msg_id=(52,20,-1,0), props={})  with payload 'msg-exclusive-20'\nReceived again: Message(prod=standalone-0-8, seq=21, publish_time=1597068973684, payload_size=16, msg_id=(52,21,-1,0), props={})  with payload 'msg-exclusive-21'\nReceived again: Message(prod=standalone-0-8, seq=22, publish_time=1597068973709, payload_size=16, msg_id=(52,22,-1,0), props={})  with payload 'msg-exclusive-22'\nReceived again: Message(prod=standalone-0-8, seq=23, publish_time=1597068973728, payload_size=16, msg_id=(52,23,-1,0), props={})  with payload 'msg-exclusive-23'\nReceived again: Message(prod=standalone-0-8, seq=24, publish_time=1597068973750, payload_size=16, msg_id=(52,24,-1,0), props={})  with payload 'msg-exclusive-24'\nReceived again: Message(prod=standalone-0-8, seq=25, publish_time=1597068973755, payload_size=16, msg_id=(52,25,-1,0), props={})  with payload 'msg-exclusive-25'\nReceived again: Message(prod=standalone-0-8, seq=26, publish_time=1597068973761, payload_size=16, msg_id=(52,26,-1,0), props={})  with payload 'msg-exclusive-26'\nReceived again: Message(prod=standalone-0-8, seq=27, publish_time=1597068973763, payload_size=16, msg_id=(52,27,-1,0), props={})  with payload 'msg-exclusive-27'\n2020-08-10 22:16:15.839 INFO  [0x116a555c0] ConsumerImpl:866 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 2] Closing consumer for topic persistent://public/default/test-exclusive-topic-4\n2020-08-10 22:16:15.840 INFO  [0x70000c1b9000] ConsumerImpl:920 | [persistent://public/default/test-exclusive-topic-4, test-exclusive-sub-4, 2] Closed consumer 2\n2020-08-10 22:16:15.840 INFO  [0x116a555c0] ProducerImpl:502 | [persistent://public/default/test-exclusive-topic-4, standalone-0-8] Closing producer for topic persistent://public/default/test-exclusive-topic-4\n2020-08-10 22:16:15.841 INFO  [0x70000c1b9000] ProducerImpl:545 | [persistent://public/default/test-exclusive-topic-4, standalone-0-8] Closed producer\n2020-08-10 22:16:15.841 INFO  [0x116a555c0] ClientImpl:479 | Closing Pulsar client\n2020-08-10 22:16:15.841 INFO  [0x116a555c0] ProducerImpl:481 | Producer - [persistent://public/default/test-exclusive-topic-4, standalone-0-8] , [batchMessageContainer = { BatchContainer [size = 0] [batchSizeInBytes_ = 0] [maxAllowedMessageBatchSizeInBytes_ = 131072] [maxAllowedNumMessagesInBatch_ = 1000] [topicName = persistent://public/default/test-exclusive-topic-4] [producerName_ = standalone-0-8] [batchSizeInBytes_ = 0] [numberOfBatchesSent = 30] [averageBatchSize = 1]}]\n2020-08-10 22:16:15.841 INFO  [0x116a555c0] BatchMessageContainer:194 | [numberOfBatchesSent = 30] [averageBatchSize = 1]\n2020-08-10 22:16:15.841 INFO  [0x116a555c0] ClientConnection:1387 | [127.0.0.1:50580 -\u003e 127.0.0.1:6650] Connection closed\n2020-08-10 22:16:15.841 INFO  [0x116a555c0] ClientConnection:238 | [127.0.0.1:50580 -\u003e 127.0.0.1:6650] Destroyed connection\n```\n\n## How to use TestExclusiveConsumer and TestExclusiveProducer\n\n- Broker version: 2.6.1\n- Pulsar cpp client version: 2.6.1\n\n### Build\n\n```bash\n$ g++ --std=c++11 TestExclusiveConsumer.cc -o testExclusiveConsumer -I$HOME/github.com/apache/pulsar/pulsar-client-cpp/include -lpulsar -L$HOME/github.com/apache/pulsar/pulsar-client-cpp/lib\n$ g++ --std=c++11 TestExclusiveProducer.cc -o testExclusiveProducer -I$HOME/github.com/apache/pulsar/pulsar-client-cpp/include -lpulsar -L$HOME/github.com/apache/pulsar/pulsar-client-cpp/lib\n```\n\n### Run\n\n```bash\n$ ./testExclusiveConsumer\n$ ./testExclusiveProducer\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwolfstudy%2Fpulsar-cpp-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwolfstudy%2Fpulsar-cpp-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwolfstudy%2Fpulsar-cpp-examples/lists"}