azure-sdk-for-js: [Service Bus] If receiveBatch() failed on receiving new message after timeout, next call try to receive more message during other async call stack
- Package Name: @azure/service-bus
- Package Version: 1.0.0-preview.1
- Operating system: macOS 10.14.3
- nodejs
- version: * v10.15.0
- browser
- name/version:
- typescript
- version:
- 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.
After receiveBatch() received 0 messages, next receiveBatch(1) call received first message successfully but, it received second message during async processing first one. So the second message can not be handled and skipped with this error Received transfer when credit was 0
SOURCE
const ns = Namespace.createFromConnectionString(connectionString)
const subscriptionClient = ns.createSubscriptionClient(topicName, subscriptionName)
const receiver = subscriptionClient.getReceiver()
const timeout = ms => {
return new Promise(resolve => setTimeout(resolve, ms))
}
const subscribe = async () => {
const receiveLoop = async () => {
console.log('receiveLoop start...')
const message = await receiver.receiveBatch(1, 5)
if (message.length) {
console.log('Message', message[0].body)
await timeout(5000)
await message.complete()
}
console.log('receiveLoop end...')
return await receiveLoop()
}
return await receiveLoop()
}
subscribe()
OUTPUT
'receiveLoop start...'
// 5 seconds later
'receiveLoop end...'
'receiveLoop start...'
// publish {body: 1}
// publish {body: 2}
// publish {body: 3}
Message 1
Received transfer when credit was 0
'receiveLoop end...'
'receiveLoop start...'
Message 2 (or 3)
'receiveLoop end...'
'receiveLoop start...'
'receiveLoop end...'
...
This solved the problem but I don’t think this is the right answer.
const ns = Namespace.createFromConnectionString(connectionString)
const timeout = ms => {
return new Promise(resolve => setTimeout(resolve, ms))
}
const subscribe = async () => {
const receiveLoop = async () => {
console.log('receiveLoop start...')
// move client & receiver making part to here
const subscriptionClient = ns.createSubscriptionClient(topicName, subscriptionName)
const receiver = subscriptionClient.getReceiver()
const message = await receiver.receiveBatch(1, 5)
if (message.length) {
console.log('Message', message[0].body)
await timeout(5000)
await message.complete()
}
console.log('receiveLoop end...')
return await receiveLoop()
}
return await receiveLoop()
}
subscribe()
Expected behavior
Receiving new messages should be stoped during subsequent async calls after receiveBatch()
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (10 by maintainers)
@ramya-rao-a @richardpark-msft - It would be great to get this done soon. It is currently 545 days old as of today. Thanks, Jon