python-qpid-proton示例,发送消息给azure不起作用

时间:2015-08-24 18:51:06

标签: python azure amqp qpid

我尝试使用python-qpid-proton版本0.9.1将消息发送到Azure Service Bus队列。

examples/python/messenger/中的示例接受amqps://<user>:<password>@<server>/<queue name>形式的地址,我可以成功地将消息发送到Azure上的队列。这样做的问题是我无法控制很多正在发生的事情,即我无法确定发送是否失败。最终我想要保留邮件,以防互联网连接暂时中断。

示例代码examples/python/db_send.pyexamples/python/simple_send.py似乎对这些方面更有用,因为它们使用MessagingHandler而不是Messenger类。但是当我运行它们时,我收到了这个错误:

./simple_send.py -a amqps://send:mxirestofmypassword@testsoton.servicebus.windows.net/queue2
Traceback (most recent call last):
  File "./simple_send.py", line 62, in <module>
    Container(Send(opts.address, opts.messages)).run()
  File "/usr/local/lib/python2.7/dist-packages/proton/reactor.py", line 120, in run
    while self.process(): pass
  File "/usr/local/lib/python2.7/dist-packages/proton/reactor.py", line 143, in proce
    self._check_errors()
  File "/usr/local/lib/python2.7/dist-packages/proton/__init__.py", line 3737, in dis
    ev.dispatch(self.handler)
  File "/usr/local/lib/python2.7/dist-packages/proton/__init__.py", line 3662, in dis
    result = dispatch(handler, type.method, self)
  File "/usr/local/lib/python2.7/dist-packages/proton/__init__.py", line 3551, in dis
    return m(*args)
  File "/usr/local/lib/python2.7/dist-packages/proton/handlers.py", line 416, in on_r
    self.on_start(event)
  File "./simple_send.py", line 36, in on_start
    event.container.create_sender(self.url)
  File "/usr/local/lib/python2.7/dist-packages/proton/reactor.py", line 671, in creat
    session = self._get_session(context)
  File "/usr/local/lib/python2.7/dist-packages/proton/reactor.py", line 634, in _get_
    return self._get_session(self.connect(url=context))
  File "/usr/local/lib/python2.7/dist-packages/proton/reactor.py", line 611, in conne
    if url: connector.address = Urls([url])
  File "/usr/local/lib/python2.7/dist-packages/proton/reactor.py", line 555, in __ini
    self.values = [Url(v) for v in values]
  File "/usr/local/lib/python2.7/dist-packages/proton/__init__.py", line 3851, in __i
    if defaults: self.defaults()
  File "/usr/local/lib/python2.7/dist-packages/proton/__init__.py", line 3894, in def
    self.port = self.port or self.Port(self.scheme)
  File "/usr/local/lib/python2.7/dist-packages/proton/__init__.py", line 3868, in _ge
    return portstr and Url.Port(portstr)
  File "/usr/local/lib/python2.7/dist-packages/proton/__init__.py", line 3812, in __n
    port = super(Url.Port, cls).__new__(cls, cls._port_int(value))
  File "/usr/local/lib/python2.7/dist-packages/proton/__init__.py", line 3833, in _po
    raise ValueError("Not a valid port number or service name: '%s'" % value)
ValueError: Not a valid port number or service name: 'mxitheresto'

对我来说似乎没有正确解析地址。我粘贴了和以前一样的地址。我还将它粘贴到python解释器中,如下所示:

>>> import proton
>>> u = proton.Url("amqps://send:mxirestofmypassword@testsoton.servicebus.windows.net/queue2")
>>> # no error, and I can access all the parameters:
>>> u.port
5671
>>> u.username
send
>>> # ...

如果我使用没有用户名和密码的本地连接,它可以正常工作。如果我不使用任何用户名和密码,但显然无法正常运行,那么就超过了这一点。

有什么方法可以使用MessagingHandler类并指定用户名和密码来发送消息到远程(如Azure)?

0 个答案:

没有答案