A minimal, self‑contained example demonstrating how to build a C++ publisher and subscriber using the Solace C API (solclient). The subscriber listens on the topic fx/rates/normalized, and the publisher sends a sample FX payload (EURUSD=1.1034) to the same topic.
This project contains two standalone executables:
subscriber — connects to Solace, subscribes to a topic, and prints received messages
publisher — connects to Solace and publishes a binary‑attachment message to a topic
solClient_initialize for API setup
context with internal I/O thread
callbacks for events and messages
binary attachment payloads
topic-based publish/subscribe
Solace PubSub+ Broker (local or remote) , I have setup on Docker on Mac
Solace C API (solclient) installed (Be sure about the api version and compatibility, this is tested with solclient_Darwin-universal2_opt_7.33.1.1 )
C++ compiler (g++/clang++) Linux or WSL recommended . ├── README.md ├── publisher.cpp └── subscriber.cpp
-
Set Solace library paths Example (adjust to your installation): export LD_LIBRARY_PATH=/usr/sw/solclient/lib:$LD_LIBRARY_PATH export CPATH=/usr/sw/solclient/include
-
Compile subscriber bash gclang++ subscriber.cpp -std=c++20 \ -I /Users/$USER/solace-c/include
-L /Users/$USER/solace-c/lib
-lsolclient
-Wl,-rpath,/Users/$USER/solace-c/lib
-o subscriber -
Compile publisher clang++ publisher.cpp -std=c++20 \ -I /Users/$USER/solace-c/include
-L /Users/$USER/solace-c/lib
-lsolclient
-Wl,-rpath,/Users/$USER/solace-c/lib
-o publisher
- Start the subscriber bash ./subscriber You should see:
Output: ./subscriber Initializing Solace API... solClient_initialize rc = 0 context_create rc = 0 session_create rc = 0 session pointer = 0x4000ffe [Event] Session up session_connect rc = 0 topicSubscribe rc = 0 Listening on topic fx/rates/normalized...
- Run the publisher bash ./publisher
Output: ./publisher Connected. Publishing messages... Message sent: EURUSD=1.1034
- Subscriber output
[Callback] messageCallback fired [Message] Received: EURUSD=1.1034
Subscriber Initializes Solace API
Creates a context with an internal thread
Creates a session with message + event callbacks
Subscribes to topic fx/rates/normalized
Prints incoming binary payloads
Publisher Initializes API and creates session
Allocates a message
Sets topic destination
Attaches binary payload
Sends message via session
Queue subscriptions require Solace API 8.x+; this example uses topic subscription for compatibility.
The subscriber uses an internal Solace I/O thread, so no manual event loop is required.
Payloads are handled as binary attachments, which is the recommended pattern for raw text or encoded data.