2017-10-10 78 views
2

我有一个用Python编写的具有服务总线(主题)输出绑定的Azure函数。该函数由另一个队列触发,我们处理blobl存储中的一些文件,然后将另一个消息放入队列中。Azure函数 - Python的 - ServiceBus输出绑定 - 设置自定义属性

我function.json文件看起来像这样:

{ 
"bindings": [ 
    { 
    "type": "serviceBus", 
    "connection": "Omnibus_Input_Send_Servicebus", 
    "name": "outputMessage", 
    "queueName": "validation-output-queue", 
    "accessRights": "send", 
    "direction": "out" 
    } 
], 
"disabled": false 
} 

在我的功能,我可以将消息发送给像另一个队列:

with open(os.environ['outputMessage'], 'w') as output_message: 
    output_message.write('This is my output test message !') 

这是工作的罚款。现在我想发送消息给一个主题。我创建了SQLFilter订阅,我需要将一些自定义属性设置为BrokeredMessage

azure sdk for python,我发现我可以像添加自定义属性(我已经安装使用PIP蔚蓝的模块):

from azure.servicebus import Message 
sent_msg = Message(b'This is the third message', 
    broker_properties={'Label': 'M3'}, 
    custom_properties={'Priority': 'Medium', 
         'Customer': 'ABC'} 
) 

我的新function.json文件看起来像这样:

{ 
"bindings": [ 
    { 
    "type": "serviceBus", 
    "connection": "Omnibus_Input_Send_Servicebus", 
    "name": "outputMessage", 
    "topicName": "validation-output-topic", 
    "accessRights": "send", 
    "direction": "out" 
    } 
], 
"disabled": false 
} 

而且我已经修改我的函数那样:

from azure.servicebus import Message 
sent_msg = Message(b'This is the third message', 
    broker_properties={'Label': 'M3'}, 
    custom_properties={'Priority': 'Medium', 
         'Customer': 'ABC'} 
) 

with open(os.environ['outputMessage'], 'w') as output_message: 
    output_message.write(sent_msg) 

当我运行功能,我得到这个异常:

TypeError: expected a string or other character buffer object

我试图用buffermemoryview功能,但仍然得到另一个异常:

TypeError: cannot make memory view because object does not have the buffer interface

我想知道如果实际结合支持BrokeredMessage以及如何应对用它 ?

+0

你试过[broker_properties = '{ “ForcePersistence”:假的, “标签”: “我的标签”}' sent_msg =消息(b'receive消息”, broker_properties = broker_properties ) –

+0

对不起不工作 – Thomas

回答

1

Python(和其他脚本语言)的ServiceBus输出绑定仅支持简单的字符串映射,其中您指定的字符串将成为在幕后创建的BrokeredMessage的内容。要设置任何扩展属性或做更复杂的任何事情,您必须下载到自己的函数中使用Azure Python SDK。

+0

这是将来会实施的吗?我应该在git repo中打开一个问题吗? – Thomas

+0

输入绑定是否一样?我可以使用python访问中介消息吗? – Thomas

相关问题