我有一個用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