JasperFx / wolverine

Supercharged .NET server side development!
https://wolverinefx.net
MIT License
1.27k stars 139 forks source link

Events with Google PubSub: I don't get it and need help #1132

Closed NeussConsulting closed 1 week ago

NeussConsulting commented 1 week ago

I need help, I'm to stupid to figure out a total "simple" scenario. I tried now for hours and I'm out of ideas.

I just want to publish events into a Google Pub/Sub topic with name "events" and want to get them then out of this and feed them to a Wolverine handler if there is one for this event.

But I get Dead Letter issues or Envelope issues that don't tell me anything. As a little information, I get the topic and that's it, there is no way I allow Wolverine to create topics inside the infrastructure! And I use it with Marten.

// Marten Registration
builder.Services.AddMarten(...)
    .AddAsyncDeamon(DeamonMode.Solo)
    .IntegrateWithWolverine(int => int.UseWolverineManagedEventSubscriptionDistribution = true)

// Wolverine Registration
builder.Host.UseWolverine(opts =>
{
    // AssemblyScanningStuff that works

    opts.UsePubSub("ProjectId");

    opts.PublishAllMessages().ToPubSubTopic("events");

    opts.ListenToPubsubTopic("events");
});

public record GreatEvent(string Text);

public static class GreatEventHandler
{
    public static void Handle(GreatEvent message)
    {
        ...
    }
}

public class SomeController
{
    public async Task<IActionResult> SomeAction()
    {
        await MessageBus.PublishAsync(new GreatEvent("Hello World"));
    }
}

The publishing is working I can see messages are landing inside the topic. But the getting the messages aspect seems not to work, I receive the following exception and my Handler is never called.

PostgresException: null value in column "message_type" of relation wolverine_dead_letters violates not-null constraint.

I think I have two issues here, why is he trying to write something into the dead letter queue in the first place and then the "message_type" issue itself, the error is very clear, but I don't know how to solve it.

A second question (but lower prio) would be, if an application is writing plain PubsubMessages into this topic

var message = new PubsubMessage()
message.Attributes.Add("Hallo", "World");

Google.SDK.PubsubClient.PublishAsync(message);

How would I handle these with Wolverine? Simple like this?

public static class GenericHandler
{
    public static void Handle(PubsubMessage message)
    {
        ...
    }
}

I would be very thankful if someone could help me.

jeremydmiller commented 1 week ago

Couple things.

This:

builder.Services.AddMarten(...)
    .AddAsyncDeamon(DeamonMode.Solo)
    .IntegrateWithWolverine(int => int.UseWolverineManagedEventSubscriptionDistribution = true)

Use one or the other, but not both of those options

So what are the dead letter event stack traces? Or Envelope stack traces? Are you publishing from something that's not Wolverine to Wolverine with the message type error? I think I'd need to see a reproduction to get what's going on there. But in all cases, a stack trace would be very helpful here. I don't see anything above that's not innocuous except for the conflicting configuration I pointed out above. That would absolutely cause errors if you have any async projections

jeremydmiller commented 1 week ago

There's nothing actionable here without more information.