Exemple #1
0
void Listener::received(Message& request) {
    Message response;

    // Get routing key for response from the request's replyTo property
    string routingKey;

    if (request.getMessageProperties().hasReplyTo()) {
        routingKey = request.getMessageProperties().getReplyTo().getRoutingKey();
    } else {
        std::cout << "Error: " << "No routing key for request (" << request.getData() << ")" << std::endl;
        return;
    } 

    std::cout << "Request: " << request.getData() << "  (" <<routingKey << ")" << std::endl;

    // Transform message content to upper case
    std::string s = request.getData();
    std::transform (s.begin(), s.end(), s.begin(), toupper);
    response.setData(s);

    // Send it back to the user
    response.getDeliveryProperties().setRoutingKey(routingKey);

    // Asynchronous transfer sends messages as quickly as
    // possible without waiting for confirmation.
    asyncSession.messageTransfer(arg::content=response, arg::destination="amq.direct");
}
Exemple #2
0
int main(int argc, char** argv) {
    try {
        qpid::tests::PingOptions opts;
        opts.parse(argc, argv);
        opts.con.heartbeat = (opts.timeout+1)/2;
        Connection connection;
        opts.open(connection);
        if (!opts.quiet) cout << "Opened connection." << endl;
        AsyncSession s = connection.newSession();
        string qname(Uuid(true).str());
        s.queueDeclare(queue=qname, autoDelete=true, exclusive=true);
        s.messageTransfer(content=Message("hello", qname));
        if (!opts.quiet) cout << "Sent message." << endl;
        SubscriptionManager subs(s);
        subs.get(qname);
        if (!opts.quiet) cout << "Received message." << endl;
        s.sync();
        s.close();
        connection.close();
        if (!opts.quiet) cout << "Success." << endl;
        return 0;
    } catch (const exception& e) {
        cerr << "Error: " << e.what() << endl;
        return 1;
    }
}