diff --git a/src/main/kotlin/com/api/nft/config/KafkaConfig.kt b/src/main/kotlin/com/api/nft/config/KafkaConfig.kt index 87c0722..5eac751 100644 --- a/src/main/kotlin/com/api/nft/config/KafkaConfig.kt +++ b/src/main/kotlin/com/api/nft/config/KafkaConfig.kt @@ -1,6 +1,7 @@ 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 @@ -9,11 +10,11 @@ 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.ContainerProperties import org.springframework.kafka.listener.MessageListenerContainer import org.springframework.kafka.support.serializer.JsonDeserializer @@ -33,7 +34,7 @@ class KafkaConfig { val props = mapOf( ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, - ConsumerConfig.GROUP_ID_CONFIG to "wallet-group", + 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 "*", diff --git a/src/main/kotlin/com/api/nft/config/RabbitConfig.kt b/src/main/kotlin/com/api/nft/config/RabbitConfig.kt index ef5b415..b189c52 100644 --- a/src/main/kotlin/com/api/nft/config/RabbitConfig.kt +++ b/src/main/kotlin/com/api/nft/config/RabbitConfig.kt @@ -29,12 +29,4 @@ class RabbitConfig { @Bean fun nftExchange() = createFanoutExchange("nftExchange") - - - @Bean - fun listingExchange() = createFanoutExchange("listingExchange") - - - @Bean - fun auctionExchange() = createFanoutExchange("auctionExchange") } \ No newline at end of file diff --git a/src/main/kotlin/com/api/nft/kafka/KafkaConsumer.kt b/src/main/kotlin/com/api/nft/kafka/KafkaConsumer.kt index c42a3e5..5f540fe 100644 --- a/src/main/kotlin/com/api/nft/kafka/KafkaConsumer.kt +++ b/src/main/kotlin/com/api/nft/kafka/KafkaConsumer.kt @@ -1,6 +1,9 @@ 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 @@ -9,6 +12,8 @@ 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", @@ -19,8 +24,12 @@ class KafkaConsumer( 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() } } diff --git a/src/main/kotlin/com/api/nft/kafka/dto/SaleResponse.kt b/src/main/kotlin/com/api/nft/kafka/dto/SaleResponse.kt index 3b6f227..409d246 100644 --- a/src/main/kotlin/com/api/nft/kafka/dto/SaleResponse.kt +++ b/src/main/kotlin/com/api/nft/kafka/dto/SaleResponse.kt @@ -12,7 +12,7 @@ data class SaleResponse( val createdDateTime: Long, val endDateTime: Long, val statusType: StatusType, - val startingPrice: BigDecimal, + val price: BigDecimal, val chainType: ChainType, val orderType: OrderType ) diff --git a/src/main/kotlin/com/api/nft/rabbitMQ/RabbitMQReceiver.kt b/src/main/kotlin/com/api/nft/rabbitMQ/RabbitMQReceiver.kt deleted file mode 100644 index 3dc84bf..0000000 --- a/src/main/kotlin/com/api/nft/rabbitMQ/RabbitMQReceiver.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.api.nft.rabbitMQ - -import com.api.nft.service.api.NftAuctionService -import com.api.nft.service.api.NftListingService -import com.api.nft.service.dto.ListingResponse -import org.springframework.amqp.core.ExchangeTypes -import org.springframework.amqp.rabbit.annotation.Exchange -import org.springframework.amqp.rabbit.annotation.Queue -import org.springframework.amqp.rabbit.annotation.QueueBinding -import org.springframework.amqp.rabbit.annotation.RabbitListener -import org.springframework.stereotype.Service -import com.api.nft.service.dto.AuctionResponse as AuctionResponse - -@Service -class RabbitMQReceiver( - private val nftListingService: NftListingService, - private val nftAuctionService: NftAuctionService -) { - - - @RabbitListener(bindings = [QueueBinding( - value = Queue(name = "", durable = "false", exclusive = "true", autoDelete = "true"), - exchange = Exchange(value = "listingExchange", type = ExchangeTypes.FANOUT) - )]) - fun listingMessage(listing: ListingResponse){ - nftListingService.update(listing).subscribe() - } - - @RabbitListener(bindings = [QueueBinding( - value = Queue(name = "", durable = "false", exclusive = "true", autoDelete = "true"), - exchange = Exchange(value = "auctionExchange", type = ExchangeTypes.FANOUT) - )]) - fun auctionMessage(auction: AuctionResponse){ - nftAuctionService.update(auction).subscribe() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/api/nft/service/api/NftAuctionService.kt b/src/main/kotlin/com/api/nft/service/api/NftAuctionService.kt index 58102fd..8fee8cb 100644 --- a/src/main/kotlin/com/api/nft/service/api/NftAuctionService.kt +++ b/src/main/kotlin/com/api/nft/service/api/NftAuctionService.kt @@ -3,6 +3,7 @@ package com.api.nft.service.api import com.api.nft.domain.nft.NftAuction import com.api.nft.domain.nft.repository.NftAuctionRepository import com.api.nft.enums.StatusType +import com.api.nft.kafka.dto.SaleResponse import com.api.nft.service.dto.AuctionResponse import org.springframework.stereotype.Service import reactor.core.publisher.Mono @@ -12,7 +13,7 @@ class NftAuctionService( private val nftAuctionRepository: NftAuctionRepository, ) { - fun update(newAuction: AuctionResponse): Mono { + fun update(newAuction: SaleResponse): Mono { return when (newAuction.statusType) { StatusType.RESERVATION -> { save(newAuction) @@ -33,12 +34,12 @@ class NftAuctionService( else -> Mono.empty() } } - fun save(auction: AuctionResponse) : Mono { + fun save(auction: SaleResponse) : Mono { return nftAuctionRepository.save( NftAuction( id = auction.id, nftId = auction.nftId, - startingPrice = auction.startingPrice, + startingPrice = auction.price, chainType = auction.chainType, statusType = auction.statusType, createdDate = auction.createdDateTime, diff --git a/src/main/kotlin/com/api/nft/service/api/NftListingService.kt b/src/main/kotlin/com/api/nft/service/api/NftListingService.kt index 1741c41..0850702 100644 --- a/src/main/kotlin/com/api/nft/service/api/NftListingService.kt +++ b/src/main/kotlin/com/api/nft/service/api/NftListingService.kt @@ -3,6 +3,7 @@ package com.api.nft.service.api import com.api.nft.domain.nft.NftListing import com.api.nft.domain.nft.repository.NftListingRepository import com.api.nft.enums.StatusType +import com.api.nft.kafka.dto.SaleResponse import com.api.nft.service.RedisService import com.api.nft.service.dto.ListingResponse import org.springframework.stereotype.Service @@ -14,7 +15,7 @@ class NftListingService( private val redisService: RedisService, ) { - fun update(newListing: ListingResponse): Mono { + fun update(newListing: SaleResponse): Mono { return when (newListing.statusType) { StatusType.RESERVATION -> { save(newListing) @@ -37,7 +38,7 @@ class NftListingService( else -> Mono.empty() } } - fun save(listing: ListingResponse) : Mono { + fun save(listing: SaleResponse) : Mono { return nftListingRepository.save( NftListing( id = listing.id, diff --git a/src/main/kotlin/com/api/nft/service/external/moralis/MoralisApiService.kt b/src/main/kotlin/com/api/nft/service/external/moralis/MoralisApiService.kt index 605e570..41ef570 100644 --- a/src/main/kotlin/com/api/nft/service/external/moralis/MoralisApiService.kt +++ b/src/main/kotlin/com/api/nft/service/external/moralis/MoralisApiService.kt @@ -27,7 +27,7 @@ class MoralisApiService( ChainType.LINEA_SEPOLIA -> "0xe705" ChainType.ETHEREUM_HOLESKY -> "0x4268" ChainType.ETHEREUM_SEPOLIA -> "0xaa36a7" - ChainType.POLYGON_AMOY -> "0xaa36a7" + ChainType.POLYGON_AMOY -> "0x13882" } return chain }