ServiceBusOutput binding for .NET 8 Isolated function app not sending message to topic subscription in Service Bus

Prasenjit Paul (HCL Technologies Corporate Ser) 0 Reputation points Microsoft Vendor
2024-07-16T09:24:00.78+00:00

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 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 message to Service Bus from console application, it is working fine. 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;

}

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
586 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,620 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pinaki Ghatak 3,110 Reputation points Microsoft Employee
    2024-07-17T10:12:34.55+00:00

    Hello Prasenjit Paul (HCL Technologies Corporate Ser)

    Based on the code you provided, it seems that you are using the ServiceBusOutput binding to send messages to a Service Bus topic subscription.

    One possible reason for this issue could be that the subscription rule is not configured correctly. You mentioned that the subject field in the message and subject for rule in subscription are the same, but it's possible that there is a typo or a mismatch in the subject name. Please double-check the subject name in both the message and the subscription rule to ensure that they match exactly.

    Another possible reason could be that the messages are being sent to a different subscription or topic than the one you are expecting. Please verify that the topic2 and subscription1 variables in the ServiceBusOutput and ServiceBusTrigger attributes are set correctly.

    Additionally, you mentioned that sending messages from a console application works fine. This suggests that the issue may be specific to the function app code. Please ensure that the function app is running correctly and that there are no errors or exceptions being thrown during message processing. If none of these suggestions resolve the issue, please provide more information such as any error messages or exceptions that you are seeing, and any additional code or configuration details that may be relevant.