Created
February 21, 2021 18:29
-
-
Save geekyarthurs/e3d927967dd8a0b7c16974c1794c94fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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