zhcn commented on issue #17279:
URL: https://github.com/apache/pulsar/issues/17279#issuecomment-1233671760
> Could you give a complete example? Your code cannot be compiled.
>
> I just downloaded the latest code in branch-2.11 and built the Pulsar C++
client from source. The following example works well.
>
> ```c++
> #include <pulsar/Client.h>
> using namespace pulsar;
>
> void func() {
> auto t = std::make_shared<std::string>("");
> std::cout << t << std::endl;
> }
>
> int main() {
> func();
> Client client("pulsar://localhost:6650");
> std::string topic = "my-topic";
> Producer producer;
> auto result = client.createProducer(topic, producer);
> if (result != ResultOk) {
> std::cout << "Error creating producer: " << result << std::endl;
> return 1;
> }
> MessageId messageId;
> producer.send(MessageBuilder().setContent("hello").build(), messageId);
> client.close();
> return 0;
> }
> ```
>
> Outputs:
>
> ```
> 0x12b9c08
> 2022-08-31 13:34:21.891 INFO [140604211804928] ClientConnection:189 |
[<none> -> pulsar://localhost:6650] Create ClientConnection, timeout=10000
> 2022-08-31 13:34:21.891 INFO [140604211804928] ConnectionPool:96 |
Created connection for pulsar://localhost:6650
> 2022-08-31 13:34:21.896 INFO [140604079314688] ClientConnection:375 |
[127.0.0.1:51650 -> 127.0.0.1:6650] Connected to broker
> 2022-08-31 13:34:21.899 INFO [140604079314688] HandlerBase:61 |
[persistent://public/default/my-topic, ] Getting connection from pool
> 2022-08-31 13:34:21.903 INFO [140604079314688] ProducerImpl:186 |
[persistent://public/default/my-topic, ] Created producer on broker
[127.0.0.1:51650 -> 127.0.0.1:6650]
> 2022-08-31 13:34:21.907 INFO [140604211804928] ClientImpl:507 | Closing
Pulsar client with 1 producers and 0 consumers
> 2022-08-31 13:34:21.908 INFO [140604211804928] ProducerImpl:657 |
[persistent://public/default/my-topic, standalone-0-2] Closing producer for
topic persistent://public/default/my-topic
> 2022-08-31 13:34:21.909 INFO [140604079314688] ProducerImpl:697 |
[persistent://public/default/my-topic, standalone-0-2] Closed producer 0
> 2022-08-31 13:34:21.909 INFO [140604060354304] ClientConnection:1560 |
[127.0.0.1:51650 -> 127.0.0.1:6650] Connection closed
> 2022-08-31 13:34:21.909 INFO [140604060354304] ClientConnection:263 |
[127.0.0.1:51650 -> 127.0.0.1:6650] Destroyed connection
> 2022-08-31 13:34:21.910 INFO [140604211804928] ProducerImpl:620 |
Producer - [persistent://public/default/my-topic, standalone-0-2] ,
[batchMessageContainer = { BatchMessageContainer [size = 0] [bytes = 0]
[maxSize = 1000] [maxBytes = 131072] [topicName =
persistent://public/default/my-topic] [numberOfBatchesSent_ = 2]
[averageBatchSize_ = 0.5] }]
> ```
>
> The dependencies are:
>
> ```
> -- Found OpenSSL: /usr/lib64/libcrypto.so (found version "1.0.2k")
> Failed to find Protobuf in config mode, try to find it from system path
> -- Protobuf_LIBRARIES: /usr/local/lib/libprotobuf.so
> -- Protobuf_INCLUDE_DIRS: /usr/local/include
> -- Found CURL: /usr/lib64/libcurl.so (found version "7.29.0")
> -- Found Boost: /usr/include (found version "1.53.0")
> -- Linking with Boost:System
> -- Using Boost::Regex
> -- Found Boost: /usr/include (found version "1.53.0") found components:
system regex
> ```
>
> I installed Protobuf 3.20.0 from source.
>
> The GCC version:
>
> ```shell
> $ g++ --version
> g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
> Copyright (C) 2015 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> ```
```
#include <pulsar/Client.h>
#include <iostream>
#include <memory>
void func() {
std::shared_ptr<std::string> t = std::make_shared<std::string>("");
}
int main(){
pulsar::Client client("pulsar://localhost:6650");
pulsar::Producer producer;
pulsar::Result result = client.createProducer("my-topic", producer);
if (result != pulsar::ResultOk) {
std::cout << "Error creating producer: " << result << std::endl;
return -1;
}
return 0;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]