<commit_before>---
title: Event Subscriber
headline: Event Subscriber
bodyclass: docs
layout: docs
sidenav: doc-side-concepts-nav.html
type: markdown
---
<h2 class="top">Event Subscriber</h2> 

Event Subscriber is an object that is subscribed to receive events.

Here is a code example which shows how a method which handles this kind of messages.

  ```
  final class TaskProjection
      extends Projection&lt;TaskId, TaskItem, TaskItemVBuilder&gt; {
      ...
      @Subscribe
      void on(TaskCreated e) {
          builder().setId(e.getId())
                      .setName(e.getName())
      }

      @Subscribe
      void on(TaskCompleted e, EventContext ctx) {
          builder().setWhenDone(ctx.getTimestamp());
      }
  }
  ```<commit_msg>Addressing reviewer's comments for issue #138: Fixing code example in Event Subscriber concept. Removing extra method from code sample.<commit_after>---
title: Event Subscriber
headline: Event Subscriber
bodyclass: docs
layout: docs
sidenav: doc-side-concepts-nav.html
type: markdown
---
<h2 class="top">Event Subscriber</h2> 

Event Subscriber is an object that is subscribed to receive events.

Here is a code example which shows how a method which handles this kind of messages.

  ```
  final class TaskProjection
      extends Projection&lt;TaskId, TaskItem, TaskItemVBuilder&gt; {
      ...
      @Subscribe
      void on(TaskCompleted e, EventContext ctx) {
          builder().setWhenDone(ctx.getTimestamp());
      }
  }
  ```
{'fraction_non_alphanumeric': 0.09825033647375504, 'fraction_numerical': 0.004710632570659489, 'mean_word_length': 3.1769662921348316, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4009807', 'n_tokens_mistral': 440, 'n_tokens_neox': 423, 'n_words': 142}