Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
416 stars 181 forks source link

ServiceBusOutput binding for .NET 8 Isolated model function app not sending message to topic subscription #2616

Open pkpaul5 opened 2 months ago

pkpaul5 commented 2 months ago

Description

I have function app with .NET 8 Isolated model which receives and sends message from Service Bus topic subscription. The output message is going to service bus successfully and I can see in the Insights in service bus that incoming messages have come in the topic but no message is showing in the topic subscription. I have checked the topic subscription rule which is based on subject/label. The subject field in the message and subject for rule in subscription are same. Spent many hours debugging the issue but not able to identify the cause. When I am sending the same message with same subject to Service Bus from console application to the same topic using ServiceBusClient and ServiceBusSender, it is working fine. Also noticed in the below article it is mentioned that output parameter can be of type string, byte[] and Object. Does it mean the return data type from the function app can be of above types only for output binding? Then how are we supposed to mention the subject of the message? https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-output?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cfunctionsv2&pivots=programming-language-csharp

Steps to reproduce

Below is the function app code:

[Function(nameof(Function1))]

[ServiceBusOutput("topic2", Connection = "ServiceBusConnection1")]

public async Task<ServiceBusMessage > Run(

[ServiceBusTrigger("topic1", "subscription1", Connection = "ServiceBusConnection1")]

ServiceBusReceivedMessage message,

ServiceBusMessageActions messageActions)
{
_logger.LogInformation("Message ID: {id}", message.MessageId);

_logger.LogInformation("Message Body: {body}", message.Body);

_logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);

await messageActions.CompleteMessageAsync(message);

ServiceBusMessage message1 = new() { Subject = "Subject1" };

message1.MessageId = Guid.NewGuid().ToString();

message1.Body = new BinaryData(Encoding.UTF8.GetBytes("test"));

return message1;

}
kshyju commented 2 months ago

@pkpaul5

The code you provided doesn’t appear to be buildable because your method’s return type is Task, but it includes a return statement. Could you please share the compilable code? Make sure to format the code in your post. We’ll be happy to take a look. Thanks!

pkpaul5 commented 2 months ago

Hi @kshyju , I updated the return type in the description but it is not reflecting. It should be below

Task<ServiceBusMessage>