Debian Codegraph @

cpp/examples/queue_browser.cpp

raw
1 /*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21
22 #include <proton/connection.hpp>
23 #include <proton/container.hpp>
24 #include <proton/delivery.hpp>
25 #include <proton/message.hpp>
26 #include <proton/messaging_handler.hpp>
27 #include <proton/receiver_options.hpp>
28 #include <proton/source_options.hpp>
29
30 #include <iostream>
31
32
33 class queue_browser : public proton::messaging_handler {
34 std::string conn_url_;
35 std::string addr_;
36
37 public:
38 queue_browser(const std::string& u, const std::string& a) :
39 conn_url_(u), addr_(a) {}
40
41 void on_container_start(proton::container& c) override {
42 proton::receiver_options ropts;
43 proton::source_options sopts;
44 ropts.source(sopts.distribution_mode(proton::source::COPY));
45
46 proton::connection conn = c.connect(conn_url_);
47 conn.open_receiver(addr_, ropts);
48 }
49
50 void on_message(proton::delivery&, proton::message& m) override {
51 std::cout << m.body() << std::endl;
52 }
53 };
54
55 int main(int argc, char** argv) {
56 try {
57 std::string conn_url = argc > 1 ? argv[1] : "//127.0.0.1:5672";
58 std::string addr = argc > 2 ? argv[2] : "examples";
59
60 queue_browser qb(conn_url, addr);
61 proton::container(qb).run();
62
63 return 0;
64 } catch (const std::exception& e) {
65 std::cerr << e.what() << std::endl;
66 }
67
68 return 1;
69 }