How to connect to azure service bus and send messages from azure databricks

Mahesh Nerella 0 Reputation points
2023-10-23T15:24:45.5266667+00:00

we wanted to send messages to azure service bus from azure databricks. Are there any ways ?

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
700 questions
Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,514 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2023-10-23T16:39:24.7433333+00:00

    I found this thread already https://learn.microsoft.com/en-us/answers/questions/723406/copy-azure-service-bus-messages-in-queue-to-data-l, so I will help you with some code in Python.

    import azure.servicebus
    from azure.servicebus import ServiceBusClient, ServiceBusMessage
    
    # Replace with your connection string
    connection_str = "YOUR_SERVICE_BUS_CONNECTION_STRING"
    queue_name = "YOUR_QUEUE_NAME"
    
    # Create a Service Bus client
    with ServiceBusClient.from_connection_string(connection_str) as client:
    
        # Send messages to the queue
        with client.get_queue_sender(queue_name) as sender:
            msg = ServiceBusMessage("Hello, Azure Service Bus!")
            sender.send_messages(msg)
            print("Message sent!")
    
    
    3 people found this answer helpful.
    0 comments No comments

  2. Dillon Silzer 57,826 Reputation points Volunteer Moderator
    2023-10-23T16:38:09.93+00:00

    Hi Mahesh,

    You should use import requests and send REST API requests to Azure Service Bus:

    Azure Service Bus REST API

    https://learn.microsoft.com/en-us/rest/api/servicebus/

    Python Requests: How to Send POST Requests

    https://scrapeops.io/python-web-scraping-playbook/python-requests-post-requests/

    Send Message

    https://learn.microsoft.com/en-us/rest/api/servicebus/send-message-to-queue


    If this is helpful please accept answer.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.