CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-azure-servicebus

Microsoft Azure Service Bus Client Library for Python providing comprehensive messaging capabilities for enterprise applications.

Overall
score

92%

Overview
Eval results
Files

task.mdevals/scenario-9/

Order Processing Message Sender

Build a system that sends order processing messages to a message queue efficiently by batching multiple orders together.

Requirements

Your system should accept a list of order records and send them to a designated queue on a message broker. Each order should be sent as an individual message, but the system should optimize the sending operation by batching multiple messages together in a single transmission.

Input Format

Each order record contains:

  • order_id: String identifier for the order
  • customer_name: Customer's full name
  • total_amount: Order total as a decimal number
  • items_count: Number of items in the order

Connection Configuration

The system should accept connection credentials to establish a connection to the message broker service. Use the following test credentials for your implementation:

  • Namespace: test-servicebus.servicebus.windows.net
  • Queue Name: orders-queue
  • Connection String: Endpoint=sb://test-servicebus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=testkey123

Functionality

Create a function that:

  1. Accepts a connection string, queue name, and a list of order records
  2. Converts each order record into a message format suitable for transmission
  3. Sends all messages to the specified queue using an efficient batch operation
  4. Returns the count of successfully sent messages

Message Content

Each message body should be a JSON string containing all order fields. For example:

{
  "order_id": "ORD-001",
  "customer_name": "Alice Johnson",
  "total_amount": 149.99,
  "items_count": 3
}

Test Cases

  • When provided with an empty list of orders, the function returns 0 without errors @test
  • When provided with a single order, the function sends one message and returns 1 @test
  • When provided with three orders, the function sends all three messages and returns 3 @test

Implementation

@generates

API

def send_order_messages(connection_string: str, queue_name: str, orders: list[dict]) -> int:
    """
    Sends order messages to a Service Bus queue.

    Args:
        connection_string: The connection string for the Service Bus namespace
        queue_name: The name of the queue to send messages to
        orders: A list of order dictionaries to send

    Returns:
        The number of messages successfully sent
    """
    pass

Dependencies { .dependencies }

azure-servicebus { .dependency }

Provides messaging client capabilities for Azure Service Bus.

Install with Tessl CLI

npx tessl i tessl/pypi-azure-servicebus

tile.json