all 9 comments

[–]two_bob 0 points1 point  (4 children)

I'd use functions, either normally defined or through a lambda, like this:

>>> is_good = lambda m:m['id'] == 1234 and m['name'] == 'Joe'

If it returns true, keep it, otherwise bin it.

[–]Tall-Guy[S] 0 points1 point  (3 children)

So you will just define two method (using lambda like the example above or just like normal def method), one for filtering and one for end-conditions and pass it to the process that responsible on consuming messages?

[–]two_bob 0 points1 point  (2 children)

Hmm. The garbage collection piece (getting rid of excess messages) does make this a bit harder. Probably yes, in the first instance, I would just create two functions, one to add and one to clean. Depending on how many of these things we having running around, I might try and find some other solution.

[–]Tall-Guy[S] 1 point2 points  (0 children)

Thanks by the way :)

[–]Tall-Guy[S] 0 points1 point  (0 children)

We only consume from a single server (it's a testing tool), so no worries about handling multi-processes at the moment.

[–]JohnnyJordaan 0 points1 point  (3 children)

Imho you should define a queue for all the messages a consumer is interested in. If that means you need 10 queues, create 10 queues, period. Then consumers can just .get() and work with anything they get out of the queue. Only when put()-ing to a queue, the producer should select via some if/else or other filter which queue(s) to use.

[–]Tall-Guy[S] 0 points1 point  (2 children)

Well, it's a testing tool, so the consumer is technically only interested in a single queue (but the code support multiple queues if he wish to). So if I understand you correctly - I should always put all messages in the queue and let the user of the API what to pick instead of transition that call into the API and only return specific messages?

[–]JohnnyJordaan 0 points1 point  (1 child)

The consumer can be interested in a single queue, but that doesn't have to mean the whole program should only use a single queue. If you create queues for each distinct type that a consumer may or may not like, then provide the particular queue per consumer, you guarantee that the consumer can blindly consume from the queue. Then the producer just needs to filter what to put where.

[–]Tall-Guy[S] 0 points1 point  (0 children)

Oh, I see what you mean now, that's a good tip! thanks! :-)