'config'에 해당되는 글 3건

  1. 2017.02.07 [HttpClient] Timeout 설정 예시
  2. 2016.02.12 [Logstash] Dynamic Config Reloading
  3. 2012.05.22 [C언어] 설정파일 읽기

[HttpClient] Timeout 설정 예시

ITWeb/개발일반 2017.02.07 13:41

HttpClient를 사용하면서 간혹 read timeout 이나 connection timeout 등이 발생 할 때가 있습니다.

그럴때 값을 조정해서 사용하시면 됩니다.


- 문서링크

setConnectionRequestTimeout

public RequestConfig.Builder setConnectionRequestTimeout(int connectionRequestTimeout)


setConnectTimeout

public RequestConfig.Builder setConnectTimeout(int connectTimeout)


setSocketTimeout

public RequestConfig.Builder setSocketTimeout(int socketTimeout)



아래 예시는 10초로 설정한 내용입니다.

HttpPost request = new HttpPost(url);


RequestConfig requestConfig = RequestConfig.custom()

  .setSocketTimeout(10*1000)

  .setConnectTimeout(10*1000)

  .setConnectionRequestTimeout(10*1000)

  .build();


request.setConfig(requestConfig);


저작자 표시 비영리 변경 금지
신고
Trackback 0 : Comment 0

[Logstash] Dynamic Config Reloading

Elastic/Logstash 2016.02.12 10:57

예전에도 있던 기능 이였는지는 잘 모르겠습니다.

그래서 기록해 봅니다.


원문링크)


한 줄 요약)

--auto-reload --reload-interval 옵션을 통해 logstash 재시작 없이 설정 적용이 가능 합니다.


명령어 예시)

bin/logstash -f config_file --auto-reload --reload-interval 2

※ 원문에 나와 있는 예시 입니다.

※ 기본 reload interval 은 3초로 정의 되어 있습니다.


이 기능을 제공하는 Version은 logstash 2.2 이상 입니다.

저작자 표시 비영리 변경 금지
신고
Trackback 0 : Comment 0

[C언어] 설정파일 읽기

ITWeb/개발일반 2012.05.22 23:17

[Build & Run]

gcc -c config.c; gcc config.o -o config

./config /home/jjeong/workspace/config/config.property

[config.property]

# UserAuthUrl
UserAuthUrl^http://192.168.1.2:8080/rcpt_auth?email=%s
# UserAuthCompareStr
UserAuthCompareStr^verified
# DlAuthUrl
DlAuthUrl^http://192.168.1.2:8080/dlCheck?q={filterSearch:'%s'}
# DlAuthCompareStr
DlAuthCompareStr^SUCCESS
# AhfServer
AhfServer^192.168.1.2
# AhfPort
AhfPort^33000
#AhfUser
AhfUser^jjeong
#AhfPass
AhfPass^1234
#AhfDb
AhfDb^demodb
#AhfQuery
AhfQuery^SELECT * FROM event WHERE id='%s'
#SkipDomain
SkipDomain^jjeong.com

[config.c]

#include <stdio.h>

#include <stdlib.h>
#include <string.h>
#include <ctype.h>

typedef struct config {
        char userAuthUrl[256];
        char userAuthCompareStr[128];
        char dlAuthUrl[256];
        char dlAuthCompareStr[128];
        char ahfServer[128];
        int ahfPort;
        char ahfUser[128];
        char ahfPass[128];
        char ahfDb[128];
        char ahfQuery[128];
        char skipDomain[128];
} CONFIG;

int isBlank(char ch) {
    return ( (ch==0x20) || (ch=='\t') || (ch=='\r') || (ch=='\n') );
}

char *trim( char *s ) {
    char *f=s, *e=0, *c=s;

    /* 뒤쪽 공백 제거 */
    e=s +(strlen(s)) -1;
    while( isBlank(*e) && s<=e) e--;
    *(e+1)=0;

    /* 앞쪽 공백 제거 */
    while( isBlank(*f) && f<=e) f++;

    /* 공백 없는 부분 복사 */
    if (s!=f) {
        while(f<=e) *(c++) = *(f++);
        *c=0;
    }

    return s;
}

