content: package customer.application;
  
  import akka.javasdk.annotations.Component;
  import akka.javasdk.annotations.Consume;
  import akka.javasdk.annotations.Query;
  import akka.javasdk.view.TableUpdater;
  import akka.javasdk.view.View;
  import customer.domain.CustomerEntries;
  import customer.domain.CustomerEntry;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  // tag::view[]
  @Component(id = "customers-by-name")
  public class CustomersByNameView extends View {
  
    // end::view[]
    private static final Logger logger = LoggerFactory.getLogger(CustomersByNameView.class);
  
    // tag::view[]
  
    @Consume.FromServiceStream( // <1>
      service = "customer-registry", // <2>
      id = "customer_events" // <3>
    )
    public static class CustomersByNameUpdater extends TableUpdater<CustomerEntry> {
  
      public Effect<CustomerEntry> onEvent( // <4>
        CustomerPublicEvent.Created created
      ) {
        // end::view[]
        logger.info("Received: {}", created);
        // tag::view[]
        var id = updateContext().eventSubject().get();
        return effects().updateRow(new CustomerEntry(id, created.email(), created.name()));
      }
  
      public Effect<CustomerEntry> onEvent(CustomerPublicEvent.NameChanged nameChanged) {
        // end::view[]
        logger.info("Received: {}", nameChanged);
        // tag::view[]
        var updated = rowState().withName(nameChanged.newName());
        return effects().updateRow(updated);
      }
    }
  
    @Query("SELECT * as customers FROM customers_by_name WHERE name = :name")
    public QueryEffect<CustomerEntries> findByName(String name) {
      return queryResult();
    }
  }
  // end::view[]
  