반응형

상황

@Document 어노테이션 indexName 에 datePattern 넣는 방법

해결

@Document(indexName = "test-index-#{@elasticsearchIndexPattern.getToday()}", createIndex = false)
public class TestLog {
    @Id
    private String id;

    @Field(type= FieldType.Text)
    private String title;

    @Field(type= FieldType.Ip)
    private String ip;

    @Field(type= FieldType.Keyword)
    private String data;
}

위 코드에 @다음 부분에 아래 component 와 함수 호출을 넣어주면 된다.

@Component
public class ElasticsearchIndexPattern {
    public String getToday() {
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        Date date = new Date();
        return dateFormat.format(date);
    }
}

 

추가 의문

getToday() 함수는 언제언제 호출 될까?

-> ES operation 이 작동할 때마다 호출이 돼서 날짜가 바로바로 반영이 된다.

 

https://stackoverflow.com/questions/24333327/rolling-index-dynamic-index-name-in-spring-data-elasticsearch

반응형
반응형

상황

kafka 의 jvm 옵션을 보니 Xms 와 Xmx 가 같게 설정되어 있어서 찾아보게 되었다

답변

1. 힙 크기를 늘릴 때 OS 에 추가 메모리를 요청해야 하므로 시간이 걸린다 (GC 가 처리되었던 요청의 응답시간에 추가됨)

2. JVM 은 힙으로 늘린 메모리를 다시 해제하지 않아 결국엔 Xmx 값이 된다

3. 힙 크기를 늘리는 작업은 stop-the-world 이벤트여서 이를 방지할 수 있다 

4. Xms 가 작게 시작하는 경우 GC 가 더 많이 발생하게 됨

5. 일반적으로 다른 앱과 메모리 경쟁을 하지 않는 경우에 이렇게 설정

 

 

https://stackoverflow.com/questions/43651167/is-there-any-advantage-in-setting-xms-and-xmx-to-the-same-value

https://developer.jboss.org/thread/149559

반응형

'java' 카테고리의 다른 글

Using @PageableDefault in webflux  (0) 2022.04.20
[spring boot] jooq query logging / show sql  (0) 2020.08.05
[java] jar 압축 해제  (0) 2020.08.03
[java][test] JSON 같은지 비교  (0) 2020.07.17
[Guava] cache simple example  (0) 2020.06.03
반응형
  • WebFlux Controller에 Paging 적용하려고 하니
@RequiredArgsConstructor
@RestController
public class PlayerController {

    private final MemberRepository memberRepository;

    @GetMapping("/members")
    public List<Member> requestMembers(@PageableDefault(size = 10) Pageable pageable) {
        return memberRepository.findAll(pageable);
    }
}
 
  • 아래와 같이 에러 발생
No primary or default constructor found for interface org.springframework.data.domain.Pageable
  • WebfluxConfig 추가 필요
@Configuration
@ConditionalOnClass(EnableWebFlux.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
public class WebfluxConfig implements WebFluxConfigurer {
    @Override
    public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
        configurer.addCustomResolver(new ReactivePageableHandlerMethodArgumentResolver());
    }
}

 

 

https://stackoverflow.com/questions/50730446/resolving-pageable-in-webflux

 

반응형

'java' 카테고리의 다른 글

[java] JVM 옵션 -Xms 와 -Xmx 를 같게 하는 이유  (0) 2022.05.26
[spring boot] jooq query logging / show sql  (0) 2020.08.05
[java] jar 압축 해제  (0) 2020.08.03
[java][test] JSON 같은지 비교  (0) 2020.07.17
[Guava] cache simple example  (0) 2020.06.03
반응형

상황

React Functional Component로 HOC 를 만들어보자

(CUSTOM hooks를 사용하는 방법도 있음)

해결

const withSomething = WrappedComponent => {

    // 대문자로 시작 안하면, Lint 에서 에러 발생 (compile error)
    const Hoc = (props) => {
        useEffect(() => {
           // something
        }, []);

        return <WrappedComponent {...props}/>
    };

    return Hoc;
};

export default withSomething;
반응형
반응형

상황

토픽을 생성한 적이 없는데, produce 하는 것만으로 토픽이 자동 생성됐다

처리

확인해보니

auto.create.topics.enable = true 가 기본값

 

https://kafka.apache.org/documentation/#auto.create.topics.enable

반응형
반응형

상황

jOOQ 에서 실행되는 SQL 을 show, print, logging 해보자

해결법

1. Listener 생성

public class LoggingExecuteListener extends DefaultExecuteListener {

	@Override
	public void executeStart(ExecuteContext ctx) {
		// Create a new DSLContext for logging rendering purposes
		// This DSLContext doesn't need a connection, only the SQLDialect...
		DSLContext create = DSL.using(ctx.dialect(),
				// ... and the flag for pretty-printing
				new Settings().withRenderFormatted(true));
		// If we're executing a query
		if (ctx.query() != null) {
			System.out.println(create.renderInlined(ctx.query()));
		} else if (ctx.routine() != null) {
			// If we're executing a routine
			System.out.println(create.renderInlined(ctx.routine()));
		} else if (ctx.batchQueries() != null) {
			// If we're executing a batch queries
			Arrays.stream(ctx.batchQueries()).forEach(query -> System.out.println(create.renderInlined(query)));
		}
	}
}

2. ListenerProvider Bean 생성

@Bean
public ExecuteListenerProvider executeListenerProvider() {
    return new DefaultExecuteListenerProvider(new LoggingExecuteListener());
}

 

 

출처

https://www.jooq.org/doc/3.13/manual/sql-execution/execute-listeners 

https://www.jooq.org/doc/latest/manual/sql-building/queryparts/pretty-printing/

반응형

'java' 카테고리의 다른 글

[java] JVM 옵션 -Xms 와 -Xmx 를 같게 하는 이유  (0) 2022.05.26
Using @PageableDefault in webflux  (0) 2022.04.20
[java] jar 압축 해제  (0) 2020.08.03
[java][test] JSON 같은지 비교  (0) 2020.07.17
[Guava] cache simple example  (0) 2020.06.03
반응형
반응형
반응형

상황

WHERE 절이 아닌 가져오는 칼럼이 NULL 이나 빈 값이면 다른 칼럼 가져오기

해결

SELECT IF(col1 IS NULL or col1 = '', col2, col1) as col FROM TABLE

 

SELECT IF(CONDITION, IF_TRUE_VALUE, IF_FALSE_VALUE) FROM TABLE

 

 

출처

https://stackoverflow.com/questions/8470813/how-do-i-check-if-a-column-is-empty-or-null-in-mysql

반응형
반응형

상황

반복문으로 나온 Element 를 이용해서 if 조건으로 style을 넣기

해결

 <tr th:each="element: ${Elements}" th:inline="text" th:style="${element.name == 'kimxavi' ? 'font-weight: bold;' : ''}">
 <tr/>

 

반응형

'HTML CSS' 카테고리의 다른 글

[CSS] a 태그 글자에 밑 줄 제거하기  (0) 2020.01.08
[thymeleaf] HTML 태그 넣기  (0) 2019.12.14
반응형

상황

특정 문자열이 들어가지 않은 데이터 조회하고 싶다

해결

SELECT * FROM TABLE WHERE FIELD_NAME NOT LIKE '%STRING%';
반응형

+ Recent posts