PROTON-1733: [cpp] remove helloworld_direct example A program that talks to itself is strange and confusing. Peer-to-peer AMQP is better illustrated by the direct_send/direct_recv examples.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/59cedf3a Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/59cedf3a Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/59cedf3a Branch: refs/heads/master Commit: 59cedf3a5a7aa9478ec30ce6ccf448f04fbbd2e1 Parents: c7fcec1 Author: Alan Conway <[email protected]> Authored: Thu Jan 4 15:51:02 2018 -0500 Committer: Alan Conway <[email protected]> Committed: Thu Jan 4 16:07:22 2018 -0500 ---------------------------------------------------------------------- examples/cpp/CMakeLists.txt | 1 - examples/cpp/README.dox | 9 ---- examples/cpp/example_test.py | 4 -- examples/cpp/helloworld_direct.cpp | 81 --------------------------------- examples/cpp/tutorial.dox | 58 ----------------------- 5 files changed, 153 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/59cedf3a/examples/cpp/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 662bc72..2b0e491 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -61,7 +61,6 @@ endif() foreach(example broker helloworld - helloworld_direct simple_recv simple_send reconnect_client http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/59cedf3a/examples/cpp/README.dox ---------------------------------------------------------------------- diff --git a/examples/cpp/README.dox b/examples/cpp/README.dox index a5228d3..aa2b039 100644 --- a/examples/cpp/README.dox +++ b/examples/cpp/README.dox @@ -18,15 +18,6 @@ node. Sends one message and receives it back. */ -/** @example helloworld_direct.cpp - -Variation of helloworld that does not use a broker, but listens for -incoming connections itself. It establishes a connection to itself -with a link over which a single message is sent. This demonstrates the -ease with which a simple daemon an be built using the API. - -*/ - /** @example simple_send.cpp An example of sending a fixed number of messages and tracking their http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/59cedf3a/examples/cpp/example_test.py ---------------------------------------------------------------------- diff --git a/examples/cpp/example_test.py b/examples/cpp/example_test.py index 8be3352..fa6143f 100644 --- a/examples/cpp/example_test.py +++ b/examples/cpp/example_test.py @@ -104,10 +104,6 @@ class ContainerExampleTest(BrokerTestCase): def test_helloworld(self): self.assertMultiLineEqual('Hello World!\n', self.proc(["helloworld", self.addr]).wait_exit()) - def test_helloworld_direct(self): - with TestPort() as tp: - self.assertMultiLineEqual('Hello World!\n', self.proc(["helloworld_direct", tp.addr]).wait_exit()) - def test_simple_send_recv(self): self.assertMultiLineEqual("all messages confirmed\n", self.proc(["simple_send", "-a", self.addr]).wait_exit()) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/59cedf3a/examples/cpp/helloworld_direct.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/helloworld_direct.cpp b/examples/cpp/helloworld_direct.cpp deleted file mode 100644 index 085db0f..0000000 --- a/examples/cpp/helloworld_direct.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * - * 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/listener.hpp> -#include <proton/message.hpp> -#include <proton/messaging_handler.hpp> -#include <proton/sender.hpp> -#include <proton/tracker.hpp> - -#include <iostream> - -#include "fake_cpp11.hpp" - -class hello_world_direct : public proton::messaging_handler { - private: - std::string url; - proton::listener listener; - - public: - hello_world_direct(const std::string& u) : url(u) {} - - void on_container_start(proton::container &c) OVERRIDE { - listener = c.listen(url); - c.open_sender(url); - } - - // Send one message and close sender - void on_sendable(proton::sender &s) OVERRIDE { - proton::message m("Hello World!"); - s.send(m); - s.close(); - } - - // Receive one message and stop listener - void on_message(proton::delivery &, proton::message &m) OVERRIDE { - std::cout << m.body() << std::endl; - listener.stop(); - } - - // After receiving acknowledgement close connection - void on_tracker_accept(proton::tracker &t) OVERRIDE { - t.connection().close(); - } -}; - -int main(int argc, char **argv) { - try { - // Pick an "unusual" port since we are going to be talking to - // ourselves, not a broker. - std::string url = argc > 1 ? argv[1] : "127.0.0.1:8888/examples"; - - hello_world_direct hwd(url); - proton::container(hwd).run(); - - return 0; - } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; - } - - return 1; -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/59cedf3a/examples/cpp/tutorial.dox ---------------------------------------------------------------------- diff --git a/examples/cpp/tutorial.dox b/examples/cpp/tutorial.dox index 0b72d9d..fdab808 100644 --- a/examples/cpp/tutorial.dox +++ b/examples/cpp/tutorial.dox @@ -109,64 +109,6 @@ subclass of `proton::error`. That in turn is a subclass of \until } \until } -Hello World, direct! --------------------- - -\dontinclude helloworld_direct.cpp - -Though often used in conjunction with a broker, AMQP does not require -this. It also allows senders and receivers to communicate directly if -desired. - -We will modify our example to send a message directly to itself. This -is a bit contrived but illustrates both sides of the direct send and -receive scenario. The full code is at @ref helloworld_direct.cpp. - -The first difference is that, rather than creating a receiver on the -same connection as our sender, we listen for incoming connections by -invoking the `proton::container::listen()` method on the container. - -\skip on_container_start -\until } - -Since we only need to initiate one link, the sender, we can do that by -passing in a URL rather than an existing connection. The connection -will also be automatically established for us. - -We send the message in response to the -`proton::messaging_handler::on_sendable()` callback and print the -message out in response to the -`proton::messaging_handler::on_message()` callback exactly as before. - -\skip on_sendable -\until } -\until } - -However, we also handle two new events. We now close the connection -from the sender's side once the message has been accepted. The -acceptance of the message is an indication of successful transfer to -the peer. We are notified of that event through the -`proton::messaging_handler::on_tracker_accept()` callback. - -\skip on_tracker_accept -\until } - -Then, once the connection has been closed, of which we are notified -through the `proton::messaging_handler::on_connection_close()` -callback, we stop accepting incoming connections. At that point there -is no work to be done, the event loop exits, and the -`proton::container::run()` method returns. - -\skip on_connection_close -\until } - -So now we have our example working without a broker involved! - -Note that for this example we pick an "unusual" port 8888 since we are -talking to ourselves rather than a broker. - -\skipline url = - Asynchronous send and receive ----------------------------- --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
