veluxer62 / veluxer62.github.io

veluxer's blog
http://veluxer62.github.io
MIT License
2 stars 0 forks source link

1월 회고 #510

Closed veluxer62 closed 3 years ago

veluxer62 commented 3 years ago

SCTP

https://developers.redhat.com/blog/2018/01/03/sctp-stream-schedulers/

veluxer62 commented 3 years ago

가비지 컬렉션 관련 글

https://medium.com/javarevisited/jvm-garbage-collection-basics-edce6791ae98

veluxer62 commented 3 years ago

bull

https://github.com/OptimalBits/bull

veluxer62 commented 3 years ago

graalvm

https://www.graalvm.org/

veluxer62 commented 3 years ago

몽고 세션 정리

veluxer62 commented 3 years ago

anti corruption layer

부패방지 계층

veluxer62 commented 3 years ago

kotlin에서 Entity 클래스 사용 시 getter를 따로 만들지 않고 인스턴스 변수를 사설로 사용할 수 있는 방법

@Entity
class MessageHistory(
    @Id
    val id: UUID = UUID.randomUUID(),

    phoneNumber: String,
) {
    @Column
    final var phoneNumber: String = phoneNumber
        private set

    fun test() {
        phoneNumber = "ddd"
    }
}
veluxer62 commented 3 years ago

Kotlin에서 @JsonCreator를 사용하는 경우 아래와 같이 사용하면 된다

enum class MessageResultCode(private val code: String) {
    KAKAO_SUCCESS("1000"),
    KAKAO_UNKNOWN_NUMBER("4001"),
    KAKAO_NOT_SUPPORTED_NUMBER("4002"),
    KAKAO_ERROR("9999"),
    LMS_SUCCESS("R000"),
    LMS_UNKNOWN_NUMBER("R500"),
    LMS_BLOCKED_NUMBER("R501"),
    LMS_ERROR("R502");

    companion object {
        @JsonCreator
        @JvmStatic
        fun fromCode(code: String): MessageResultCode {
            return values().first { it.code == code }
        }
    }
}
veluxer62 commented 3 years ago

Kotlin JPA 사용시 Entity의 setter를 외부에서 사용하지 못하도록 하는 방법에 대한 고민

https://multifrontgarden.tistory.com/272

JPA가 내부적으로 Entity의 proxy를 생성하여 Entity를 상속하여 사용하는 것처럼 보임 그래서 private setter인 경우 오류가 발생함

protected setter를 사용하는 경우 final 키워드를 사용하지 않아도 됨

Entity는 기본적으로 mutable 변수를 써야하므로 val를 쓰는것은 추천하지 않음

고민 결과 최선의 코드

@Entity
class MessageHistory(
    promotionId: UUID,
    phoneNumber: String,
    content: String,
) {
    @Id
    var id: UUID = UUID.randomUUID()
        protected set

    @Column(nullable = false)
    var promotionId = promotionId
        protected set

    @Column(nullable = false)
    var createdAt: ZonedDateTime = ZonedDateTime.now()
        protected set

    @Column
    @Enumerated(STRING)
    var provider: Provider? = null
        protected set

    @Column(nullable = false)
    @Enumerated(STRING)
    var status = REQUESTED
        protected set

    @Column(nullable = false)
    var phoneNumber = phoneNumber
        protected set

    @Column(length = 4000)
    var content = content
        protected set

    @Column
    var sentAt: ZonedDateTime? = null
        protected set

    @Column
    var responseAt: ZonedDateTime? = null
        protected set

    @Column
    @Enumerated(STRING)
    var resultCode: MessageResultCode? = null
        protected set

    fun changeStatusToSend(provider: Provider) {
        if (status != REQUESTED) {
            throw DomainException("이미 전송된 메시지 이력은 전송상태로 변경할 수 없습니다.")
        }

        this.provider = provider
        this.status = SENT
        this.sentAt = ZonedDateTime.now()
    }

    fun putResponseResult(code: MessageResultCode) {
        if (status != SENT) {
            throw DomainException("전송되지 않은 메시지는 전송결과를 저장할 수 없습니다.")
        }

        status = code.getHistoryStatus()
        responseAt = ZonedDateTime.now()
        resultCode = code
    }
}

lazy loading을 쓰고자 한다면 gradle에 아래와 같은 설정을 넣어줘야 함

allOpen {
    annotation("javax.persistence.Entity")
    annotation("javax.persistence.MappedSuperclass")
    annotation("javax.persistence.Embeddable")
}
noArg {
    annotation("javax.persistence.Entity")
    annotation("javax.persistence.MappedSuperclass")
    annotation("javax.persistence.Embeddable")
}
veluxer62 commented 3 years ago

jpa open-in-view

https://gracelove91.tistory.com/100

veluxer62 commented 3 years ago

JMS Listener 에서 동시성 처리하려면 아래와 같이 하면됨

@JmsListener(destination = MESSAGE_SEND_REQUEST, concurrency = "3-10")
veluxer62 commented 3 years ago

Kafka topic convention

https://devshawn.com/blog/apache-kafka-topic-naming-conventions/

veluxer62 commented 3 years ago

대학 수학 지식 관련 PDF

https://venhance.github.io/napkin/Napkin.pdf

veluxer62 commented 3 years ago

Jackson

enum 소문자로 표시할때

enum class Provider {
    KAKAO,
    LMS;

    @JsonValue
    fun getKey() = this.name.toLowerCase()
}
veluxer62 commented 3 years ago

JPA EntityGraph 이슈

interface DocumentRepository : JpaRepository<Document, Long> {
    @EntityGraph(attributePaths = ["approvalLines"])
    fun findByDrafter(drafter: String): List<Document>

    fun findByApprovalLinesAssignment(assignment: String): List<Document>

    @EntityGraph(attributePaths = ["approvalLines"])
    fun findByDrafterOrApprovalLinesAssignment(drafter: String, assignment: String): List<Document>
}
veluxer62 commented 3 years ago

소나큐브

https://www.sonarqube.org/

veluxer62 commented 3 years ago

wasp zap

보안 감사 도구

https://www.zaproxy.org/

veluxer62 commented 3 years ago

인터페이스 구현체로 빈을 주입하는 경우 java dynamic proxy가 생긴다 클래스를 직접 주입하면 CGLIB이 동작한다.

CGLIB이 성능적으로 뛰어나다 그이유는 컴파일 단계에서 프록시 파일을 생성하기 때문이다.

만약 인터페이스 구현체도 CGLIB을 사용하도록 하려면

@EnableAspectJAutoProxy(proxyTargetClass = true) 을 사용하자

근데 설정없이 인터페이스로 주입해보니 CGLIB으로 프록시가 생성되네???