int setConfig(CONFIG *conf, char *confFile) {
        char readBuff[512];
        char varBuff[256];
        char *temp;

        FILE *fp;

        memset(varBuff, 0, 256);

        fp = fopen(confFile, "r");

        if ( fp ){
                while ( !feof(fp) ) {
                        memset(readBuff, 0, 512);

                        if ( fgets(readBuff, 512, fp) == NULL ) {
                                continue;
                        }

                        temp = trim(readBuff);

                        if ( *temp == '#' ) {
                                continue;
                        }

                        if ( strncasecmp(temp, "UserAuthUrl", strlen("UserAuthUrl")) == 0 ) {
                                strcpy(conf->userAuthUrl, strrchr(temp, '^')+1);
                                snprintf(varBuff, sizeof(varBuff), conf->userAuthUrl, "sadfasdfsafasfsdafsafsadf");
                                printf("UserAuthUrl : %s\n", varBuff);
                                memset(varBuff, 0, 256);
                        }

                        if ( strncasecmp(temp, "UserAuthCompareStr", strlen("UserAuthCompareStr")) == 0 ) {
                                strcpy(conf->userAuthCompareStr, strrchr(temp, '^')+1);
                                printf("UserAuthCompareStr : %s\n", conf->userAuthCompareStr);
                        }

                        if ( strncasecmp(temp, "DlAuthUrl", strlen("DlAuthUrl")) == 0 ) {
                                strcpy(conf->dlAuthUrl, strrchr(temp, '^')+1);
                                snprintf(varBuff, sizeof(varBuff), conf->dlAuthUrl, "mail@jjeong.com");
                                printf("DlAuthUrl : %s\n", varBuff);
                                memset(varBuff, 0, 256);

                        }

                        if ( strncasecmp(temp, "DlAuthCompareStr", strlen("DlAuthCompareStr")) == 0 ) {
                                strcpy(conf->dlAuthCompareStr, strrchr(temp, '^')+1);

                                if ( strstr("SUCCESS", conf->dlAuthCompareStr) ) {
                                        printf("DlAuthCompareStr SUCCESS\n");
                                }
                                printf("DlAuthCompareStr : %s\n", conf->dlAuthCompareStr);
                        }

                        if ( strncasecmp(temp, "AhfServer", strlen("AhfServer")) == 0 ) {
                                strcpy(conf->ahfServer, strrchr(temp, '^')+1);
                                printf("AhfServer : %s\n", conf->ahfServer);
                        }

                        if ( strncasecmp(temp, "AhfPort", strlen("AhfPort")) == 0 ) {
                                conf->ahfPort = atoi(strrchr(temp, '^')+1);
                                printf("AhfPort : %d\n", conf->ahfPort);
                        }

                        if ( strncasecmp(temp, "AhfUser", strlen("AhfUser")) == 0 ) {
                                strcpy(conf->ahfUser, strrchr(temp, '^')+1);
                                printf("AhfUser : %s\n", conf->ahfUser);
                        }

                        if ( strncasecmp(temp, "AhfPass", strlen("AhfPass")) == 0 ) {
                                strcpy(conf->ahfPass, strrchr(temp, '^')+1);
                                printf("AhfPass : %s\n", conf->ahfPass);
                        }

                        if ( strncasecmp(temp, "AhfDb", strlen("AhfDb")) == 0 ) {
                                strcpy(conf->ahfDb, strrchr(temp, '^')+1);
                                printf("AhfDb : %s\n", conf->ahfDb);
                        }

                        if ( strncasecmp(temp, "AhfQuery", strlen("AhfQuery")) == 0 ) {
                                strcpy(conf->ahfQuery, strrchr(temp, '^')+1);
                                snprintf(varBuff, sizeof(varBuff), conf->ahfQuery, "TEST");
                                printf("AhfQuery: %s\n", varBuff);
                                memset(varBuff, 0, 256);
                        }

                        if ( strncasecmp(temp, "SkipDomain", strlen("SkipDomain")) == 0 ) {
                                strcpy(conf->skipDomain, strrchr(temp, '^')+1);
                                printf("SkpDomain : %s\n", conf->skipDomain);
                        }

                }
        } else {
        }

        fclose(fp);

        return 1;
}


int main(int argc, char *argv[]) {
        CONFIG conf;

        printf("file full path : %s\n", argv[1]);

        setConfig(&conf, argv[1]);

        return 1;
}

일부 코드는 레퍼런스 코드 가져다 사용하였습니다.

뭐 이런 종류의 코드는 구글링 하면 많이 나오니까.. ^^;;

신고
tags : c, config, Property
Trackback 0 : Comment 0