Error KLX-00121 with a view based on a topic

Hi,
I see the following runtime error for a view that consumes messages from a topic.

Error reported from Kalix system: KLX-00121 An incoming event for the view [ViewName] was missing the subject id attribute ce-subject, view updates are stalled.

What is this ce-subject? I followed the documentation, but I don’t find what is missing. I see this error running the service locally (with the gcloud-pubsub-emulator)
This is the view-declaration

message ViewState{
  //...
}
message Data{
//...
}
service ViewName{
  option (kalix.codegen) = {
    view: {}
  };

  rpc Update(Data) returns (ViewState) {
    option (kalix.method).eventing.in = {
      topic: "data"
    };
    option(kalix.method).view.update = {
      table: "viewname"
      transform_updates: true
    };
  }

I’m using kalix-sdk:1.0.2 and kalix-proxy:1.0.10

The cloud event subject id is used to identify what row in the view to update for an incoming event, without it a view cannot know which view entry it should update.

Note that it is also important to enable event ordering and use the same id for the google pub sub ordering key with the subject id to guarantee that a view entry is not updated by two events processed in parallel (and therefore losing one of the updates to the same view entry).

If you are producing to the topic from an action you can pass the id via metadata, something like this:

var metadata = actionContext().metadata().set("ce-subject", request.anId);
return effects().reply(reply, metadata);

If you are producing to google pub sub from the “outside” the subject id can be specified via an custom event attribute ce-subject.

For future reference: Better to create new MetaData object instead of passing along the one from the calling context.

Indeed, sorry about the previous code snippet here, that was not a good idea, passing the full request metadata out with the response.

Creating a new one and only setting the metadata is the way to go:

return effects().reply(
  message, 
  Metadata.EMPTY.set("ce-subject", message.id))