Skip to content

Instantly share code, notes, and snippets.

@geekyarthurs
Created February 21, 2021 18:29
Show Gist options
  • Save geekyarthurs/e3d927967dd8a0b7c16974c1794c94fd to your computer and use it in GitHub Desktop.
Save geekyarthurs/e3d927967dd8a0b7c16974c1794c94fd to your computer and use it in GitHub Desktop.
import json
import logging
import azure.functions as func
from azure.servicebus import ServiceBusClient, ServiceBusMessage
CONN_STR = "#"
QUEUE_NAME = "messages"
def main(req: func.HttpRequest) -> func.HttpResponse:
req_body = req.get_json()
item = req_body.get('item')
price = req_body.get('price')
contact = "+977" + req_body.get('contact')
with ServiceBusClient.from_connection_string(CONN_STR) as client:
with client.get_queue_sender(QUEUE_NAME) as sender:
message = json.dumps({"item": item, "price": price, "contact" : contact})
logging.log(msg=message,level=50)
sender.send_messages(ServiceBusMessage(message))
return func.HttpResponse(f"Hello, {contact}. This HTTP triggered function executed successfully.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment