Skip to content

ServiceBus output binding messages not of type 'application/json' #107

Open
@bitbaggi

Description

@bitbaggi

Hi there,

as in the documentation described, i want to send an message to azure service bus with contentType 'application/json'.

Documentation:
"Access the queue or topic by using context.bindings.. You can assign a string, a byte array, or a JavaScript object (deserialized into JSON) to context.binding.."

My Code:

import {app, HttpResponseInit, InvocationContext, output} from "@azure/functions"
import {Timer} from "@azure/functions/types/timer";

const serviceBusOutput = output.serviceBusTopic({
    topicName: 'test-topic',
    connection: 'ConnectionString_ServiceBus',
});

export async function httpTrigger1(myTimer: Timer, context: InvocationContext): Promise<HttpResponseInit> {
    const outputMessages = [];
    outputMessages.push(
        {propName: 'test'}
    );
    outputMessages.push(
        JSON.stringify({propName: 'test'})
    );
    outputMessages.push(
        new Object({propName: 'test'})
    );
    outputMessages.push(
        Object.create({propName: 'test'})
    );
    outputMessages.push(
        ['propName', 'test2']
    );
    outputMessages.push(
        "{\"propName\":\"test\"}"
    );

    context.extraOutputs.set(serviceBusOutput, outputMessages);
    return {body: `Hello, ${'name'}!`};
}

app.timer('test', {
    schedule: '*/10 * * * * *',
    extraOutputs: [serviceBusOutput],
    handler: httpTrigger1
})

My expectation:
In Azure service bus i expect 6 Messages, first 5 in format 'application/json' and the last one, because its a string in 'text/plain'

What i get:
Messages in Azure Service, all have contentType 'text/plain'.
image

How could i get 'application/json' as contentType?

My Setup:
I use azure functions with typescript as language.

host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "watchDirectories": ["./"],
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  }
}

dependencies in package.json:

 "dependencies": {
    "@azure/functions": "^4.0.0-alpha.11"
  },
  "devDependencies": {
    "@types/node": "18.x",
    "typescript": "^5.1.3"
  }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions