Şu satırı dahil ederiz
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-protobuf</artifactId></dependency>
2. src/main/proto/ dizinine proto dosyasını tanımlarız
Örnek
Şöyle yaparız
syntax = "proto3";
package example;
message Product {
    string id = 1;
    string name = 2;
    double price = 3;
}3. plugin tanımlarız
Örnek
Şöyle yaparız
<!-- pom.xml configuration for protobuf-maven-plugin -->
<build>
    <plugins>
        <plugin>
            <groupId>org.xolstice.maven.plugins</groupId>
            <artifactId>protobuf-maven-plugin</artifactId>
            <version>0.6.1</version>
            ...
        </plugin>
    </plugins>
</build>4. Rest Controller tanımlarız
Örnek
Şöyle yaparız
@RestController
public class ProductController {
    @PostMapping("/product")
    public Product addProduct(@RequestBody Product product) {
        // Business logic here
        return product;
    }
}Açıklaması şöyle
When a request is received, Spring will automatically handle the deserialization from the Protocol Buffers format to a Product object. Similarly, the response will be automatically serialized to the Protocol Buffers format.
 
Hiç yorum yok:
Yorum Gönder