Could you provide an example of CloudEventDataConverterAttribute
jchannon opened this issue · 7 comments
I have the below simple event function:
open Google.Cloud.Functions.Framework
open Google.Events
open Google.Events.Protobuf.Cloud.PubSub.V1
open System.Threading.Tasks
type Function() =
interface ICloudEventFunction<PubsubMessage> with
member this.HandleAsync(cloudEvent, data, cancellationToken) =
printfn "%s" data.TextData
Task.CompletedTask
When deployed I get the error:
System.InvalidOperationException: Unable to create data converter for target type Google.Events.Protobuf.Cloud.PubSub.V1.PubsubMessage
---> System.ArgumentException: Type Google.Events.Protobuf.Cloud.PubSub.V1.PubsubMessage does not have CloudEventDataConverterAttribute applied to it.
at Google.Events.CloudEventConverters.CreateDataConverter[T]()
--- End of inner exception stack trace ---
at Google.Events.CloudEventConverters.CreateDataConverter[T]()
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Google.Events.CloudEventConverters.GetDataConverter[T]()
at Google.Events.CloudEventConverters.ConvertCloudEventData[T](CloudEvent cloudEvent)
at Google.Cloud.Functions.Framework.CloudEventAdapter`1.HandleAsync(HttpContext context)
at Google.Cloud.Functions.Hosting.HostingInternals.Execute(HttpContext context)
at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
The README says the type in the ICloudEventFunction
should have the CloudEventDataConverterAttribute
applied to it but I would have thought GCP types would already have this?
Could you give an example of how to apply CloudEventDataConverterAttribute
to types?
Yes, you shouldn't need to do anything yourself. The trick here is that PubsubMessage
isn't the right type here - you want MessagePublishedData
, which has the attribute as shown here:
That then contains a PubsubMessage
.
See https://cloud.google.com/functions/docs/calling/pubsub#functions_calling_pubsub-csharp for a sample function.
It looks like we need more documentation around the types to use though. If you have any suggestions as to where you would expect to find that sort of thing, that would be really helpful.
Thanks!
The "Trigger type: Cloud Pub/Sub" template for .NET generated by the web frontend has this problem.
@vestigialdev: I don't know what you mean by "this problem", or indeed what you mean by "the web frontend". Could you file a new issue with more details?
@vestigialdev: Ah, hang on - do you mean the template in https://console.cloud.google.com/functions/add uses PubsubMessage
rather than MessagePublishedData
? Will check and fix if that's the case.
I'll leave this issue closed and file an internal issue for that - it's not something that can be fixed within this repository.
Sorry for being unclear- I do mean that the template generated by the Cloud Console (rather than using powershell locally to run dotnet new gcf-event) seems to output a bad Function.cs that doesn't compile/deploy
@vestigialdev: Yup - sorry for taking too long to work out that's what you meant. (First coffee of the day hadn't fully kicked in.)
It turns out there were issues with some other snippets too. I'm fixing those up, and also trying to work out why this wasn't caught in automated testing. Thanks for spotting it and drawing my attention to it.