Debian Codegraph @

cpp/examples/connection_options.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/connection_options.hpp>
24 #include <proton/container.hpp>
25 #include <proton/messaging_handler.hpp>
26 #include <proton/transport.hpp>
27
28 #include <iostream>
29
30 using proton::connection_options;
31
32
33 class handler_2 : public proton::messaging_handler {
34 void on_connection_open(proton::connection &c) override {
35 std::cout << "connection events going to handler_2" << std::endl;
36 std::cout << "connection max_frame_size: " << c.max_frame_size() <<
37 ", idle timeout: " << c.idle_timeout() << std::endl;
38 c.close();
39 }
40 };
41
42 class main_handler : public proton::messaging_handler {
43 private:
44 std::string url;
45 handler_2 conn_handler;
46
47 public:
48 main_handler(const std::string& u) : url(u) {}
49
50 void on_container_start(proton::container &c) override {
51 // Connection options for this connection. Merged with and overriding the container's
52 // client_connection_options() settings.
53 c.connect(url, connection_options().handler(conn_handler).max_frame_size(2468));
54 }
55
56 void on_connection_open(proton::connection &c) override {
57 std::cout << "unexpected connection event on main handler" << std::endl;
58 c.close();
59 }
60 };
61
62 int main(int argc, char **argv) {
63 try {
64 std::string url = argc > 1 ? argv[1] : "127.0.0.1:5672/examples";
65 main_handler handler(url);
66 proton::container container(handler);
67 // Global connection options for future connections on container.
68 container.client_connection_options(connection_options().max_frame_size(12345).idle_timeout(proton::duration(15000)));
69 container.run();
70 return 0;
71 } catch (const std::exception& e) {
72 std::cerr << e.what() << std::endl;
73 }
74 return 1;
75 }