Skip to content

Commit

Permalink
[PPABV-34] feat: pm database connection configured (#139)
Browse files Browse the repository at this point in the history
* feat: pm database connection configured

* feat: new connection to the second db has been estabilished

* fix: connection update to multiple databases with a single client
  • Loading branch information
FrancescoDiTonno-BVT authored Oct 29, 2024
1 parent c4c6041 commit 1e70335
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 118 deletions.
25 changes: 0 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,6 @@ services:
depends_on:
- mongo

mongo-history:
container_name: pagopa-history-helpdesk-mongo
image: mongo
env_file: docker/mongoDB/conf/mongodb-history.env
ports:
- "27018:27017"
networks:
- pagopa-ecommerce-net
healthcheck:
test: echo "db.stats().ok" | mongo --quiet
interval: 10s
volumes:
- ./docker/mongoDB/mongo-history-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro

mongo-express-history:
container_name: pagopa-history-helpdesk-express
image: mongo-express
env_file: docker/mongoDB/conf/mongo-express-history.env
ports:
- "8082:8081"
networks:
- pagopa-ecommerce-net
depends_on:
- mongo-history

pagopa-pdv-mock:
container_name: pagopa-pdv-mock-helpdesk
build:
Expand Down
3 changes: 0 additions & 3 deletions docker/mongoDB/conf/mongo-express-history.env

This file was deleted.

3 changes: 0 additions & 3 deletions docker/mongoDB/conf/mongodb-history.env

This file was deleted.

75 changes: 0 additions & 75 deletions docker/mongoDB/mongo-history-init.js

This file was deleted.

75 changes: 75 additions & 0 deletions docker/mongoDB/mongo-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,78 @@ db.getCollection('dead-letter-events').insertMany([{
"insertionDate": "2023-11-30T14:50:27.001Z",
"data": "NOTIFICATIONS_SERVICE"
}]);

db2 = conn.getDB("ecommerce-history");

db2.getCollection('pm-transactions-history').insertMany([{
"userInfo": {
"userFiscalCode": "RSSMRA80A01H501U",
"notificationEmail": "[email protected]",
"authenticationType": 1
},
"transactionInfo": {
"creationDate": "2024-05-10T11:14:32.556+02:00",
"status": 1,
"statusDetails": 1,
"amount": 30000,
"fee": 100,
"grandTotal": 30100,
"rrn": "241310000102",
"authorizationCode": "00",
"paymentMethodName": "Pagamento con carte"
},
"paymentInfo": {
"origin": "CITTADINANZA_DIGITALE",
"details": [
{
"subject": "TARI 2021",
"iuv": "02055446688775544",
"idTransaction": "feae3da1480841a6ba11520cbd36090b",
"creditorInstitution": "EC_TE",
"paFiscalCode": "77777777777"
}
]
},
"pspInfo": {
"pspId": "UNCRITMM",
"businessName": "UniCredit S.p.A",
"idChannel": "00348170101_01_ONUS"
},
"product": "PM"
},
{
"userInfo": {
"userFiscalCode": "NVEGVN80A01H501U",
"notificationEmail": "[email protected]",
"authenticationType": 1
},
"transactionInfo": {
"creationDate": "2024-06-10T11:14:32.556+02:00",
"status": 1,
"statusDetails": 1,
"amount": 45000,
"fee": 150,
"grandTotal": 45150,
"rrn": "241310000103",
"authorizationCode": "01",
"paymentMethodName": "Pagamento con carte"
},
"paymentInfo": {
"origin": "CITTADINANZA_DIGITALE",
"details": [
{
"subject": "TARI 2022",
"iuv": "02055446688775545",
"idTransaction": "feae3da1480841a6ba11520cbd36091c",
"creditorInstitution": "EC_TE",
"paFiscalCode": "77777777777"
}
]
},
"pspInfo": {
"pspId": "UNCRITMM",
"businessName": "UniCredit S.p.A",
"idChannel": "00348170101_01_ONUS"
},
"product": "PM"
}]);
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package it.pagopa.ecommerce.helpdesk

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration
import org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration
import org.springframework.boot.runApplication

@SpringBootApplication(exclude = [MongoReactiveAutoConfiguration::class])
@SpringBootApplication(
exclude = [MongoReactiveAutoConfiguration::class, MongoReactiveDataAutoConfiguration::class]
)
class PagopaEcommerceHelpdeskServiceApplication

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package it.pagopa.ecommerce.helpdesk.configurations

import org.springframework.context.annotation.Configuration
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories

@Configuration
@EnableReactiveMongoRepositories(
basePackages = ["it.pagopa.ecommerce.helpdesk.dataproviders.repositories.history"],
reactiveMongoTemplateRef = "ecommerceHistoryReactiveMongoTemplate"
)
class EcommerceHistoryMongoRepositoryConfig {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.springframework.data.mongodb.core.ReactiveMongoTemplate
class MongoEcommerceConfig() {
@Bean(name = ["ecommerceReactiveMongoClient"])
fun ecommerceReactiveMongoClient(
@Value("\${ecommerce.mongodb.uri}") uri: String,
@Value("\${mongodb.uri}") uri: String,
): MongoClient {
val connectionString = ConnectionString(uri)
val settings = MongoClientSettings.builder().applyConnectionString(connectionString).build()
Expand All @@ -24,7 +24,15 @@ class MongoEcommerceConfig() {
@Bean(name = ["ecommerceReactiveMongoTemplate"])
fun ecommerceReactiveMongoTemplate(
@Qualifier("ecommerceReactiveMongoClient") mongoClient: MongoClient,
@Value("\${ecommerce.mongodb.database}") database: String
@Value("\${mongodb.ecommerce.database}") database: String
): ReactiveMongoTemplate {
return ReactiveMongoTemplate(mongoClient, database)
}

@Bean(name = ["ecommerceHistoryReactiveMongoTemplate"])
fun ecommerceHistoryReactiveMongoTemplate(
@Qualifier("ecommerceReactiveMongoClient") mongoClient: MongoClient,
@Value("\${mongodb.ecommerce_history.database}") database: String
): ReactiveMongoTemplate {
return ReactiveMongoTemplate(mongoClient, database)
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ pm.oracle.password=\${PM_ORACLE_PASSWORD}
#spring.data.mongodb.uri=mongodb://\${MONGO_USERNAME}:\${MONGO_PASSWORD}@\${MONGO_HOST}:\${MONGO_PORT}/?ssl=\${MONGO_SSL_ENABLED}&readPreference=secondary&minPoolSize=\${MONGO_MIN_POOL_SIZE}&maxPoolSize=\${MONGO_MAX_POOL_SIZE}&maxIdleTimeMS=\${MONGO_MAX_IDLE_TIMEOUT_MS}&connectTimeoutMS=\${MONGO_CONNECTION_TIMEOUT_MS}&socketTimeoutMS=\${MONGO_SOCKET_TIMEOUT_MS}&serverSelectionTimeoutMS=\${MONGO_SERVER_SELECTION_TIMEOUT_MS}&waitQueueTimeoutMS=\${MONGO_WAITING_QUEUE_MS}&heartbeatFrequencyMS=\${MONGO_HEARTBEAT_FREQUENCY_MS}\${MONGO_REPLICA_SET_OPTION:}
#spring.data.mongodb.database=ecommerce

#Ecommerce mongo database configuration
ecommerce.mongodb.uri=mongodb://\${MONGO_USERNAME}:\${MONGO_PASSWORD}@\${MONGO_HOST}:\${MONGO_PORT}/?ssl=\${MONGO_SSL_ENABLED}&readPreference=secondary&minPoolSize=\${MONGO_MIN_POOL_SIZE}&maxPoolSize=\${MONGO_MAX_POOL_SIZE}&maxIdleTimeMS=\${MONGO_MAX_IDLE_TIMEOUT_MS}&connectTimeoutMS=\${MONGO_CONNECTION_TIMEOUT_MS}&socketTimeoutMS=\${MONGO_SOCKET_TIMEOUT_MS}&serverSelectionTimeoutMS=\${MONGO_SERVER_SELECTION_TIMEOUT_MS}&waitQueueTimeoutMS=\${MONGO_WAITING_QUEUE_MS}&heartbeatFrequencyMS=\${MONGO_HEARTBEAT_FREQUENCY_MS}\${MONGO_REPLICA_SET_OPTION:}
ecommerce.mongodb.database=ecommerce
#Ecommerce mongo database configurations
mongodb.uri=mongodb://\${MONGO_USERNAME}:\${MONGO_PASSWORD}@\${MONGO_HOST}:\${MONGO_PORT}/?ssl=\${MONGO_SSL_ENABLED}&readPreference=secondary&minPoolSize=\${MONGO_MIN_POOL_SIZE}&maxPoolSize=\${MONGO_MAX_POOL_SIZE}&maxIdleTimeMS=\${MONGO_MAX_IDLE_TIMEOUT_MS}&connectTimeoutMS=\${MONGO_CONNECTION_TIMEOUT_MS}&socketTimeoutMS=\${MONGO_SOCKET_TIMEOUT_MS}&serverSelectionTimeoutMS=\${MONGO_SERVER_SELECTION_TIMEOUT_MS}&waitQueueTimeoutMS=\${MONGO_WAITING_QUEUE_MS}&heartbeatFrequencyMS=\${MONGO_HEARTBEAT_FREQUENCY_MS}\${MONGO_REPLICA_SET_OPTION:}
mongodb.ecommerce.database=ecommerce
mongodb.ecommerce_history.database=ecommerce-history


deadLetter.queueMapping=\${SEARCH_DEAD_LETTER_QUEUE_MAPPING}
#PDV configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class MongoEcommerceConfigTest {
private val mongoEcommerceConfig = MongoEcommerceConfig()
private val uri = "mongodb://localhost:27017/test"
private val mongoClient: MongoClient = mongoEcommerceConfig.ecommerceReactiveMongoClient(uri)
val database = "ecommerce"
val database_ecommerce = "ecommerce"
val database_ecommerce_history = "ecommerce-history"

@Test
fun `ecommerceReactiveMongoClient should create MongoClient with correct settings`() {
Expand All @@ -19,10 +20,23 @@ class MongoEcommerceConfigTest {
@Test
fun `ecommerceReactiveMongoTemplate should create ReactiveMongoTemplate with correct client and database`() {
val reactiveMongoTemplate =
mongoEcommerceConfig.ecommerceReactiveMongoTemplate(mongoClient, database)
mongoEcommerceConfig.ecommerceReactiveMongoTemplate(mongoClient, database_ecommerce)

assertThat(reactiveMongoTemplate).isNotNull
assertThat(reactiveMongoTemplate.mongoDatabaseFactory.mongoDatabase.block()?.name)
.isEqualTo(database)
.isEqualTo(database_ecommerce)
}

@Test
fun `ecommerceHistoryReactiveMongoTemplate should create ReactiveMongoTemplate with correct client and database`() {
val reactiveMongoTemplate =
mongoEcommerceConfig.ecommerceHistoryReactiveMongoTemplate(
mongoClient,
database_ecommerce_history
)

assertThat(reactiveMongoTemplate).isNotNull
assertThat(reactiveMongoTemplate.mongoDatabaseFactory.mongoDatabase.block()?.name)
.isEqualTo(database_ecommerce_history)
}
}
7 changes: 4 additions & 3 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ pm.oracle.password=test
#spring.data.mongodb.uri=mongodb://mongo:mongo@$mongo:6080/?ssl=true&replicaSet=globaldb
#spring.data.mongodb.database=ecommerce

#Ecommerce mongo database configuration
ecommerce.mongodb.uri=mongodb://mongo:mongo@$mongo:6080/?ssl=true&replicaSet=globaldb
ecommerce.mongodb.database=ecommerce
#Ecommerce mongo database configurations
mongodb.uri=mongodb://mongo:mongo@$mongo:6081/?ssl=true&replicaSet=globaldb
mongodb.ecommerce.database=ecommerce
mongodb.ecommerce_history.database=ecommerce-history


deadLetter.queueMapping={ ALL: '*', ECOMMERCE: 'pagopa-ecommerce-transactions-dead-letter-queue', NOTIFICATIONS_SERVICE: 'pagopa-ecommerce-notifications-service-errors-queue' }
Expand Down

0 comments on commit 1e70335

Please sign in to comment.