This page compares C++ and Python code samples from our examples, looking for arbitrary discrepancies in the API. I suggest that we add proposals to fix these discrepancies inline for each example.
Python uses a socket object, not needed in the C++ API. I suggest that Python follow C++ here.
Python requires the user to provide a UUID instead of creating one for him. I suggest that Python provide the UUID automagically, as does C++.
Our Python examples end by closing the session, our C++ examples end by closing the connection. If both APIs allow both approaches, we should fix the examples; if not, we should make the APIs consistent.
C++ local queues are created as standalone objects, then subscribed. Python retrieves a local queue from the server using the session.incoming() method.
Python starts delivery using the local queue's start() method. C++ begins delivery using the SubscriptionManger.run() or Session.run() method.
Naming: Python calls the method "message_subscribe", which corresponds to the AMQP name, but it's odd naming: it does not subscribe to a message, nor does it subscribe a message to anything else.
Python requires the programmer to create the delivery property object for a new message using a session object. That seems strange - it would be better to create it using the message, since it pertains to a message's delivery properties.
This same discrepancy affects message properties
SubscriptionManager
Discrepancies
Python does not have a SubscriptionManager. This would be very useful once Python supports async mode.
Message Listeners
C++
// A message listener:
class Listener : public MessageListener{
private:
SubscriptionManager& subscriptions;
public:
Listener(SubscriptionManager& subscriptions);
virtual void received(Message& message);
};
void Listener::received(Message& message) {
std::cout << "Message: " << message.getData() << std::endl;
if (endCondition(message)) {
subscriptions.cancel(message.getDestination());
}
}
// Using a message listener with a subscription manager:
SubscriptionManager subscriptions(session);
Listener listener(subscriptions);
subscriptions.subscribe(listener, "message_queue");
subscriptions.run();
Python
#----- Message Receive Handler -----------------------------
class Receiver:
def __init__ (self):
self.finalReceived = False
def isFinal (self):
return self.finalReceived
def Handler (self, message):
content = message.body
session.message_accept(RangedSet(message.id))
print content
if content == "That's all, folks!":
self.finalReceived = True
# Call message_subscribe() to tell the broker to deliver messages
# from the AMQP queue to this local client queue. The broker will
# start delivering messages as soon as message_subscribe() is called.
session.message_subscribe(queue="message_queue", destination=local_queue_name)
queue.start()
# Register a message listener with the queue
receiver = Receiver()
queue.listen (receiver.Handler)
while not receiver.isFinal() :
sleep (1)
Discrepancies
In Python, a message handler is registered with a local queue, and the local queue is subscribed to the remote queue. In C+, a message listener is subscribed to using a Session or a Subscription Manager. I prefer the C+ approach here.
Synchronous / Asynchronous Modes
Discrepancies
C++ supports both synchronous and asynchronous modes. Python supports only synchronous mode. Python should support both.
Getting and Setting Message Contents
C++
// getData()
std::cout << "Response: " << message.getData() << std::endl;
// setData()
message.setData("That's all, folks!");
// appendData()
message.appendData(" ... let's add a bit more ...");
Different data model. C++ has a message, which has headers. Python has a message, which has message properties, including application headers.
Python supports via a dictionary, which is very nice. Can I do this in C++?
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org