Azure函数ServiceBusReceivedMessage不工作

vsnjm48y  于 2023-05-18  发布在  其他
关注(0)|答案(1)|浏览(179)

我正在尝试与MassTransit一起创建一个azure函数,但是我遇到了一个问题,因为ServiceBusReceivedMessage对象是函数中的一个参数。这是根据教程。当我将消息发送到topic/queue时,它在以下错误时崩溃。你知道该怎么做吗?我做错什么了吗?谢谢你

[Function("Function1")]
        public async Task Run([ServiceBusTrigger(_topic, _sub)] ServiceBusReceivedMessage message, ServiceBusMessageActions messageAction)
        {
            return _reciever.HandleConsumer<TestConsumer>(_topic, _sub, messages, cancellationToken);
        }

_publishEndpoint.Publish<TestMessage>(new TestMessage() { Test = "Test" }); // { "Test": "Test" }
我得到了这个错误:

Azure Functions Core Tools
Core Tools Version:       4.0.5148 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.17.3.20392

[2023-05-16T05:42:32.811Z] Found C:\user\workspace\Checks.Function\Src\Checks.FunctionApp2\Checks.FunctionApp2.csproj. Using for user secrets file configuration.

Functions:

        Function1: serviceBusTrigger

For detailed output, run func with --verbose flag.
[2023-05-16T05:42:35.335Z] Azure Functions .NET Worker (PID: 28972) initialized in debug mode. Waiting for debugger to attach...
[2023-05-16T05:42:40.244Z] Host lock lease acquired by instance ID '0000000000000000000000002BA96687'.
[2023-05-16T05:42:40.923Z] Worker process started and initialized.
[2023-05-16T05:44:11.382Z] Executing 'Functions.Function1' (Reason='(null)', Id=da963684-80bf-4672-b144-b9f50986c296)
[2023-05-16T05:44:11.386Z] Trigger Details: MessageId: 21adc57c25a84c5bb7473a8bac1391ad, SequenceNumber: 6, DeliveryCount: 1, EnqueuedTimeUtc: 2023-05-16T05:44:11.0720000+00:00, LockedUntilUtc: 2023-05-16T05:45:11.0720000+00:00, SessionId: (null)
[2023-05-16T05:44:11.622Z] Starting MassTransit
[2023-05-16T05:44:12.024Z] Function 'Function1', Invocation id 'da963684-80bf-4672-b144-b9f50986c296': An exception was thrown by the invocation.
[2023-05-16T05:44:12.026Z] Result: Function 'Function1', Invocation id 'da963684-80bf-4672-b144-b9f50986c296': An exception was thrown by the invocation.
Exception: Microsoft.Azure.Functions.Worker.FunctionInputConverterException: Error converting 1 input parameters for Function 'Function1': Cannot convert input parameter 'message' to type 'Azure.Messaging.ServiceBus.ServiceBusReceivedMessage' from type 'System.String'. Error:System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Azure.Messaging.ServiceBus.ServiceBusReceivedMessage'. Path: $ | LineNumber: 0 | BytePositionInLine: 1.
[2023-05-16T05:44:12.030Z]  ---> System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Azure.Messaging.ServiceBus.ServiceBusReceivedMessage'.
[2023-05-16T05:44:12.037Z]    --- End of inner exception stack trace ---
[2023-05-16T05:44:12.039Z]    at System.Text.Json.ThrowHelper.ThrowNotSupportedException(ReadStack& state, Utf8JsonReader& reader, NotSupportedException ex)
[2023-05-16T05:44:12.042Z]    at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
[2023-05-16T05:44:12.045Z]    at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
[2023-05-16T05:44:12.048Z]    at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
[2023-05-16T05:44:12.054Z]    at System.Text.Json.Serialization.JsonConverter`1.ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
[2023-05-16T05:44:12.057Z]    at System.Text.Json.JsonSerializer.ReadCore[TValue](Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo, ReadStack& state)
[2023-05-16T05:44:12.061Z]    at System.Text.Json.JsonSerializer.ContinueDeserialize[TValue](ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack, JsonTypeInfo jsonTypeInfo)
[2023-05-16T05:44:12.066Z]    at System.Text.Json.JsonSerializer.ReadFromStreamAsync[TValue](Stream utf8Json, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
[2023-05-16T05:44:12.071Z]    at Microsoft.Azure.Functions.Worker.Converters.JsonPocoConverter.GetConversionResultFromDeserialization(Byte[] bytes, Type type) in D:\a\_work\1\s\src\DotNetWorker.Core\Converters\JsonPocoConverter.cs:line 66
[2023-05-16T05:44:12.075Z]    at Microsoft.Azure.Functions.Worker.Context.Features.DefaultFunctionInputBindingFeature.BindFunctionInputAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Context\Features\DefaultFunctionInputBindingFeature.cs:line 106
[2023-05-16T05:44:12.079Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 42
[2023-05-16T05:44:12.087Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2023-05-16T05:44:12.093Z]    at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 77
Stack:    at Microsoft.Azure.Functions.Worker.Context.Features.DefaultFunctionInputBindingFeature.BindFunctionInputAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Context\Features\DefaultFunctionInputBindingFeature.cs:line 106
[2023-05-16T05:44:12.099Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 42
[2023-05-16T05:44:12.102Z]    at 
.... More info in file
```[text]



I tried to modify the method header in various ways, but nothing really worked. I've tried sending a different message, but nothing either. Anyway, I tried a google search, but I couldn't find exactly what I was looking for.
0lvr5msh

0lvr5msh1#

Azure Functions不适用于.NET 7,您需要坚持使用.NET 6才能正常工作。
MassTransit Sample展示了如何在v4函数运行时中正确使用Azure函数。

相关问题