blob: dfe94992352bda950dd48b1de8fdd84b8560a2c3 [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><title>Pulsar C++ client · Apache Pulsar</title><meta name="viewport" content="width=device-width, initial-scale=1.0"/><meta name="generator" content="Docusaurus"/><meta name="description" content="You can use Pulsar C++ client to create Pulsar producers and consumers in C++."/><meta name="docsearch:version" content="2.8.2"/><meta name="docsearch:language" content="en"/><meta property="og:title" content="Pulsar C++ client · Apache Pulsar"/><meta property="og:type" content="website"/><meta property="og:url" content="https://pulsar.apache.org/"/><meta property="og:description" content="You can use Pulsar C++ client to create Pulsar producers and consumers in C++."/><meta name="twitter:card" content="summary"/><meta name="twitter:image" content="https://pulsar.apache.org/img/pulsar.svg"/><link rel="shortcut icon" href="/img/pulsar.ico"/><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/atom-one-dark.min.css"/><link rel="alternate" type="application/atom+xml" href="https://pulsar.apache.org/blog/atom.xml" title="Apache Pulsar Blog ATOM Feed"/><link rel="alternate" type="application/rss+xml" href="https://pulsar.apache.org/blog/feed.xml" title="Apache Pulsar Blog RSS Feed"/><link rel="stylesheet" href="/css/code-blocks-buttons.css"/><script type="text/javascript" src="https://buttons.github.io/buttons.js"></script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script><script type="text/javascript" src="/js/custom.js"></script><script src="/js/scrollSpy.js"></script><link rel="stylesheet" href="/css/main.css"/><script src="/js/codetabs.js"></script></head><body class="sideNavVisible separateOnPageNav"><div class="fixedHeaderContainer"><div class="headerWrapper wrapper"><header><a href="/en"><img class="logo" src="/img/pulsar.svg" alt="Apache Pulsar"/></a><a href="/en/versions"><h3>2.8.2</h3></a><div class="navigationWrapper navigationSlider"><nav class="slidingNav"><ul class="nav-site nav-site-internal"><li class="siteNavGroupActive"><a href="/docs/en/2.8.2/getting-started-standalone" target="_self">Docs</a></li><li class=""><a href="/en/download" target="_self">Download</a></li><li class="siteNavGroupActive"><a href="/docs/en/2.8.2/client-libraries" target="_self">Clients</a></li><li class=""><a href="#restapis" target="_self">REST APIs</a></li><li class=""><a href="#cli" target="_self">Cli</a></li><li class=""><a href="/blog/" target="_self">Blog</a></li><li class=""><a href="#community" target="_self">Community</a></li><li class=""><a href="#apache" target="_self">Apache</a></li><li class=""><a href="https://pulsar-next.staged.apache.org/" target="_self">New Website (Beta)</a></li><span><li><a id="languages-menu" href="#"><img class="languages-icon" src="/img/language.svg" alt="Languages icon"/>English</a><div id="languages-dropdown" class="hide"><ul id="languages-dropdown-items"><li><a href="/docs/ja/2.8.2/client-libraries-cpp">日本語</a></li><li><a href="/docs/fr/2.8.2/client-libraries-cpp">Français</a></li><li><a href="/docs/ko/2.8.2/client-libraries-cpp">한국어</a></li><li><a href="/docs/zh-CN/2.8.2/client-libraries-cpp">中文</a></li><li><a href="/docs/zh-TW/2.8.2/client-libraries-cpp">繁體中文</a></li><li><a href="https://crowdin.com/project/apache-pulsar" target="_blank" rel="noreferrer noopener">Help Translate</a></li></ul></div></li><script>
const languagesMenuItem = document.getElementById("languages-menu");
const languagesDropDown = document.getElementById("languages-dropdown");
languagesMenuItem.addEventListener("click", function(event) {
event.preventDefault();
if (languagesDropDown.className == "hide") {
languagesDropDown.className = "visible";
} else {
languagesDropDown.className = "hide";
}
});
</script></span></ul></nav></div></header></div></div><div class="navPusher"><div class="docMainWrapper wrapper"><div class="docsNavContainer" id="docsNav"><nav class="toc"><div class="toggleNav"><section class="navWrapper wrapper"><div class="navBreadcrumb wrapper"><div class="navToggle" id="navToggler"><div class="hamburger-menu"><div class="line1"></div><div class="line2"></div><div class="line3"></div></div></div><h2><i></i><span>Client Libraries</span></h2><div class="tocToggler" id="tocToggler"><i class="icon-toc"></i></div></div><div class="navGroups"><div class="navGroup"><h3 class="navGroupCategoryTitle">Get Started</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/getting-started-standalone">Run Pulsar locally</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/getting-started-docker">Run Pulsar in Docker</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/getting-started-helm">Run Pulsar in Kubernetes</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Concepts and Architecture</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/concepts-overview">Overview</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/concepts-messaging">Messaging</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/concepts-architecture-overview">Architecture</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/concepts-clients">Clients</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/concepts-replication">Geo Replication</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/concepts-multi-tenancy">Multi Tenancy</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/concepts-authentication">Authentication and Authorization</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/concepts-topic-compaction">Topic Compaction</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/concepts-proxy-sni-routing">Proxy support with SNI routing</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/concepts-multiple-advertised-listeners">Multiple advertised listeners</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Pulsar Schema</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/schema-get-started">Get started</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/schema-understand">Understand schema</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/schema-evolution-compatibility">Schema evolution and compatibility</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/schema-manage">Manage schema</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Pulsar Functions</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/functions-overview">Overview</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/functions-runtime">Setup: Configure Functions runtime</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/functions-worker">Setup: Pulsar Functions Worker</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/functions-develop">How-to: Develop</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/functions-package">How-to: Package</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/functions-debug">How-to: Debug</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/functions-deploy">How-to: Deploy</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/functions-cli">Reference: CLI</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/window-functions-context">Window Functions: Context</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Pulsar IO</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/io-overview">Overview</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/io-quickstart">Get started</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/io-use">Use</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/io-debug">Debug</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/io-connectors">Built-in connector</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/io-cdc">CDC connector</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/io-develop">Develop</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/io-cli">CLI</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Pulsar SQL</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/sql-overview">Overview</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/sql-getting-started">Query data</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/sql-deployment-configurations">Configuration and deployment</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/sql-rest-api">REST APIs</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Tiered Storage</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/tiered-storage-overview">Overview</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/tiered-storage-aws">AWS S3 offloader</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/tiered-storage-gcs">GCS offloader</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/tiered-storage-filesystem">Filesystem offloader</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/tiered-storage-azure">Azure BlobStore offloader</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/tiered-storage-aliyun">Aliyun OSS offloader</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Transactions</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/txn-why">Why transactions?</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/txn-what">What are transactions?</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/txn-how">How transactions work?</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/txn-use">How to use transactions?</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/txn-monitor">How to monitor transactions?</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Kubernetes (Helm)</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/helm-overview">Overview</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/helm-prepare">Prepare</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/helm-install">Install</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/helm-deploy">Deployment</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/helm-upgrade">Upgrade</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/helm-tools">Required Tools</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Deployment</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/deploy-aws">Amazon Web Services</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/deploy-kubernetes">Kubernetes</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/deploy-bare-metal">Bare metal</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/deploy-bare-metal-multi-cluster">Bare metal multi-cluster</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/deploy-docker">Docker</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/deploy-monitoring">Monitor</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Administration</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/administration-zk-bk">ZooKeeper and BookKeeper</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/administration-geo">Geo-replication</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/administration-pulsar-manager">Pulsar Manager</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/administration-stats">Pulsar statistics</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/administration-load-balance">Load balance</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/administration-proxy">Pulsar proxy</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/administration-upgrade">Upgrade</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/administration-isolation">Pulsar isolation</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Security</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-overview">Overview</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-tls-transport">Transport Encryption using TLS</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-tls-authentication">Authentication using TLS</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-tls-keystore">Using TLS with KeyStore configure</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-jwt">Authentication using JWT</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-athenz">Authentication using Athenz</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-kerberos">Authentication using Kerberos</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-oauth2">Authentication using OAuth 2.0 access tokens</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-authorization">Authorization and ACLs</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-encryption">End-to-End Encryption</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-extending">Extending</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/security-bouncy-castle">Bouncy Castle Providers</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Performance</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/performance-pulsar-perf">Pulsar Perf</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Client Libraries</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/client-libraries">Overview</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/client-libraries-java">Java</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/client-libraries-go">Go</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/client-libraries-python">Python</a></li><li class="navListItem navListItemActive"><a class="navItem" href="/docs/en/2.8.2/client-libraries-cpp">C++</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/client-libraries-node">Node.js</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/client-libraries-websocket">WebSocket</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/client-libraries-dotnet">C#</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Admin API</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/admin-api-overview">Overview</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/admin-api-clusters">Clusters</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/admin-api-tenants">Tenants</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/admin-api-brokers">Brokers</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/admin-api-namespaces">Namespaces</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/admin-api-permissions">Permissions</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/admin-api-topics">Topics</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/admin-api-functions">Functions</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/admin-api-packages">Packages</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Adaptors</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/adaptors-kafka">Kafka client wrapper</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/adaptors-spark">Apache Spark</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/adaptors-storm">Apache Storm</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Cookbooks</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/cookbooks-compaction">Topic compaction</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/cookbooks-deduplication">Message deduplication</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/cookbooks-non-persistent">Non-persistent messaging</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/cookbooks-retention-expiry">Message retention and expiry</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/cookbooks-encryption">Encryption</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/cookbooks-message-queue">Message queue</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/cookbooks-bookkeepermetadata">BookKeeper Ledger Metadata</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Development</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/develop-tools">Simulation tools</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/developing-binary-protocol">Binary protocol</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/develop-schema">Custom schema storage</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/develop-load-manager">Modular load manager</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Reference</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/reference-terminology">Terminology</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/reference-cli-tools">Pulsar CLI tools</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/reference-configuration">Pulsar configuration</a></li><li class="navListItem"><a class="navItem" href="/docs/en/2.8.2/reference-metrics">Pulsar Metrics</a></li></ul></div></div></section></div><script>
var coll = document.getElementsByClassName('collapsible');
var checkActiveCategory = true;
for (var i = 0; i < coll.length; i++) {
var links = coll[i].nextElementSibling.getElementsByTagName('*');
if (checkActiveCategory){
for (var j = 0; j < links.length; j++) {
if (links[j].classList.contains('navListItemActive')){
coll[i].nextElementSibling.classList.toggle('hide');
coll[i].childNodes[1].classList.toggle('rotate');
checkActiveCategory = false;
break;
}
}
}
coll[i].addEventListener('click', function() {
var arrow = this.childNodes[1];
arrow.classList.toggle('rotate');
var content = this.nextElementSibling;
content.classList.toggle('hide');
});
}
document.addEventListener('DOMContentLoaded', function() {
createToggler('#navToggler', '#docsNav', 'docsSliderActive');
createToggler('#tocToggler', 'body', 'tocActive');
var headings = document.querySelector('.toc-headings');
headings && headings.addEventListener('click', function(event) {
var el = event.target;
while(el !== headings){
if (el.tagName === 'A') {
document.body.classList.remove('tocActive');
break;
} else{
el = el.parentNode;
}
}
}, false);
function createToggler(togglerSelector, targetSelector, className) {
var toggler = document.querySelector(togglerSelector);
var target = document.querySelector(targetSelector);
if (!toggler) {
return;
}
toggler.onclick = function(event) {
event.preventDefault();
target.classList.toggle(className);
};
}
});
</script></nav></div><div class="container mainContainer docsContainer"><div class="wrapper"><div class="post"><header class="postHeader"><a class="edit-page-link button" href="https://github.com/apache/pulsar/edit/master/site2/docs/client-libraries-cpp.md" target="_blank" rel="noreferrer noopener">Edit</a><h1 id="__docusaurus" class="postHeaderTitle">Pulsar C++ client</h1></header><article><div><span><p>You can use Pulsar C++ client to create Pulsar producers and consumers in C++.</p>
<p>All the methods in producer, consumer, and reader of a C++ client are thread-safe.</p>
<h2><a class="anchor" aria-hidden="true" id="supported-platforms"></a><a href="#supported-platforms" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Supported platforms</h2>
<p>Pulsar C++ client is supported on <strong>Linux</strong> and <strong>MacOS</strong> platforms.</p>
<p><a href="http://www.doxygen.nl/">Doxygen</a>-generated API docs for the C++ client are available <a href="/api/cpp/2.8.0-SNAPSHOT">here</a>.</p>
<h2><a class="anchor" aria-hidden="true" id="system-requirements"></a><a href="#system-requirements" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>System requirements</h2>
<p>You need to install the following components before using the C++ client:</p>
<ul>
<li><a href="https://cmake.org/">CMake</a></li>
<li><a href="http://www.boost.org/">Boost</a></li>
<li><a href="https://developers.google.com/protocol-buffers/">Protocol Buffers</a> 2.6</li>
<li><a href="https://curl.haxx.se/libcurl/">libcurl</a></li>
<li><a href="https://github.com/google/googletest">Google Test</a></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="linux"></a><a href="#linux" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Linux</h2>
<h3><a class="anchor" aria-hidden="true" id="compilation"></a><a href="#compilation" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Compilation</h3>
<ol>
<li>Clone the Pulsar repository.</li>
</ol>
<pre><code class="hljs css language-shell"><span class="hljs-meta">$</span><span class="bash"> git <span class="hljs-built_in">clone</span> https://github.com/apache/pulsar</span>
</code></pre>
<ol start="2">
<li>Install all necessary dependencies.</li>
</ol>
<pre><code class="hljs css language-shell"><span class="hljs-meta">$</span><span class="bash"> apt-get install cmake libssl-dev libcurl4-openssl-dev liblog4cxx-dev \</span>
libprotobuf-dev protobuf-compiler libboost-all-dev google-mock libgtest-dev libjsoncpp-dev
</code></pre>
<ol start="3">
<li>Compile and install <a href="https://github.com/google/googletest">Google Test</a>.</li>
</ol>
<pre><code class="hljs css language-shell"><span class="hljs-meta">#</span><span class="bash"> libgtest-dev version is 1.18.0 or above</span>
<span class="hljs-meta">$</span><span class="bash"> <span class="hljs-built_in">cd</span> /usr/src/googletest</span>
<span class="hljs-meta">$</span><span class="bash"> sudo cmake .</span>
<span class="hljs-meta">$</span><span class="bash"> sudo make</span>
<span class="hljs-meta">$</span><span class="bash"> sudo cp ./googlemock/libgmock.a ./googlemock/gtest/libgtest.a /usr/lib/</span>
<span class="hljs-meta">
#</span><span class="bash"> less than 1.18.0</span>
<span class="hljs-meta">$</span><span class="bash"> <span class="hljs-built_in">cd</span> /usr/src/gtest</span>
<span class="hljs-meta">$</span><span class="bash"> sudo cmake .</span>
<span class="hljs-meta">$</span><span class="bash"> sudo make</span>
<span class="hljs-meta">$</span><span class="bash"> sudo cp libgtest.a /usr/lib</span>
<span class="hljs-meta">
$</span><span class="bash"> <span class="hljs-built_in">cd</span> /usr/src/gmock</span>
<span class="hljs-meta">$</span><span class="bash"> sudo cmake .</span>
<span class="hljs-meta">$</span><span class="bash"> sudo make</span>
<span class="hljs-meta">$</span><span class="bash"> sudo cp libgmock.a /usr/lib</span>
</code></pre>
<ol start="4">
<li>Compile the Pulsar client library for C++ inside the Pulsar repository.</li>
</ol>
<pre><code class="hljs css language-shell"><span class="hljs-meta">$</span><span class="bash"> <span class="hljs-built_in">cd</span> pulsar-client-cpp</span>
<span class="hljs-meta">$</span><span class="bash"> cmake .</span>
<span class="hljs-meta">$</span><span class="bash"> make</span>
</code></pre>
<p>After you install the components successfully, the files <code>libpulsar.so</code> and <code>libpulsar.a</code> are in the <code>lib</code> folder of the repository. The tools <code>perfProducer</code> and <code>perfConsumer</code> are in the <code>perf</code> directory.</p>
<h3><a class="anchor" aria-hidden="true" id="install-dependencies"></a><a href="#install-dependencies" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Install Dependencies</h3>
<blockquote>
<p>Since 2.1.0 release, Pulsar ships pre-built RPM and Debian packages. You can download and install those packages directly.</p>
</blockquote>
<p>After you download and install RPM or DEB, the <code>libpulsar.so</code>, <code>libpulsarnossl.so</code>, <code>libpulsar.a</code>, and <code>libpulsarwithdeps.a</code> libraries are in your <code>/usr/lib</code> directory.</p>
<p>By default, they are built in code path <code>${PULSAR_HOME}/pulsar-client-cpp</code>. You can build with the command below.</p>
<p><code>cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON &amp;&amp; make pulsarShared pulsarSharedNossl pulsarStatic pulsarStaticWithDeps -j 3</code>.</p>
<p>These libraries rely on some other libraries. If you want to get detailed version of dependencies, see <a href="https://github.com/apache/pulsar/blob/master/pulsar-client-cpp/pkg/rpm/Dockerfile">RPM</a> or <a href="https://github.com/apache/pulsar/blob/master/pulsar-client-cpp/pkg/deb/Dockerfile">DEB</a> files.</p>
<ol>
<li><code>libpulsar.so</code> is a shared library, containing statically linked <code>boost</code> and <code>openssl</code>. It also dynamically links all other necessary libraries. You can use this Pulsar library with the command below.</li>
</ol>
<pre><code class="hljs css language-bash"> g++ --std=c++11 PulsarTest.cpp -o <span class="hljs-built_in">test</span> /usr/lib/libpulsar.so -I/usr/<span class="hljs-built_in">local</span>/ssl/include
</code></pre>
<ol start="2">
<li><code>libpulsarnossl.so</code> is a shared library, similar to <code>libpulsar.so</code> except that the libraries <code>openssl</code> and <code>crypto</code> are dynamically linked. You can use this Pulsar library with the command below.</li>
</ol>
<pre><code class="hljs css language-bash"> g++ --std=c++11 PulsarTest.cpp -o <span class="hljs-built_in">test</span> /usr/lib/libpulsarnossl.so -lssl -lcrypto -I/usr/<span class="hljs-built_in">local</span>/ssl/include -L/usr/<span class="hljs-built_in">local</span>/ssl/lib
</code></pre>
<ol start="3">
<li><code>libpulsar.a</code> is a static library. You need to load dependencies before using this library. You can use this Pulsar library with the command below.</li>
</ol>
<pre><code class="hljs css language-bash"> g++ --std=c++11 PulsarTest.cpp -o <span class="hljs-built_in">test</span> /usr/lib/libpulsar.a -lssl -lcrypto -ldl -lpthread -I/usr/<span class="hljs-built_in">local</span>/ssl/include -L/usr/<span class="hljs-built_in">local</span>/ssl/lib -lboost_system -lboost_regex -lcurl -lprotobuf -lzstd -lz
</code></pre>
<ol start="4">
<li><code>libpulsarwithdeps.a</code> is a static library, based on <code>libpulsar.a</code>. It is archived in the dependencies of <code>libboost_regex</code>, <code>libboost_system</code>, <code>libcurl</code>, <code>libprotobuf</code>, <code>libzstd</code> and <code>libz</code>. You can use this Pulsar library with the command below.</li>
</ol>
<pre><code class="hljs css language-bash"> g++ --std=c++11 PulsarTest.cpp -o <span class="hljs-built_in">test</span> /usr/lib/libpulsarwithdeps.a -lssl -lcrypto -ldl -lpthread -I/usr/<span class="hljs-built_in">local</span>/ssl/include -L/usr/<span class="hljs-built_in">local</span>/ssl/lib
</code></pre>
<p>The <code>libpulsarwithdeps.a</code> does not include library openssl related libraries <code>libssl</code> and <code>libcrypto</code>, because these two libraries are related to security. It is more reasonable and easier to use the versions provided by the local system to handle security issues and upgrade libraries.</p>
<h3><a class="anchor" aria-hidden="true" id="install-rpm"></a><a href="#install-rpm" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Install RPM</h3>
<ol>
<li>Download a RPM package from the links in the table.</li>
</ol>
<table>
<thead>
<tr><th>Link</th><th>Crypto files</th></tr>
</thead>
<tbody>
<tr><td><a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/RPMS/apache-pulsar-client-2.8.2-1.x86_64.rpm">client</a></td><td><a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/RPMS/apache-pulsar-client-2.8.2-1.x86_64.rpm.asc">asc</a>, <a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/RPMS/apache-pulsar-client-2.8.2-1.x86_64.rpm.sha512">sha512</a></td></tr>
<tr><td><a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/RPMS/apache-pulsar-client-debuginfo-2.8.2-1.x86_64.rpm">client-debuginfo</a></td><td><a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/RPMS/apache-pulsar-client-debuginfo-2.8.2-1.x86_64.rpm.asc">asc</a>, <a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/RPMS/apache-pulsar-client-debuginfo-2.8.2-1.x86_64.rpm.sha512">sha512</a></td></tr>
<tr><td><a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/RPMS/apache-pulsar-client-devel-2.8.2-1.x86_64.rpm">client-devel</a></td><td><a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/RPMS/apache-pulsar-client-devel-2.8.2-1.x86_64.rpm.asc">asc</a>, <a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/RPMS/apache-pulsar-client-devel-2.8.2-1.x86_64.rpm.sha512">sha512</a></td></tr>
</tbody>
</table>
<ol start="2">
<li>Install the package using the following command.</li>
</ol>
<pre><code class="hljs css language-bash">$ rpm -ivh apache-pulsar-client*.rpm
</code></pre>
<p>After you install RPM successfully, Pulsar libraries are in the <code>/usr/lib</code> directory.</p>
<h3><a class="anchor" aria-hidden="true" id="install-debian"></a><a href="#install-debian" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Install Debian</h3>
<ol>
<li>Download a Debian package from the links in the table.</li>
</ol>
<table>
<thead>
<tr><th>Link</th><th>Crypto files</th></tr>
</thead>
<tbody>
<tr><td><a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/DEB/apache-pulsar-client.deb">client</a></td><td><a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/DEB/apache-pulsar-client.deb.asc">asc</a>, <a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/DEB/apache-pulsar-client.deb.sha512">sha512</a></td></tr>
<tr><td><a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/DEB/apache-pulsar-client-dev.deb">client-devel</a></td><td><a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/DEB/apache-pulsar-client-dev.deb.asc">asc</a>, <a href="https://archive.apache.org/dist/pulsar/pulsar-2.8.2/DEB/apache-pulsar-client-dev.deb.sha512">sha512</a></td></tr>
</tbody>
</table>
<ol start="2">
<li>Install the package using the following command.</li>
</ol>
<pre><code class="hljs css language-bash">$ apt install ./apache-pulsar-client*.deb
</code></pre>
<p>After you install DEB successfully, Pulsar libraries are in the <code>/usr/lib</code> directory.</p>
<h3><a class="anchor" aria-hidden="true" id="build"></a><a href="#build" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Build</h3>
<blockquote>
<p>If you want to build RPM and Debian packages from the latest master, follow the instructions below. You should run all the instructions at the root directory of your cloned Pulsar repository.</p>
</blockquote>
<p>There are recipes that build RPM and Debian packages containing a
statically linked <code>libpulsar.so</code> / <code>libpulsarnossl.so</code> / <code>libpulsar.a</code> / <code>libpulsarwithdeps.a</code> with all required dependencies.</p>
<p>To build the C++ library packages, you need to build the Java packages first.</p>
<pre><code class="hljs css language-shell">mvn install -DskipTests
</code></pre>
<h4><a class="anchor" aria-hidden="true" id="rpm"></a><a href="#rpm" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>RPM</h4>
<p>To build the RPM inside a Docker container, use the command below. The RPMs are in the <code>pulsar-client-cpp/pkg/rpm/RPMS/x86_64/</code> path.</p>
<pre><code class="hljs css language-shell">pulsar-client-cpp/pkg/rpm/docker-build-rpm.sh
</code></pre>
<table>
<thead>
<tr><th>Package name</th><th>Content</th></tr>
</thead>
<tbody>
<tr><td>pulsar-client</td><td>Shared library <code>libpulsar.so</code> and <code>libpulsarnossl.so</code></td></tr>
<tr><td>pulsar-client-devel</td><td>Static library <code>libpulsar.a</code>, <code>libpulsarwithdeps.a</code>and C++ and C headers</td></tr>
<tr><td>pulsar-client-debuginfo</td><td>Debug symbols for <code>libpulsar.so</code></td></tr>
</tbody>
</table>
<h4><a class="anchor" aria-hidden="true" id="debian"></a><a href="#debian" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Debian</h4>
<p>To build Debian packages, enter the following command.</p>
<pre><code class="hljs css language-shell">pulsar-client-cpp/pkg/deb/docker-build-deb.sh
</code></pre>
<p>Debian packages are created in the <code>pulsar-client-cpp/pkg/deb/BUILD/DEB/</code> path.</p>
<table>
<thead>
<tr><th>Package name</th><th>Content</th></tr>
</thead>
<tbody>
<tr><td>pulsar-client</td><td>Shared library <code>libpulsar.so</code> and <code>libpulsarnossl.so</code></td></tr>
<tr><td>pulsar-client-dev</td><td>Static library <code>libpulsar.a</code>, <code>libpulsarwithdeps.a</code> and C++ and C headers</td></tr>
</tbody>
</table>
<h2><a class="anchor" aria-hidden="true" id="macos"></a><a href="#macos" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>MacOS</h2>
<h3><a class="anchor" aria-hidden="true" id="compilation-1"></a><a href="#compilation-1" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Compilation</h3>
<ol>
<li>Clone the Pulsar repository.</li>
</ol>
<pre><code class="hljs css language-shell"><span class="hljs-meta">$</span><span class="bash"> git <span class="hljs-built_in">clone</span> https://github.com/apache/pulsar</span>
</code></pre>
<ol start="2">
<li>Install all necessary dependencies.</li>
</ol>
<pre><code class="hljs css language-shell"><span class="hljs-meta">#</span><span class="bash"> OpenSSL installation</span>
<span class="hljs-meta">$</span><span class="bash"> brew install openssl</span>
<span class="hljs-meta">$</span><span class="bash"> <span class="hljs-built_in">export</span> OPENSSL_INCLUDE_DIR=/usr/<span class="hljs-built_in">local</span>/opt/openssl/include/</span>
<span class="hljs-meta">$</span><span class="bash"> <span class="hljs-built_in">export</span> OPENSSL_ROOT_DIR=/usr/<span class="hljs-built_in">local</span>/opt/openssl/</span>
<span class="hljs-meta">
#</span><span class="bash"> Protocol Buffers installation</span>
<span class="hljs-meta">$</span><span class="bash"> brew tap homebrew/versions</span>
<span class="hljs-meta">$</span><span class="bash"> brew install protobuf260</span>
<span class="hljs-meta">$</span><span class="bash"> brew install boost</span>
<span class="hljs-meta">$</span><span class="bash"> brew install log4cxx</span>
<span class="hljs-meta">
#</span><span class="bash"> Google Test installation</span>
<span class="hljs-meta">$</span><span class="bash"> git <span class="hljs-built_in">clone</span> https://github.com/google/googletest.git</span>
<span class="hljs-meta">$</span><span class="bash"> <span class="hljs-built_in">cd</span> googletest</span>
<span class="hljs-meta">$</span><span class="bash"> cmake .</span>
<span class="hljs-meta">$</span><span class="bash"> make install</span>
</code></pre>
<ol start="3">
<li>Compile the Pulsar client library in the repository that you cloned.</li>
</ol>
<pre><code class="hljs css language-shell"><span class="hljs-meta">$</span><span class="bash"> <span class="hljs-built_in">cd</span> pulsar-client-cpp</span>
<span class="hljs-meta">$</span><span class="bash"> cmake .</span>
<span class="hljs-meta">$</span><span class="bash"> make</span>
</code></pre>
<h3><a class="anchor" aria-hidden="true" id="install-libpulsar"></a><a href="#install-libpulsar" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Install <code>libpulsar</code></h3>
<p>Pulsar releases are available in the <a href="https://brew.sh/">Homebrew</a> core repository. You can install the C++ client library with the following command. The package is installed with the library and headers.</p>
<pre><code class="hljs css language-shell">brew install libpulsar
</code></pre>
<h2><a class="anchor" aria-hidden="true" id="connection-urls"></a><a href="#connection-urls" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Connection URLs</h2>
<p>To connect Pulsar using client libraries, you need to specify a Pulsar protocol URL.</p>
<p>Pulsar protocol URLs are assigned to specific clusters, you can use the Pulsar URI scheme. The default port is <code>6650</code>. The following is an example for localhost.</p>
<pre><code class="hljs css language-http">pulsar://localhost:6650
</code></pre>
<p>In a Pulsar cluster in production, the URL looks as follows.</p>
<pre><code class="hljs css language-http">pulsar://pulsar.us-west.example.com:6650
</code></pre>
<p>If you use TLS authentication, you need to add <code>ssl</code>, and the default port is <code>6651</code>. The following is an example.</p>
<pre><code class="hljs css language-http">pulsar+ssl://pulsar.us-west.example.com:6651
</code></pre>
<h2><a class="anchor" aria-hidden="true" id="create-a-consumer"></a><a href="#create-a-consumer" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Create a consumer</h2>
<p>To use Pulsar as a consumer, you need to create a consumer on the C++ client. The following is an example.</p>
<pre><code class="hljs css language-c++"><span class="hljs-function"><span class="hljs-built_in">Client</span> <span class="hljs-title">client</span><span class="hljs-params">(<span class="hljs-string">"pulsar://localhost:6650"</span>)</span></span>;
Consumer consumer;
Result result = client.subscribe(<span class="hljs-string">"my-topic"</span>, <span class="hljs-string">"my-subscription-name"</span>, consumer);
<span class="hljs-keyword">if</span> (result != ResultOk) {
LOG_ERROR(<span class="hljs-string">"Failed to subscribe: "</span> &lt;&lt; result);
<span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;
}
Message msg;
<span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>) {
consumer.receive(msg);
LOG_INFO(<span class="hljs-string">"Received: "</span> &lt;&lt; msg
&lt;&lt; <span class="hljs-string">" with payload '"</span> &lt;&lt; msg.getDataAsString() &lt;&lt; <span class="hljs-string">"'"</span>);
consumer.acknowledge(msg);
}
client.<span class="hljs-built_in">close</span>();
</code></pre>
<h2><a class="anchor" aria-hidden="true" id="create-a-producer"></a><a href="#create-a-producer" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Create a producer</h2>
<p>To use Pulsar as a producer, you need to create a producer on the C++ client. The following is an example.</p>
<pre><code class="hljs css language-c++"><span class="hljs-function"><span class="hljs-built_in">Client</span> <span class="hljs-title">client</span><span class="hljs-params">(<span class="hljs-string">"pulsar://localhost:6650"</span>)</span></span>;
Producer producer;
Result result = client.createProducer(<span class="hljs-string">"my-topic"</span>, producer);
<span class="hljs-keyword">if</span> (result != ResultOk) {
LOG_ERROR(<span class="hljs-string">"Error creating producer: "</span> &lt;&lt; result);
<span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;
}
<span class="hljs-comment">// Publish 10 messages to the topic</span>
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">10</span>; i++){
Message msg = MessageBuilder().setContent(<span class="hljs-string">"my-message"</span>).build();
Result res = producer.send(msg);
LOG_INFO(<span class="hljs-string">"Message sent: "</span> &lt;&lt; res);
}
client.<span class="hljs-built_in">close</span>();
</code></pre>
<h2><a class="anchor" aria-hidden="true" id="enable-authentication-in-connection-urls"></a><a href="#enable-authentication-in-connection-urls" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Enable authentication in connection URLs</h2>
<p>If you use TLS authentication when connecting to Pulsar, you need to add <code>ssl</code> in the connection URLs, and the default port is <code>6651</code>. The following is an example.</p>
<pre><code class="hljs css language-cpp">ClientConfiguration config = ClientConfiguration();
config.setUseTls(<span class="hljs-literal">true</span>);
config.setTlsTrustCertsFilePath(<span class="hljs-string">"/path/to/cacert.pem"</span>);
config.setTlsAllowInsecureConnection(<span class="hljs-literal">false</span>);
config.setAuth(pulsar::AuthTls::create(
<span class="hljs-string">"/path/to/client-cert.pem"</span>, <span class="hljs-string">"/path/to/client-key.pem"</span>););
<span class="hljs-function">Client <span class="hljs-title">client</span><span class="hljs-params">(<span class="hljs-string">"pulsar+ssl://my-broker.com:6651"</span>, config)</span></span>;
</code></pre>
<p>For complete examples, refer to <a href="https://github.com/apache/pulsar/tree/master/pulsar-client-cpp/examples">C++ client examples</a>.</p>
<h2><a class="anchor" aria-hidden="true" id="schema"></a><a href="#schema" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Schema</h2>
<p>This section describes some examples about schema. For more information about schema, see <a href="/docs/en/2.8.2/schema-get-started">Pulsar schema</a>.</p>
<h3><a class="anchor" aria-hidden="true" id="create-producer-with-avro-schema"></a><a href="#create-producer-with-avro-schema" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Create producer with Avro schema</h3>
<p>The following example shows how to create a producer with an Avro schema.</p>
<pre><code class="hljs css language-cpp"><span class="hljs-keyword">static</span> <span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> exampleSchema =
<span class="hljs-string">"{\"type\":\"record\",\"name\":\"Example\",\"namespace\":\"test\","</span>
<span class="hljs-string">"\"fields\":[{\"name\":\"a\",\"type\":\"int\"},{\"name\":\"b\",\"type\":\"int\"}]}"</span>;
Producer producer;
ProducerConfiguration producerConf;
producerConf.setSchema(SchemaInfo(AVRO, <span class="hljs-string">"Avro"</span>, exampleSchema));
client.createProducer(<span class="hljs-string">"topic-avro"</span>, producerConf, producer);
</code></pre>
<h3><a class="anchor" aria-hidden="true" id="create-consumer-with-avro-schema"></a><a href="#create-consumer-with-avro-schema" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Create consumer with Avro schema</h3>
<p>The following example shows how to create a consumer with an Avro schema.</p>
<pre><code class="hljs css language-cpp"><span class="hljs-keyword">static</span> <span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> exampleSchema =
<span class="hljs-string">"{\"type\":\"record\",\"name\":\"Example\",\"namespace\":\"test\","</span>
<span class="hljs-string">"\"fields\":[{\"name\":\"a\",\"type\":\"int\"},{\"name\":\"b\",\"type\":\"int\"}]}"</span>;
ConsumerConfiguration consumerConf;
Consumer consumer;
consumerConf.setSchema(SchemaInfo(AVRO, <span class="hljs-string">"Avro"</span>, exampleSchema));
client.subscribe(<span class="hljs-string">"topic-avro"</span>, <span class="hljs-string">"sub-2"</span>, consumerConf, consumer)
</code></pre>
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/en/2.8.2/client-libraries-python"><span class="arrow-prev"></span><span>Python</span></a><a class="docs-next button" href="/docs/en/2.8.2/client-libraries-node"><span>Node.js</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#supported-platforms">Supported platforms</a></li><li><a href="#system-requirements">System requirements</a></li><li><a href="#linux">Linux</a><ul class="toc-headings"><li><a href="#compilation">Compilation</a></li><li><a href="#install-dependencies">Install Dependencies</a></li><li><a href="#install-rpm">Install RPM</a></li><li><a href="#install-debian">Install Debian</a></li><li><a href="#build">Build</a></li></ul></li><li><a href="#macos">MacOS</a><ul class="toc-headings"><li><a href="#compilation-1">Compilation</a></li><li><a href="#install-libpulsar">Install <code>libpulsar</code></a></li></ul></li><li><a href="#connection-urls">Connection URLs</a></li><li><a href="#create-a-consumer">Create a consumer</a></li><li><a href="#create-a-producer">Create a producer</a></li><li><a href="#enable-authentication-in-connection-urls">Enable authentication in connection URLs</a></li><li><a href="#schema">Schema</a><ul class="toc-headings"><li><a href="#create-producer-with-avro-schema">Create producer with Avro schema</a></li><li><a href="#create-consumer-with-avro-schema">Create consumer with Avro schema</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="copyright">Copyright © 2022 The Apache Software Foundation. All Rights Reserved. Apache, Apache Pulsar and the Apache feather logo are trademarks of The Apache Software Foundation.</section><span><script>
const community = document.querySelector("a[href='#community']").parentNode;
const communityMenu =
'<li>' +
'<a id="community-menu" href="#">Community <span style="font-size: 0.75em">&nbsp;▼</span></a>' +
'<div id="community-dropdown" class="hide">' +
'<ul id="community-dropdown-items">' +
'<li><a href="/en/contact">Contact</a></li>' +
'<li><a href="/en/contributing">Contributing</a></li>' +
'<li><a href="/en/coding-guide">Coding guide</a></li>' +
'<li><a href="/en/events">Events</a></li>' +
'<li><a href="https://twitter.com/Apache_Pulsar" target="_blank">Twitter &#x2750</a></li>' +
'<li><a href="https://github.com/apache/pulsar/wiki" target="_blank">Wiki &#x2750</a></li>' +
'<li><a href="https://github.com/apache/pulsar/issues" target="_blank">Issue tracking &#x2750</a></li>' +
'<li><a href="https://pulsar-summit.org/" target="_blank">Pulsar Summit &#x2750</a></li>' +
'<li>&nbsp;</li>' +
'<li><a href="/en/resources">Resources</a></li>' +
'<li><a href="/en/team">Team</a></li>' +
'<li><a href="/en/powered-by">Powered By</a></li>' +
'</ul>' +
'</div>' +
'</li>';
community.innerHTML = communityMenu;
const communityMenuItem = document.getElementById("community-menu");
const communityDropDown = document.getElementById("community-dropdown");
communityMenuItem.addEventListener("click", function(event) {
event.preventDefault();
if (communityDropDown.className == 'hide') {
communityDropDown.className = 'visible';
} else {
communityDropDown.className = 'hide';
}
});
</script></span></footer></div><script>window.twttr=(function(d,s, id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return t;js=d.createElement(s);js.id=id;js.src='https://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js, fjs);t._e = [];t.ready = function(f) {t._e.push(f);};return t;}(document, 'script', 'twitter-wjs'));</script></body></html>