- Apache Kafka Quick Start Guide
- Raúl Estrada
- 532字
- 2021-07-02 14:26:56
Event modeling
The first step in event modeling is to express the event in English in the following form:
Subject-verb-direct object
For this example, we are modeling the event customer consults the ETH price:
- The subject in this sentence is customer, a noun in nominative case. The subject is the entity performing the action.
- The verb in this sentence is consults; it describes the action performed by the subject.
- The direct object in this sentence is ETH price. The object is the entity in which the action is being done.
We can represent our message in several message formats (covered in other sections of this book):
- JavaScript Object Notation (JSON)
- Apache Avro
- Apache Thrift
- Protocol Buffers
JSON is easily read and written by both humans and machines. For example, we could chose binary as the representation, but it has a rigid format and it was not designed for humans to read it; as counterweight, binary representation is very fast and lightweight in processing.
Listing 2.1, shows the representation of the CUSTOMER_CONSULTS_ETHPRICE event in JSON format:
{
"event": "CUSTOMER_CONSULTS_ETHPRICE",
"customer": {
"id": "14862768",
"name": "Snowden, Edward",
"ipAddress": "95.31.18.111"
},
"currency": {
"name": "ethereum",
"price": "RUB"
},
"timestamp": "2018-09-28T09:09:09Z"
}
For this example, the Ethereum (ETH) currency price is expressed in Russian rouble (RUB). This JSON message has four sections:
- event: This is a string with the event's name.
- customer: This represents the person (in this case its id is 14862768) consulting the Ethereum price. In this representation, there is a unique id for the customer, the name, and the browser ipAddress, which is the IP address of the computer the customer is logged on.
- currency: This contains the cryptocurrency name and the currency in which the price is expressed.
- timestamp: The timestamp in which the customer made the request (UTC).
From another perspective, the message has two parts: the metadata—this is the event name and the timestamp and two business entities, the customer and the currency. As we can see, this message can be read and understood by a human.
Other messages from the same use case in JSON format could be as follows:
{ "event": "CUSTOMER_CONSULTS_ETHPRICE",
"customer": {
"id": "13548310",
"name": "Assange, Julian",
"ipAddress": "185.86.151.11"
},
"currency": {
"name": "ethereum",
"price": "EUR"
},
"timestamp": "2018-09-28T08:08:14Z"
}
This is another example:
{ "event": "CUSTOMER_CONSULTS_ETHPRICE",
"customer": {
"id": "15887564",
"name": "Mills, Lindsay",
"ipAddress": "186.46.129.15"
},
"currency": {
"name": "ethereum",
"price": "USD"
},
"timestamp": "2018-09-28T19:51:35Z"
}
What happens if we want to represent our message in the Avro schema? Yes, the Avro schema of our message (note that it's not the message, but the schema) is in Listing 2.2:
{ "name": "customer_consults_ethprice",
"namespace": "monedero.avro",
"type": "record",
"fields": [
{ "name": "event", "type": "string" },
{ "name": "customer",
"type": {
"name": "id", "type": "long",
"name": "name", "type": "string",
"name": "ipAddress", "type": "string"
}
},
{ "name": "currency",
"type": {
"name": "name", "type": "string",
"name": "price", "type": {
"type": "enum", "namespace": "monedero.avro",
"name": "priceEnum", "symbols": ["USD", "EUR", "RUB"]}
}
},
{ "name": "timestamp", "type": "long",
"logicalType": "timestamp-millis"
}
]
}
For more information about the Avro schema, check the Apache Avro specification:
- 新編Visual Basic程序設計上機實驗教程
- 演進式架構(原書第2版)
- JavaScript全程指南
- LabVIEW程序設計基礎與應用
- Learning Real-time Processing with Spark Streaming
- Manga Studio Ex 5 Cookbook
- C++面向對象程序設計(微課版)
- Java從入門到精通(第4版)
- 零基礎學Java(第4版)
- Learning Apache Kafka(Second Edition)
- 用Flutter極速構建原生應用
- 微服務架構深度解析:原理、實踐與進階
- Continuous Delivery and DevOps:A Quickstart Guide Second Edition
- INSTANT Apache Hive Essentials How-to
- Android 游戲開發大全(第二版)