DreamPearl commented on code in PR #355: URL: https://github.com/apache/qpid-proton/pull/355#discussion_r845962781
########## cpp/examples/tracing_client.cpp: ########## @@ -0,0 +1,108 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include <proton/connection.hpp> +#include <proton/container.hpp> +#include <proton/delivery.hpp> +#include <proton/message.hpp> +#include <proton/message_id.hpp> +#include <proton/messaging_handler.hpp> +#include <proton/receiver.hpp> +#include <proton/receiver_options.hpp> +#include <proton/sender.hpp> +#include <proton/source_options.hpp> +#include <proton/target.hpp> +#include <proton/uuid.hpp> + +// Header file for tracing. +#include <proton/tracing.hpp> + +#include <iostream> +#include <string> + +struct client : public proton::messaging_handler { + std::string conn_url_; + std::string addr_; + std::string msg_; + proton::sender sender_; + + public: + client(const std::string& u, const std::string& r, std::string& m) : conn_url_(u), addr_(r), msg_(m) {} + + void on_container_start(proton::container& cont) override { + proton::connection conn = cont.connect(conn_url_); + + sender_ = conn.open_sender(addr_); + + proton::receiver_options opts{}; + proton::source_options sopts{}; + + sopts.dynamic(true); + opts.source(sopts); + + conn.open_receiver("", opts); + } + + void on_sender_open(proton::sender& snd) override { + std::cout << "Opened sender for target address '" << snd.target().address() << "'\n"; + } + + void on_receiver_open(proton::receiver& rcv) override { + std::cout << "Opened dynamic receiver for responses\n"; + + proton::message request{msg_}; + request.id(proton::message_id{proton::uuid::random()}); + request.reply_to(rcv.source().address()); + + sender_.send(request); + + std::cout << "Sent request '" << request.body() << "'\n"; + } + + void on_message(proton::delivery& d, proton::message& response) override { + std::cout << "Received response '" << response.body() << "'\n"; + + d.receiver().close(); + d.connection().close(); + } +}; + +int main(int argc, char** argv) { + try { + std::string conn_url = argc > 1 ? argv[1] : "//127.0.0.1:5672"; + std::string addr = argc > 2 ? argv[2] : "examples"; + std::string msg = argc > 3 ? argv[3] : "Hello tracing"; + + // The only thing that makes this example a tracing example. + proton::initOpentelemetryTracer(proton::jaeger); + + client c(conn_url, addr, msg); + + proton::container(c).run(); + + return 0; + } catch (const std::exception& e) { + std::cerr << e.what() << "\n"; + return 1; Review Comment: Will remove this in the next PR update. (Removed locally) -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
