-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subscription.pull() should return a list of objects rather than tuples. #913
Comments
|
I'm fine with just
Can we ack multiple messages at a time? that is, could the following be possible in our current implementation? received = subscription.pull()
for ack_id, messages in received:
for message in messages:
print message.data
acknowledge(ack_id) |
Per the spec, each message in a multi-message It is kind of like the difference between the "envelope From" and the "payload |
Sure, so the idea then is... if we had a |
We do have a message class, but putting the |
I get that it is logically a separate thing, however conceptually, the only thing I can acknowledge is a single message, right? I'm OK with the acknowledge method living elsewhere, but wouldn't it make sense to put the |
The bits of the application that deal with the actual message payload are going to be very different from the part that does the I think keeping the |
Can you give any more background on why that's a win? If we put it in the message the list returns a list of Message objects. If we don't it's a list of tuples, that has more specific unpacking requirements. So the code might look like: for message in subscription.pull():
acknowledgement_system.acknowledge_receipt(message.ack_id)
# or even...
acknowledgement_system.acknowledge_receipt(message)
message_processing_system.process_message(message) In other words, I'm saying "I want to acknowledge the receipt of a message", treating the Is this crazy? |
In my mind the "payload" is the I'm sorry that I don't seem to be communicating here my sense of the importance of separation of concerns, in addition to staying as close a reasonably possible to the concepts used by the back-end API:
Except in toy examples, the code dealing with |
OK, and if another attribute comes back with the It seems like if
Since the |
"We" don't unpack them -- the caller does. If it makes sense, we could bundle the two as a for received in subscription.pull():
if 'log_me' in received.message.attrs:
print received.message.data
acknowledge(received.ack_id) |
I'd be fine with the named tuple, but then it leads to the question: why would we use a named tuple here instead of an object for Are we making the decision that "if there's only N properties and 0 methods, we should use a named tuple"? |
Also, using your example code, I'm a tiny bit confused why that's preferable to: for message in subscription.pull():
if 'log_me' in message.attrs:
print message.data
acknowledge(message.ack_id) Is there some example you can share as to why that is a horrible idea ? |
I've tried to share it above: the |
So what about the part asking about the named tuple vs object? |
These discussion seems to have died. Closing out for now (feel free to re-open if feature is necessary) |
…les#913) * Fixes for non-ASCII encodings * Adds test for UTF * Style fix
Copied from comments in #910
Currently, when pulling messages via a subscription, I'd write:
I think it'd be better to have the return value be an iterable of some more complex object (maybe a
pubsub.Message
?):The text was updated successfully, but these errors were encountered: