Skip to content

Kafka ReceiveRawJson disables automatic processing of Envelope.Ping on the consumer's side #2838

Description

@Maflend

Describe the bug
Calling the ReceiveRawJson method disables the default wolverine behavior associated with processing the wolverine/ping message.

I get an error on the consumer:

fail: Wolverine.Runtime.WolverineRuntime[108]
      Envelope Envelope #08deb4de-0758-b6ea-d8bb-c19fcdfd0000 to kafka://topic/wolverine-test-ping was moved to the error queue
      System.Text.Json.JsonException: '0x01' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
       ---> System.Text.Json.JsonReaderException: '0x01' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.

If I delete the call to the Receive Raw Json method, there will be no error, the consumer will not be called, everything is correct.

Source code (wolverine version is 5.39.0):

using Wolverine;
using Wolverine.Kafka;
using Wolverine.Runtime;

var builder = WebApplication.CreateBuilder(args);
var kafkaServers = builder.Configuration["Kafka:BootstrapServers"]!;
const string topic = "wolverine-test-ping";

builder.Host.UseWolverine(opts =>
{
    opts.UseKafka(kafkaServers).AutoProvision();
    opts.PublishMessage<Msg>().ToKafkaTopic(topic);
    opts.ListenToKafkaTopic(topic)
        .ReceiveRawJson<Msg>(); // enable or disable this for test
});

var app = builder.Build();

app.MapGet("/ping", async (IWolverineRuntime runtime) =>
{
    var uri = KafkaEndpointUri.Topic(topic);
    var agent = runtime.Endpoints.GetOrBuildSendingAgent(uri);
    await agent.EnqueueOutgoingAsync(Envelope.ForPing(uri));
});

app.Run();

public record Msg(string Name);

public class MsgConsumer
{
    public void Consume(Msg msg, IMessageContext ctx)
    {
        Console.WriteLine($"EnvelopeId = {ctx.Envelope.Id}");
    }
}

To Reproduce
Steps to reproduce the behavior based on the attached source code:

  1. Call the ReceiveRawJson method
  2. Send a request /ping
  3. You should see an exception in the logs

Expected behavior
ReceiveRawJson should not disable the infrastructure behavior of wolverine.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions