-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : send message as string to avoid type header
- Loading branch information
1 parent
7d3a7b9
commit e064484
Showing
13 changed files
with
76 additions
and
53 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
catalog-service/src/main/java/com/example/catalogservice/kafka/CatalogKafkaProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*** | ||
<p> | ||
Licensed under MIT License Copyright (c) 2024 Raja Kolli. | ||
</p> | ||
***/ | ||
|
||
package com.example.catalogservice.kafka; | ||
|
||
import com.example.catalogservice.config.logging.Loggable; | ||
import com.example.catalogservice.mapper.ProductMapper; | ||
import com.example.catalogservice.model.request.ProductRequest; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.springframework.cloud.stream.function.StreamBridge; | ||
import org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Service | ||
@Loggable | ||
public class CatalogKafkaProducer { | ||
|
||
private final StreamBridge streamBridge; | ||
private final ProductMapper productMapper; | ||
private final ObjectMapper objectMapper; | ||
|
||
public CatalogKafkaProducer( | ||
StreamBridge streamBridge, ProductMapper productMapper, ObjectMapper objectMapper) { | ||
this.streamBridge = streamBridge; | ||
this.productMapper = productMapper; | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
public Mono<Boolean> send(ProductRequest productRequest) { | ||
return Mono.fromCallable( | ||
() -> { | ||
// Convert ProductRequest to JSON | ||
return this.objectMapper.writeValueAsString( | ||
this.productMapper.toProductDto(productRequest)); | ||
}) | ||
.flatMap( | ||
productDtoAsString -> | ||
Mono.fromCallable( | ||
() -> { | ||
// Send the message via StreamBridge | ||
return streamBridge.send( | ||
"inventory-out-0", productDtoAsString); | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters