pyspark 从synapse notebook向服务总线队列发送消息

fdx2calv  于 12个月前  发布在  Spark
关注(0)|答案(1)|浏览(151)

我们正在从blob文件加载数据,需要将消息发送到服务总线。尝试查找是否可以从Azure synapse notebook将消息发送到服务总线队列。如果可能,请分享有关如何连接到服务总线的详细信息。
我找不到任何具体的

mmvthczy

mmvthczy1#

从synapse notebook向服务总线队列发送消息
你可以使用下面的代码来做同样的事情:

from pyspark.sql import SparkSession
from azure.servicebus import ServiceBusClient, ServiceBusMessage

if __name__ == "__main__":
 
    rith_servicebus_conn_string = "Endpoint=sb://servicebusname.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=umaboZwpRa+sQ="
    rith_service_bus_queue = "rithwik"
    rith_message = "Hello Rithwik Bojja Service Bus!"
    with ServiceBusClient.from_connection_string(rith_servicebus_conn_string) as client:
        with client.get_queue_sender(rith_service_bus_queue) as sender:
            rith_msg = ServiceBusMessage(rith_message)
            sender.send_messages(rith_msg)
    print("Hello Rithwik Bojja!!!, Messages sent to Service Bus.")

字符串
在这里,
rith_service_bus_queue =队列名称
rith_servicebus_conn_string =连接字符串
在使用上面的代码之前,请安装这个包:

!pip install azure-servicebus


的数据

Output:


In Service Bus Queue:


相关问题