Azure / Azure/Azure-Functions

ServiceBusTrigger (nodejs) doesn't preserve the relationship between the messages received and the correlation ids in the binding data.

Open
#2,084 3 comments 0 reactions 1 assignee Claimed by @v-bbalaiagar View on GitHub
bug needs-investigation
Dominant language
PowerShell
Stars
1.1k
Forks
215
Avg merge
4h 2m
Merged PRs (30d)
1

Description

The number of messages received by the service bus trigger is not consistent with the number of correlation ids in the binding data making it impossible to know which correlation id was related to any given message.

---

I am using a azure function **project runtime of ~3** and TypeScript as the project language.

I am using a service bus input binding configure in the following way
```
{
"bindings": [
{
"name": "myBindingName",
"type": "serviceBusTrigger",
"direction": "in",
"cardinality": "many",
"connection": "ServiceBusConnection",
"subscriptionName": "mySubscription",
"topicName": "myTopic",
"isSessionsEnabled": true
}
],
"scriptFile": "../dist/index.js"
}
```

The source file contains the following function
```
import { AzureFunction, Context } from '@azure/functions'

const servicesBusTrigger: AzureFunction = async (
context: Context,
messages
) => {
context.log('Binding Data =', context.bindingData)
context.log('Messages =', messages)

const sessionId = context.bindingData.messageSession.sessionId
console.log('sessionId =', sessionId)

const correlationIds: string[] = context.bindingData.correlationIdArray
console.log('correlationIds =', correlationIds)

}
export default servicesBusTrigger;
```

I am expecting to multiplex on session Id and receive batches of messages within each session. This is configured in the function.json file by **isSessionEnabled: true** and **"cardinality": "many"**

I am receiving multiple messages with the same session id, however the length of `messages` and the length of the `correlationIdArray` are not always equal leaving me unable to determine which correlation id is associated to any given message.

For example the logs include:

```
Binding Data = {
invocationId: 'aff16f15-acca-4246-8f63-8112f43c3371',
messageReceiver: {
lockedUntilUtc: '2021-10-22T16:47:27.1596554Z',
sessionId: 'A',
registeredPlugins: [],
receiveMode: 0,
prefetchCount: 4,
lastPeekedSequenceNumber: 0,
path: 'XXXX',
operationTimeout: '00:01:00',
serviceBusConnection: {
endpoint: 'XXXX',
operationTimeout: '00:01:00',
retryPolicy: [Object],
transportType: 0,
tokenProvider: {},
isClosedOrClosing: false
},
isClosedOrClosing: false,
ownsConnection: false,
clientId: 'XXXX',
retryPolicy: {
minimalBackoff: '00:00:00',
maximumBackoff: '00:00:30',
deltaBackoff: '00:00:03',
maxRetryCount: 5,
isServerBusy: false,
serverBusyExceptionMessage: null
}
},
messageSession: {
lockedUntilUtc: '2021-10-22T16:47:27.1596554Z',
sessionId: 'A',
registeredPlugins: [],
receiveMode: 0,
prefetchCount: 4,
lastPeekedSequenceNumber: 0,
path: 'XXXX',
operationTimeout: '00:01:00',
serviceBusConnection: {
endpoint: 'XXXX',
operationTimeout: '00:01:00',
retryPolicy: [Object],
transportType: 0,
tokenProvider: {},
isClosedOrClosing: false
},
isClosedOrClosing: false,
ownsConnection: false,
clientId: 'XXXX',
retryPolicy: {
minimalBackoff: '00:00:00',
maximumBackoff: '00:00:30',
deltaBackoff: '00:00:03',
maxRetryCount: 5,
isServerBusy: false,
serverBusyExceptionMessage: null
}
},
deliveryCountArray: [ 1, 1, 1 ],
deadLetterSourceArray: [],
lockTokenArray: [
'1ae2dc47-e6c1-4730-97d6-3bd276a460ca',
'ff6fc435-6358-4e3a-96ee-d0520457a4a7',
'7d362753-1769-4ea7-9cc7-e453601f7539'
],
expiresAtUtcArray: [
'2021-11-05T16:46:51.69Z',
'2021-11-05T16:46:51.69Z',
'2021-11-05T16:46:51.69Z'
],
enqueuedTimeUtcArray: [
'2021-10-22T16:46:51.69Z',
'2021-10-22T16:46:51.69Z',
'2021-10-22T16:46:51.69Z'
],
messageIdArray: [
'd24a3661-5fc2-4314-93b3-c8c70ee9c309',
'47800520-19b6-4607-826a-3ec34d54f242',
'973ae730-4013-46c6-8c50-d5d98a8ddc98'
],
contentTypeArray: [],
replyToArray: [],
sequenceNumberArray: [ '137', '138', '139' ],
toArray: [],
labelArray: [],
correlationIdArray: [ 'A', 'C' ],
userPropertiesArray: [ {}, {}, {} ]
}
Messages = [
{prop: 'value'},
{prop: 'value'},
{prop: 'value'}
]
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.