diff options
Diffstat (limited to 'qpid/cpp/examples')
| -rw-r--r-- | qpid/cpp/examples/messaging/client.cpp | 11 | ||||
| -rw-r--r-- | qpid/cpp/examples/messaging/server.cpp | 30 |
2 files changed, 29 insertions, 12 deletions
diff --git a/qpid/cpp/examples/messaging/client.cpp b/qpid/cpp/examples/messaging/client.cpp index 983f0a8878..44720ef3ce 100644 --- a/qpid/cpp/examples/messaging/client.cpp +++ b/qpid/cpp/examples/messaging/client.cpp @@ -7,9 +7,9 @@ * 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 @@ -39,7 +39,7 @@ using std::string; int main(int argc, char** argv) { const char* url = argc>1 ? argv[1] : "amqp:tcp:127.0.0.1:5672"; std::string connectionOptions = argc > 2 ? argv[2] : ""; - + Connection connection(url, connectionOptions); try { connection.open(); @@ -62,10 +62,11 @@ int main(int argc, char** argv) { Message request; request.setReplyTo(responseQueue); for (int i=0; i<4; i++) { - request.setContent(s[i]); + request.setContentObject(s[i]); sender.send(request); Message response = receiver.fetch(); - std::cout << request.getContent() << " -> " << response.getContent() << std::endl; + std::cout << request.getContentObject() << " -> " << response.getContentObject() << std::endl; + session.acknowledge(response); } connection.close(); return 0; diff --git a/qpid/cpp/examples/messaging/server.cpp b/qpid/cpp/examples/messaging/server.cpp index aa271d91f9..ba9fa9e063 100644 --- a/qpid/cpp/examples/messaging/server.cpp +++ b/qpid/cpp/examples/messaging/server.cpp @@ -52,15 +52,31 @@ int main(int argc, char** argv) { const Address& address = request.getReplyTo(); if (address) { Sender sender = session.createSender(address); - std::string s = request.getContent(); - std::transform(s.begin(), s.end(), s.begin(), toupper); - Message response(s); + Message response; + + qpid::types::Variant requestObj = request.getContentObject(); + if (requestObj.getType() == qpid::types::VAR_STRING) { + // Received a string. + // Server returns request string in upper case with same encoding. + std::string s = requestObj; + std::transform(s.begin(), s.end(), s.begin(), toupper); + qpid::types::Variant responseObj(s); + responseObj.setEncoding( requestObj.getEncoding() ); + response.setContentObject( responseObj ); + } else { + // Received something other than a string. + // Server echos received object as a utf8 string. + qpid::types::Variant responseObj( requestObj.asString() ); + responseObj.setEncoding( "utf8" ); + response.setContentObject( requestObj ); + } sender.send(response); - std::cout << "Processed request: " - << request.getContent() - << " -> " - << response.getContent() << std::endl; + std::cout << "Processed request: " + << request.getContentObject() + << " -> " + << response.getContentObject() << std::endl; session.acknowledge(); + sender.close(); } else { std::cerr << "Error: no reply address specified for request: " << request.getContent() << std::endl; session.reject(request); |
