-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from NTF-marketplace/develop
Develop
- Loading branch information
Showing
16 changed files
with
190 additions
and
88 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.api.nft.config | ||
|
||
import org.apache.kafka.clients.admin.AdminClientConfig | ||
import org.apache.kafka.clients.admin.NewTopic | ||
import org.apache.kafka.clients.consumer.ConsumerConfig | ||
import org.apache.kafka.common.serialization.StringDeserializer | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.kafka.annotation.EnableKafka | ||
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory | ||
import org.springframework.kafka.config.TopicBuilder | ||
import org.springframework.kafka.core.ConsumerFactory | ||
import org.springframework.kafka.core.DefaultKafkaConsumerFactory | ||
import org.springframework.kafka.core.KafkaAdmin | ||
import org.springframework.kafka.listener.CommonErrorHandler | ||
import org.springframework.kafka.listener.MessageListenerContainer | ||
import org.springframework.kafka.support.serializer.JsonDeserializer | ||
|
||
@Configuration | ||
@EnableKafka | ||
class KafkaConfig { | ||
private val logger = LoggerFactory.getLogger(KafkaConfig::class.java) | ||
|
||
@Value("\${spring.kafka.bootstrap-servers}") | ||
private lateinit var bootstrapServers: String | ||
|
||
@Bean | ||
fun kafkaAdmin(): KafkaAdmin = KafkaAdmin(mapOf(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers)) | ||
|
||
@Bean | ||
fun consumerFactory(): ConsumerFactory<String, Any> { | ||
val props = | ||
mapOf( | ||
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, | ||
ConsumerConfig.GROUP_ID_CONFIG to "nft-group", | ||
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java.name, | ||
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to JsonDeserializer::class.java.name, | ||
JsonDeserializer.TRUSTED_PACKAGES to "*", | ||
JsonDeserializer.VALUE_DEFAULT_TYPE to Any::class.java.name, | ||
) | ||
return DefaultKafkaConsumerFactory(props, StringDeserializer(), JsonDeserializer(Any::class.java, false)) | ||
} | ||
|
||
@Bean | ||
fun kafkaListenerContainerFactory(): ConcurrentKafkaListenerContainerFactory<String, Any> { | ||
val factory = ConcurrentKafkaListenerContainerFactory<String, Any>() | ||
factory.consumerFactory = consumerFactory() | ||
factory.setConcurrency(4) | ||
factory.setCommonErrorHandler( | ||
object : CommonErrorHandler { | ||
override fun handleRemaining( | ||
thrownException: Exception, | ||
records: List<org.apache.kafka.clients.consumer.ConsumerRecord<*, *>>, | ||
consumer: org.apache.kafka.clients.consumer.Consumer<*, *>, | ||
container: MessageListenerContainer, | ||
) { | ||
logger.error("Error in consumer: ${thrownException.message}", thrownException) | ||
logger.error("Problematic records: $records") | ||
} | ||
}, | ||
) | ||
return factory | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.api.nft.kafka | ||
|
||
import com.api.nft.enums.OrderType | ||
import com.api.nft.kafka.dto.SaleResponse | ||
import com.api.nft.service.api.NftAuctionService | ||
import com.api.nft.service.api.NftListingService | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.springframework.kafka.annotation.KafkaListener | ||
import org.springframework.messaging.Message | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class KafkaConsumer( | ||
private val objectMapper: ObjectMapper, | ||
private val nftListingService: NftListingService, | ||
private val nftAuctionService: NftAuctionService | ||
) { | ||
@KafkaListener(topics = ["sale-topic"], | ||
groupId = "nft-group", | ||
containerFactory = "kafkaListenerContainerFactory" | ||
) | ||
fun consumeLedgerStatusEvents(message: Message<Any>) { | ||
val payload = message.payload | ||
|
||
if (payload is LinkedHashMap<*, *>) { | ||
val saleStatusRequest = objectMapper.convertValue(payload, SaleResponse::class.java) | ||
println("saleStatusRequest : " + saleStatusRequest) | ||
when(saleStatusRequest.orderType){ | ||
OrderType.LISTING -> nftListingService.update(saleStatusRequest).subscribe() | ||
OrderType.AUCTION -> nftAuctionService.update(saleStatusRequest).subscribe() | ||
} | ||
|
||
// orderService.updateOrderStatus(ledgerStatusRequest).subscribe() | ||
} | ||
} | ||
|
||
} |
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,20 @@ | ||
package com.api.nft.kafka.dto | ||
|
||
import com.api.nft.enums.ChainType | ||
import com.api.nft.enums.StatusType | ||
import com.api.nft.enums.OrderType | ||
import java.math.BigDecimal | ||
|
||
data class SaleResponse( | ||
val id : Long, | ||
val nftId : Long, | ||
val address: String, | ||
val createdDateTime: Long, | ||
val endDateTime: Long, | ||
val statusType: StatusType, | ||
val price: BigDecimal, | ||
val chainType: ChainType, | ||
val orderType: OrderType | ||
) | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.