Receive messages from Azure Eventhub using AMQP

PURPOSE: Receive messages from EventHub using python.

Setting:

  • Python 3.5
  • AMQP 1.0
  • EventHub is created on the new portal.
  • Ubuntu 16.04 and Mac OS X.
  • proton == 0.8.8 and python-qpid-proton == 0.17.0

I've been trying to get a connection from AMQP to Azure EventHub for a couple of days now. I can do it well with Java Client (as a test to make sure the EventHub is working), but I need to be able to do it with Python.

After reading a couple of examples online, I've tried a lot over the past days. I am using RootManageSharedAccessKey

and the generated key for which I do not have /

. I have tried urllib.quote

as well as normal.

My line currently looks like this:

amqps://RootManageSharedAccessKey:<primary key>@<namespace>.servicebus.windows.net/<internal hub name>

If I copy these same parameters to the Java client, it works fine. If I use the python SDK to send it works fine (it sends it over HTTPS). I have tried using amqps

and amqp

if I enable the debug option for AMQP. I am getting the error:

condition=:"amqp:unauthorized-access",
description="Unauthorized access. 'Send' claim(s) are required to perform this operation.
Resource: 'sb://<namespace>.servicebus.windows.net/<internal event hub>

      

It sounds like a permission issue, but the same keys and everything works fine in Java and Python over HTTPS, so it must be something in my code and keys. Maybe I'm not coding them correctly (I read that you don't need to code them)? Once I get it working, I'll do a GIST and update for everyone else.

My current code looks like this:

from proton import Messenger, Message

messenger = Messenger()
message = Message()
key = "key"
message.address = "amqps://RootManageSharedAccessKey:"+key+"@<namespace>.servicebus.windows.net/<hubname>"

message.body = u"This is a text string"
messenger.put(message)
messenger.send()`

      

What I have tried:

  • Provide policies for both dispatch and dispatch separately in both the event hub and namespace.
  • Recreating a hub
  • Protection against Unsecure
  • Adding ports to the firewall
  • Python 2.7 proton vs 3.5
  • Linux vs Mac
  • Primary key and secondary key
  • New namespaces
  • New keys with and without /

    in the key
  • Encoding urls and whole string
  • UTF-8 encoding
  • JSON messages and text messages.
+3


source to share


1 answer


It might be too late for your project, however there is a new AMQP 1.0 library for Python here:

http://github.com/Azure/azure-uamqp-python

While it is still in its early stages (not production ready), there are a few samples in the repo for use with Azure Event Hubs:



https://github.com/Azure/azure-uamqp-python/tree/master/samples

Regarding the error you see when using Proton, it looks like it might be trying to use the wrong authentication mechanism. Have you tried using the Event Hubs Python SDK ? They use some settings here that might be of interest

0


source







All Articles