Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support service bus 'cardinality' setting for batches #129

Closed
smolattack opened this issue Sep 7, 2023 · 1 comment
Closed

Support service bus 'cardinality' setting for batches #129

smolattack opened this issue Sep 7, 2023 · 1 comment

Comments

@smolattack
Copy link

Repro steps

Provide the steps required to reproduce the problem:

  1. add batchOptions host.json
{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  },
  "extensions": {
    "serviceBus": {
      "batchOptions": { "maxMessageCount": 50 },
      "messageHandlerOptions": {
        "maxConcurrentCalls": 4
      }
    }
  },
  "concurrency": {
    "dynamicConcurrencyEnabled": true,
    "snapshotPersistenceEnabled": true
  }
}

My expectation is that my function will now be passed an array of messages but that's not the case. The following code errors as ServiceBusQueueHandler only allows for a single message.

app.serviceBusQueue("sbq", {
  connection: "SERVICEBUS",
  queueName: "msgq",
  handler(
    messages: unknown[],
    context: InvocationContext
  ) {},
  isSessionsEnabled: true,
});
});

Also, at runtime, I see only a single message rather than an array

Expected behavior

When the maxMessageCount maxMessageCount is set, I would expect the function to try to batch messages if there are more than one in the queue.

  • Programming language used typscript
  • Links to source
  • Bindings used serviceBusQueue
@ejizba
Copy link
Contributor

ejizba commented Sep 7, 2023

I just tried it myself and apparently there's a "cardinality" setting which isn't documented that needs to be set to many.

As a temporary workaround, I think this would work:

app.generic('serviceBusQueueTrigger2', {
    trigger: trigger.serviceBusQueue({
        connection: 'SERVICEBUS',
        queueName: 'msgq',
        // @ts-ignore
        cardinality: 'many',
    }),
    handler: serviceBusQueueTrigger2,
});

@ejizba ejizba added the feature label Sep 7, 2023
@ejizba ejizba added this to the September 2023 milestone Sep 7, 2023
@ejizba ejizba changed the title How to batch process messages from a Service Bus Queue? Support service bus 'cardinality' setting for batches Sep 7, 2023
@ejizba ejizba closed this as completed Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants