tanszek:oktatas:iss_t:modern_data_integration_based_on_protocol_buffer
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tanszek:oktatas:iss_t:modern_data_integration_based_on_protocol_buffer [2023/03/05 20:47] – knehez | tanszek:oktatas:iss_t:modern_data_integration_based_on_protocol_buffer [2024/03/18 10:07] (current) – knehez | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== Protocol | + | ==== Protocol |
- | This is a solution | + | Protocol Buffers (Protobuf) |
- | Protobuf | + | **Protobuf** requires you to define your structured data in a standard format in a **.proto** file, which is then used to generate source code in your //chosen programming language//. This source code is used to write and read your structured data to and from a variety of data streams and using a variety of languages. |
+ | |||
+ | ==== Key Features of Protobuf ==== | ||
+ | * **Efficiency**: | ||
+ | * **Cross-language**: | ||
+ | * **Backward compatibility**: | ||
+ | * **Less verbose**: Protobuf messages are much less verbose than XML, leading to significant bandwidth savings. | ||
+ | |||
+ | ==== Using Protobuf in Data Integration ==== | ||
+ | |||
+ | // | ||
+ | |||
+ | * **Cross-Language Communication**: | ||
+ | * **Microservices Architecture**: | ||
+ | * **API Development**: | ||
+ | * **Big Data and Streaming**: | ||
+ | * **Data Storage:** Protobuf can also be used for serializing data before | ||
+ | |||
+ | To implement Protobuf in a data integration project, you would typically: | ||
+ | |||
+ | * Define your data structures in a **.proto** file. | ||
+ | * Use the Protobuf compiler (**protoc**) to generate data access classes in your preferred programming language from your .proto files. | ||
+ | * Use these //generated classes// | ||
More details can be found here: | More details can be found here: | ||
Line 9: | Line 31: | ||
https:// | https:// | ||
- | 1.) Install the translator | + | 1.) Install the compiler |
2.) Create a directory called ./proto and the file book.proto with the following content: | 2.) Create a directory called ./proto and the file book.proto with the following content: | ||
- | <code python> | + | <sxh python> |
syntax = " | syntax = " | ||
Line 26: | Line 48: | ||
repeated Book books = 1; | repeated Book books = 1; | ||
} | } | ||
- | </code> | + | </sxh> |
We have created two messages named Book and Books. Books can contain several Books. = 1, = 2 at the end of the lines indicates the internal position of the structure field, numbering starts from one. | We have created two messages named Book and Books. Books can contain several Books. = 1, = 2 at the end of the lines indicates the internal position of the structure field, numbering starts from one. | ||
Line 37: | Line 59: | ||
4.) Upgrade protobuf interface | 4.) Upgrade protobuf interface | ||
- | pip install | + | pip install protobuf |
5.) Create the server.py file with the following content: | 5.) Create the server.py file with the following content: | ||
- | <code python> | + | <sxh python> |
import socket | import socket | ||
import book_pb2 | import book_pb2 | ||
Line 77: | Line 99: | ||
s.close() | s.close() | ||
- | </code> | + | </sxh> |
6.) Create the create_books.py file with the following content: | 6.) Create the create_books.py file with the following content: | ||
- | <code python> | + | <sxh python> |
import book_pb2 | import book_pb2 | ||
Line 106: | Line 128: | ||
return books | return books | ||
- | </code> | + | </sxh> |
7.) Create the client.py file with the following content: | 7.) Create the client.py file with the following content: | ||
- | <code python> | + | <sxh python> |
import socket | import socket | ||
import book_pb2 | import book_pb2 | ||
Line 142: | Line 164: | ||
fb.write(msg) | fb.write(msg) | ||
print(" | print(" | ||
- | </code> | + | </sxh> |
8.) Run the server and client. python server.py then python client.py commands and let's see and analyze what happens? | 8.) Run the server and client. python server.py then python client.py commands and let's see and analyze what happens? |
tanszek/oktatas/iss_t/modern_data_integration_based_on_protocol_buffer.1678049263.txt.gz · Last modified: 2023/03/05 20:47 by knehez