On 12/01/18 08:48, Daniel Gavrila wrote:
My environment:
Proton v. 0.19
C++ Broker v.1.37 configured with AMQP 1.0
I have problems with setting up correctly the example and to test it.
It appears that it does not work, due to the selector being sent as
binary and not a string (as defined for that filter type). I have
committed a fix.
1. Do you have also a sender example that works with the selected_recv ?
No, at present there is no sender example that sets the application
property 'colour' on which the selected_recv filters. Would be nice to
add one.
Attached is a simple example, based on simple_send, the sets the colour
to green on odd messages and red on even. If you run this, then
selected_recv.py should see only the odd messages.
2. Which configuration do I need to make in the broker ?
None, other than the examples queue existing or being created on demand.
3. The variable “proton::codec::encoder enc” from line 44 looks like a
local variable that is never used
It is used with the << operator, and its purpose is to populate the
filter_value variable it wraps.
4. I cannot figure from documentation which is the purpose of the
selector “apache.org:selector-filter:string” .
Why is necessary such a construct ?
The core spec does not define any specific filter syntax. The
“apache.org:selector-filter:string” identifies an extension that uses a
JMS selector like syntax[1]. I.e. it tells the broker/server how to
interpret the filter value.
[1] http://www.amqp.org/specification/1.0/filters
#!/usr/bin/env python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# 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
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
from __future__ import print_function, unicode_literals
import optparse
from proton import Message
from proton.handlers import MessagingHandler
from proton.reactor import Container
class Send(MessagingHandler):
def __init__(self, url, messages):
super(Send, self).__init__()
self.url = url
self.sent = 0
self.confirmed = 0
self.total = messages
def on_start(self, event):
event.container.create_sender(self.url)
def on_sendable(self, event):
while event.sender.credit and self.sent < self.total:
if self.sent % 2:
colour = 'red'
else:
colour = 'green'
content = '%s %d' % (colour, self.sent+1)
msg = Message(id=(self.sent+1), properties={'colour':colour}, body=content)
event.sender.send(msg)
self.sent += 1
def on_accepted(self, event):
self.confirmed += 1
if self.confirmed == self.total:
print("all messages confirmed")
event.connection.close()
def on_disconnected(self, event):
self.sent = self.confirmed
parser = optparse.OptionParser(usage="usage: %prog [options]",
description="Send messages to the supplied address.")
parser.add_option("-a", "--address", default="localhost:5672/examples",
help="address to which messages are sent (default %default)")
parser.add_option("-m", "--messages", type="int", default=100,
help="number of messages to send (default %default)")
opts, args = parser.parse_args()
try:
Container(Send(opts.address, opts.messages)).run()
except KeyboardInterrupt: pass
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]