当前位置: 首页>>代码示例>>Java>>正文


Java MDCUtil.put方法代码示例

本文整理汇总了Java中com.icthh.xm.commons.logging.util.MDCUtil.put方法的典型用法代码示例。如果您正苦于以下问题:Java MDCUtil.put方法的具体用法?Java MDCUtil.put怎么用?Java MDCUtil.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.icthh.xm.commons.logging.util.MDCUtil的用法示例。


在下文中一共展示了MDCUtil.put方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPutRid

import com.icthh.xm.commons.logging.util.MDCUtil; //导入方法依赖的package包/类
@Test
public void testPutRid() {
    assertNull(MDCUtil.getRid());
    MDCUtil.put("key", "value");
    assertEquals("value", MDC.get("key"));

    assertNull(MDCUtil.getRid());

    MDCUtil.putRid("myRid");
    assertEquals("myRid", MDCUtil.getRid());
    assertEquals("myRid", MDC.get("rid"));

    MDCUtil.clear();

    assertNull(MDCUtil.getRid());
    assertNull(MDC.get("key"));
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:18,代码来源:MDCUtilTest.java

示例2: main

import com.icthh.xm.commons.logging.util.MDCUtil; //导入方法依赖的package包/类
/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {

    MDCUtil.put();

    SpringApplication app = new SpringApplication(UaaApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    log.info("\n----------------------------------------------------------\n\t" +
            "Application '{}' is running! Access URLs:\n\t" +
            "Local: \t\t{}://localhost:{}\n\t" +
            "External: \t{}://{}:{}\n\t" +
            "Profile(s): \t{}\n----------------------------------------------------------",
        env.getProperty("spring.application.name"),
        protocol,
        env.getProperty("server.port"),
        protocol,
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"),
        env.getActiveProfiles());

    String configServerStatus = env.getProperty("configserver.status");
    log.info("\n----------------------------------------------------------\n\t" +
            "Config Server: \t{}\n----------------------------------------------------------",
        configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:36,代码来源:UaaApp.java

示例3: consumeEvent

import com.icthh.xm.commons.logging.util.MDCUtil; //导入方法依赖的package包/类
/**
 * Consume tenant command event message.
 * @param message the tenant command event message
 */
@Retryable(maxAttemptsExpression = "${application.retry.max-attempts}",
    backoff = @Backoff(delayExpression = "${application.retry.delay}",
        multiplierExpression = "${application.retry.multiplier}"))
public void consumeEvent(ConsumerRecord<String, String> message) {
    MDCUtil.put();
    try {
        log.info("Input message {}", message);
        ObjectMapper mapper = new ObjectMapper()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.registerModule(new JavaTimeModule());
        try {
            SystemEvent event = mapper.readValue(message.value(), SystemEvent.class);
            String command = event.getEventType();
            String userKey = String.valueOf(event.getData().get(Constants.USER_KEY));
            TenantContext.setCurrent(event.getTenantInfo());
            if (Constants.UPDATE_ACCOUNT_EVENT_TYPE.equalsIgnoreCase(command)) {
                log.info("Start to update account for userKey='{}'", userKey);
                User user = userService.getUser(userKey);
                if (user == null) {
                    log.error("Failed to update account. User with userKey='{}' does not exists.", userKey);
                } else {
                    SystemEventMapper.toUser(event, user);
                    userService.saveUser(user);
                }
            }
        } catch (IOException e) {
            log.error("Kafka message has incorrect format ", e);
        }
    } finally {
        MDCUtil.remove();
    }
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:37,代码来源:SystemQueueConsumer.java

示例4: consumeEvent

import com.icthh.xm.commons.logging.util.MDCUtil; //导入方法依赖的package包/类
/**
 * Consume tenant command event message.
 * @param message the tenant command event message
 */
@Retryable(maxAttemptsExpression = "${application.retry.max-attempts}",
    backoff = @Backoff(delayExpression = "${application.retry.delay}",
        multiplierExpression = "${application.retry.multiplier}"))
public void consumeEvent(ConsumerRecord<String, String> message) {
    MDCUtil.put();
    try {
        log.info("Input message {}", message);

    } finally {
        MDCUtil.remove();
    }
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:17,代码来源:SystemTopicConsumer.java

示例5: main

import com.icthh.xm.commons.logging.util.MDCUtil; //导入方法依赖的package包/类
/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {

    MDCUtil.put();

    SpringApplication app = new SpringApplication(EntityApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    log.info("\n----------------------------------------------------------\n\t"
            + "Application '{}' is running! Access URLs:\n\t"
            + "Local: \t\t{}://localhost:{}\n\t"
            + "External: \t{}://{}:{}\n\t"
            + "Profile(s): \t{}\n----------------------------------------------------------",
        env.getProperty("spring.application.name"),
        protocol,
        env.getProperty("server.port"),
        protocol,
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"),
        env.getActiveProfiles());

    String configServerStatus = env.getProperty("configserver.status");
    log.info("\n----------------------------------------------------------\n\t"
            + "Config Server: \t{}\n----------------------------------------------------------",
        configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:36,代码来源:EntityApp.java

示例6: main

import com.icthh.xm.commons.logging.util.MDCUtil; //导入方法依赖的package包/类
/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {

    MDCUtil.put();

    SpringApplication app = new SpringApplication(TimelineApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    log.info("\n----------------------------------------------------------\n\t" +
            "Application '{}' is running! Access URLs:\n\t" +
            "Local: \t\t{}://localhost:{}\n\t" +
            "External: \t{}://{}:{}\n\t" +
            "Profile(s): \t{}\n----------------------------------------------------------",
        env.getProperty("spring.application.name"),
        protocol,
        env.getProperty("server.port"),
        protocol,
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"),
        env.getActiveProfiles());

    String configServerStatus = env.getProperty("configserver.status");
    log.info("\n----------------------------------------------------------\n\t" +
            "Config Server: \t{}\n----------------------------------------------------------",
        configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
}
 
开发者ID:xm-online,项目名称:xm-ms-timeline,代码行数:36,代码来源:TimelineApp.java

示例7: consumeEvent

import com.icthh.xm.commons.logging.util.MDCUtil; //导入方法依赖的package包/类
/**
 * Consume timeline event message.
 *
 * @param message the timeline event message
 */
@Retryable (maxAttemptsExpression = "${application.retry.max-attempts}",
    backoff = @Backoff(delayExpression = "${application.retry.delay}",
        multiplierExpression = "${application.retry.multiplier}"))
public void consumeEvent(ConsumerRecord<String, String> message) {
    MDCUtil.put();
    try {
        log.info("Input message {}", message);
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new JavaTimeModule());
        try {
            XmTimeline xmTimeline = mapper.readValue(message.value(), XmTimeline.class);
            if (CollectionUtils.isNotEmpty(tenantPropertiesService.getTenantProps().getFilter().getExcludeMethod())
                && tenantPropertiesService.getTenantProps().getFilter().getExcludeMethod()
                .contains(xmTimeline.getHttpMethod())) {
                log.debug("Message {} was excluded by http method ", xmTimeline);
                return;
            }
            if (StringUtils.isBlank(xmTimeline.getTenant())) {
                xmTimeline.setTenant(message.topic());
            }
            timelineService.insertTimelines(xmTimeline);
        } catch (IOException e) {
            log.error("Kafka message has incorrect format ", e);
        }
    } finally {
        MDCUtil.remove();
    }
}
 
开发者ID:xm-online,项目名称:xm-ms-timeline,代码行数:34,代码来源:TimelineEventConsumer.java

示例8: consumeEvent

import com.icthh.xm.commons.logging.util.MDCUtil; //导入方法依赖的package包/类
/**
 * Consume tenant command event message.
 * @param message the tenant command event message
 */
@Retryable(maxAttemptsExpression = "${application.retry.max-attempts}",
    backoff = @Backoff(delayExpression = "${application.retry.delay}",
        multiplierExpression = "${application.retry.multiplier}"))
public void consumeEvent(ConsumerRecord<String, String> message) {
    MDCUtil.put();
    try {
        log.info("Input command {}", message);
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new JavaTimeModule());
        try {
            SystemEvent event = mapper.readValue(message.value(), SystemEvent.class);
            String tenant = event.getData().get(Constants.EVENT_TENANT);
            String command = event.getEventType();
            switch (command.toUpperCase()) {
                case Constants.CREATE_COMMAND:
                    kafkaService.createKafkaConsumer(tenant);
                    break;
                case Constants.DELETE_COMMAND:
                    kafkaService.deleteKafkaConsumer(tenant);
                    break;
                default:
                    break;
            }

        } catch (IOException e) {
            log.error("Kafka message has incorrect format ", e);
        }

    } finally {
        MDCUtil.remove();
    }
}
 
开发者ID:xm-online,项目名称:xm-ms-timeline,代码行数:37,代码来源:TenantCommandConsumer.java

示例9: testGetTime

import com.icthh.xm.commons.logging.util.MDCUtil; //导入方法依赖的package包/类
@Test
public void testGetTime() {
    assertTrue(MDCUtil.getTime() == 0);
    MDCUtil.put("key", "value");
    assertTrue(MDCUtil.getExecTime() > 0);
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:7,代码来源:MDCUtilTest.java

示例10: consumeEvent

import com.icthh.xm.commons.logging.util.MDCUtil; //导入方法依赖的package包/类
/**
 * Consume system event message.
 * @param message the system event message
 */
@Retryable(maxAttemptsExpression = "${application.retry.max-attempts}",
    backoff = @Backoff(delayExpression = "${application.retry.delay}",
        multiplierExpression = "${application.retry.multiplier}"))
public void consumeEvent(ConsumerRecord<String, String> message) {
    MDCUtil.put();
    try {
        log.info("Input message {}", message);
        ObjectMapper mapper = new ObjectMapper()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.registerModule(new JavaTimeModule());
        try {
            SystemEvent event = mapper.readValue(message.value(), SystemEvent.class);
            String command = event.getEventType();
            String userKey = String.valueOf(event.getData().get("userKey"));
            TenantContext.setCurrent(event.getTenantInfo());
            switch (command.toUpperCase()) {
                case Constants.CREATE_PROFILE:
                    log.info("Start to create profile for userKey='{}'", userKey);
                    Profile newProfile = profileService.getProfile(userKey);
                    if (newProfile != null) {
                        log.error("Failed to create profile. Profile with userKey='{}' already exists.", userKey);
                        break;
                    }
                    newProfile = new Profile();
                    SystemEventMapper.toProfile(event, newProfile);
                    profileService.save(newProfile);
                    break;
                case Constants.UPDATE_PROFILE:
                    log.info("Start to update profile for userKey='{}'", userKey);
                    Profile oldProfile = profileService.getProfile(userKey);
                    if (null == oldProfile) {
                        log.error("Failed to update profile. Profile with userKey='{}' does not exists.", userKey);
                        break;
                    }
                    SystemEventMapper.toProfile(event, oldProfile);
                    profileService.save(oldProfile);
                    break;
                default:
                    break;
            }

        } catch (IOException e) {
            log.error("Kafka message has incorrect format ", e);
        }
    } finally {
        MDCUtil.remove();
    }
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:53,代码来源:SystemQueueConsumer.java


注:本文中的com.icthh.xm.commons.logging.util.MDCUtil.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。