Azure函数 - Python的 - ServiceBus输出绑定 - 设置自定义属性
问题描述:
我有一个用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
我试图用buffer
和memoryview
功能,但仍然得到另一个异常:
TypeError: cannot make memory view because object does not have the buffer interface
我想知道如果实际结合支持BrokeredMessage以及如何应对用它 ?
你试过[broker_properties = '{ “ForcePersistence”:假的, “标签”: “我的标签”}' sent_msg =消息(b'receive消息”, broker_properties = broker_properties ) –
对不起不工作 – Thomas