Getting error from service bus on sending message of size greater then 1 MB for premium tier.
See original GitHub issue- Package Name: azsdk-js-azureservicebus
- Package Version: 7.7.1
- Operating system: Mac OS BigSur version 11.2.3
- nodejs
- version: 12.16.3
- browser
- name/version:
- typescript
- version: 4.6.3
- Is the bug related to documentation in
- README.md
- source code documentation
- SDK API docs on https://docs.microsoft.com
Describe the bug A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior:
- Deploy a Premium SB namespace and topic (with maxMessageSizeInKB = 102400).
- create a function app and replace code in index file with following code
import { AzureFunction, Context, HttpRequest } from '@azure/functions'; import { ServiceBusMessage, ServiceBusClient } from '@azure/service-bus'; import * as config from './function.json'; const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> { const serviceBusMessage: ServiceBusMessage = { body: req.body } as ServiceBusMessage try { const serviceBusClient = new ServiceBusClient("set this value accordingly"); const sender = serviceBusClient.createSender("set this value accordingly"); await sender.sendMessages(serviceBusMessage); } catch (error) { context.log.error(
error SendMessage${error}); throw error; } }; export default httpTrigger;
Expected behavior sender.sendMessages should not throw error.
Error Body
InvalidOperationError: The link ‘G4S2:3993911:hybris.syndication-product.cds-sbt-2ce21e98-e39b-0b4b-a421-48f12923638f’ is force detached by the broker because publisher(link9441) received a batch message with no data in it. Detach origin: Publisher.
Additional context as per the document large-messages-support Batching is not supported for Large Messages and as per the sendMessage code https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/servicebus/service-bus/src/sender.ts#L193-L223, inside else case we are creating batch from message due to which we are getting this error, on my local machine I replaced it with following code :
async sendMessages( messages: | ServiceBusMessage | ServiceBusMessage[] | ServiceBusMessageBatch | AmqpAnnotatedMessage | AmqpAnnotatedMessage[], options?: OperationOptionsBase ): Promise { this._throwIfSenderOrConnectionClosed() throwTypeErrorIfParameterMissing(this._context.connectionId, “messages”, messages) let batch: ServiceBusMessageBatch; if (isServiceBusMessageBatch(messages)) { batch = messages; const spanLinks: TracingSpanLink[] = batch._messageSpanContexts.map((tracingContext) => { return { tracingContext, }; }) return tracingClient.withSpan( “ServiceBusSender.send”, options ?? {}, (updatedOptions) => this._sender.sendBatch(batch, updatedOptions), { spanLinks, …toSpanOptions( { entityPath: this.entityPath, host: this._context.config.host }, “client” ), } ); } else { if (!Array.isArray(messages)) { messages = [messages]; } const sendMessagesPromise = messages.map((message) => { return tracingClient.withSpan( “ServiceBusSender.send”, options ?? {}, (updatedOptions) => this._sender.send(message, updatedOptions), { …toSpanOptions( { entityPath: this.entityPath, host: this._context.config.host }, “client” ), } ); }); await Promise.all(sendMessagesPromise) } }
it worked, request you to please look into this.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (5 by maintainers)
Hey @sabharwal-garv,
Thanks for the message.
After talking to others in the feature crew for service-bus SDKs, we decided to go with “allow sending a single message without creating a batch for it”, PR created for it https://github.com/Azure/azure-sdk-for-js/pull/23014. Feel free to provide feedback.
While we have this solution, we are also going to ask the service team for new properties on the link to manage batching of messages better in the sendMessages method. I’ll post more on this if there is progress on these discussions.
But, for now, I believe this #23014 should work for you. I’ll provide you with a dev package version for you to test the fix before checking in the PR.
@sabharwal-garv, the fix has been published with the
@azure/service-bus@7.7.1
version, please pull down the latest version and let us know if the fix works for you.