ARTEMIS-2249 - update cpp example to use correct client libs
https://issues.apache.org/jira/browse/ARTEMIS-2249
This commit is contained in:
parent
3bfeaa4cd5
commit
f99db14c3a
|
@ -15,4 +15,4 @@
|
||||||
# specific language governing permissions and limitations
|
# specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
# This requires g++ and qpid-cpp-client-devel
|
# This requires g++ and qpid-cpp-client-devel
|
||||||
g++ src/main/cpp/hello.cpp -o hello -l qpidmessaging -l qpidtypes
|
g++ src/main/cpp/hello.cpp -o hello -l qpid-proton-cpp -l qpidtypes
|
||||||
|
|
|
@ -9,7 +9,7 @@ To run this example simply run the command **mvn verify -Pexample**, execute the
|
||||||
# first make sure you have the dependencies you need to compile and run the client
|
# first make sure you have the dependencies you need to compile and run the client
|
||||||
# You will have to adapt this step according to your platform. Consult the [qpid docs](http://qpid.apache.org/releases/qpid-0.30/programming/book/) for more information.
|
# You will have to adapt this step according to your platform. Consult the [qpid docs](http://qpid.apache.org/releases/qpid-0.30/programming/book/) for more information.
|
||||||
# There is a list of [packages](http://qpid.apache.org/packages.html) you can install as well.
|
# There is a list of [packages](http://qpid.apache.org/packages.html) you can install as well.
|
||||||
[proton-cpp]$ sudo yum install qpid-cpp-client-devel
|
[proton-cpp]$ sudo yum install qpid-proton-cpp-devel qpid-proton-cpp-docs
|
||||||
|
|
||||||
# on a first window
|
# on a first window
|
||||||
[proton-cpp]$ mvn verify -Pexample
|
[proton-cpp]$ mvn verify -Pexample
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef FAKE_CPP11_HPP
|
||||||
|
#define FAKE_CPP11_HPP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// These definitions allow us to use some new C++11 features in previous compilers
|
||||||
|
///
|
||||||
|
/// It is strongly recommended not to copy this - just use C++11/C++14 instead!
|
||||||
|
|
||||||
|
#if __cplusplus < 201103L
|
||||||
|
#define OVERRIDE
|
||||||
|
#else
|
||||||
|
#define OVERRIDE override
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FAKE_CPP11_HPP
|
|
@ -18,63 +18,55 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#include <proton/connection.hpp>
|
||||||
|
#include <proton/container.hpp>
|
||||||
// Step 2. Make the proper C++ imports
|
#include <proton/delivery.hpp>
|
||||||
#include <qpid/messaging/Connection.h>
|
#include <proton/message.hpp>
|
||||||
#include <qpid/messaging/Message.h>
|
#include <proton/messaging_handler.hpp>
|
||||||
#include <qpid/messaging/Receiver.h>
|
#include <proton/tracker.hpp>
|
||||||
#include <qpid/messaging/Sender.h>
|
|
||||||
#include <qpid/messaging/Session.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace qpid::messaging;
|
#include "fake_cpp11.hpp"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
class hello_world : public proton::messaging_handler {
|
||||||
std::string broker = argc > 1 ? argv[1] : "localhost:61616";
|
std::string conn_url_;
|
||||||
std::string address = argc > 2 ? argv[2] : "exampleQueue";
|
std::string addr_;
|
||||||
|
|
||||||
// Connection options documented at http://qpid.apache.org/releases/qpid-0.30/programming/book/connections.html#connection-options
|
public:
|
||||||
std::string connectionOptions = argc > 3 ? argv[3] : "{protocol:amqp1.0}";
|
hello_world(const std::string& u, const std::string& a) :
|
||||||
|
conn_url_(u), addr_(a) {}
|
||||||
|
|
||||||
try {
|
void on_container_start(proton::container& c) OVERRIDE {
|
||||||
// Step 3. Create an amqp qpid 1.0 connection
|
c.connect(conn_url_);
|
||||||
Connection connection(broker, connectionOptions);
|
|
||||||
connection.open();
|
|
||||||
|
|
||||||
// Step 4. Create a session
|
|
||||||
Session session = connection.createSession();
|
|
||||||
|
|
||||||
// Step 5. Create a sender
|
|
||||||
Sender sender = session.createSender(address);
|
|
||||||
|
|
||||||
//create a receiver
|
|
||||||
Receiver receiver = session.createReceiver(address);
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
Message message;
|
|
||||||
message.getContentObject() = "Hello world!";
|
|
||||||
|
|
||||||
message.getContentObject().setEncoding("utf8");
|
|
||||||
message.setContentType("text/plain");
|
|
||||||
|
|
||||||
sender.send(message);
|
|
||||||
|
|
||||||
// receive the simple message
|
|
||||||
message = receiver.fetch(Duration::SECOND * 1);
|
|
||||||
std::cout << "Received a message with this following content \"" << message.getContent() << "\"" << std::endl;
|
|
||||||
|
|
||||||
// acknowledge the message
|
|
||||||
session.acknowledge();
|
|
||||||
}
|
|
||||||
|
|
||||||
// close the connection
|
|
||||||
connection.close();
|
|
||||||
return 0;
|
|
||||||
} catch(const std::exception& error) {
|
|
||||||
std::cerr << error.what() << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void on_connection_open(proton::connection& c) OVERRIDE {
|
||||||
|
c.open_receiver(addr_);
|
||||||
|
c.open_sender(addr_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_sendable(proton::sender &s) OVERRIDE {
|
||||||
|
proton::message m("Hello World!");
|
||||||
|
s.send(m);
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_message(proton::delivery &d, proton::message &m) OVERRIDE {
|
||||||
|
std::cout << m.body() << std::endl;
|
||||||
|
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] : "exampleQueue";
|
||||||
|
hello_world hw(conn_url, addr);
|
||||||
|
proton::container(hw).run();
|
||||||
|
return 0;
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
Loading…
Reference in New Issue