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


Java HystrixCommand类代码示例

本文整理汇总了Java中com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand的典型用法代码示例。如果您正苦于以下问题:Java HystrixCommand类的具体用法?Java HystrixCommand怎么用?Java HystrixCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HystrixCommand类属于com.netflix.hystrix.contrib.javanica.annotation包,在下文中一共展示了HystrixCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findByName

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
/**
 * Fetch users with the specified name. A partial case-insensitive match is
 * supported. So <code>http://.../user/rest</code> will find any users with
 * upper or lower case 'rest' in their name.
 *
 * @param name
 * @return A non-null, non-empty collection of users.
 */
@HystrixCommand(fallbackMethod = "defaultUsers")
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Collection<User>> findByName(@RequestParam("name") String name) {
    logger.info(String.format("user-service findByName() invoked:%s for %s ", userService.getClass().getName(), name));
    name = name.trim().toLowerCase();
    Collection<User> users;
    try {
        users = userService.findByName(name);
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Exception raised findByName REST Call", ex);
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
    return users.size() > 0 ? new ResponseEntity<>(users, HttpStatus.OK)
            : new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Microservices-with-Java-9-Second-Edition,代码行数:24,代码来源:UserController.java

示例2: findById

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
/**
 * Fetch restaurants with the given id.
 * <code>http://.../v1/restaurants/{restaurant_id}</code> will return
 * restaurant with given id.
 *
 * @param id
 * @return A non-null, non-empty collection of restaurants.
 */
@HystrixCommand(fallbackMethod = "defaultRestaurant")
@RequestMapping(value = "/{restaurant_id}", method = RequestMethod.GET)
public ResponseEntity<Entity> findById(@PathVariable("restaurant_id") String id) {
    logger.info(String.format("restaurant-service findById() invoked:{} for {} ", restaurantService.getClass().getName(), id));
    id = id.trim();
    Entity restaurant;
    try {
        restaurant = restaurantService.findById(id);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Exception raised findById REST Call {0}", ex);
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
    return restaurant != null ? new ResponseEntity<>(restaurant, HttpStatus.OK)
            : new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Microservices-with-Java-9-Second-Edition,代码行数:24,代码来源:RestaurantController.java

示例3: indexedData

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = HYSTRIX_FALL_BACK,
        commandKey = HYSTRIX_COMMAND_KEY,
        groupKey = HYSTRIX_GROUP_KEY)
@Scheduled(fixedDelay = 60000)
public void indexedData() {

    log.info("SEARCH-SERVICE: Data indexer is starting to work.");

    currentPageIndex = getCurrentPageIndex();

    log.info("Current page for pushing is {}", currentPageIndex);

    long totalPage = tweetClient.getTweets().getMetadata().getTotalPages();

    for (long i = currentPageIndex; i <= totalPage; i++) {
        Runnable task = new PusherProcessor(tweetRepository, tweetClient, i);
        taskExecutor.execute(task);

        currentPageIndex = i++;

        saveCurrentPageIndex(i);
    }
}
 
开发者ID:thinksky-sourcecode,项目名称:microservices-prototype,代码行数:24,代码来源:DataService.java

示例4: retrieveGroup

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@Override
@CachePut(cacheNames = "RetrieveGroup", key = "#groupId")
@HystrixCommand(fallbackMethod = "retrieveGroupFallback", ignoreExceptions = IllegalArgumentException.class)
public Group retrieveGroup(String groupId) {
    Assert.hasLength(groupId, "retrieveGroup input is empty");
    Group group = groupRepository.findOne(groupId);
    if(group == null){
        logger.warn("No group with id={} was found.", groupId);
        return new Group();
    }
    return group;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:13,代码来源:AdministrativeServiceImpl.java

示例5: cats

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "dogs")
Message cats() {
  URI uri = UriComponentsBuilder.fromUriString("//backend/cats")
    .build()
    .toUri();

  Message message;
  try {
    message = rest.getForObject(uri, Message.class);
  } catch (Exception e) {
    log.error(e.getMessage());
    throw e;
  }

  return message;
}
 
开发者ID:mcwumbly,项目名称:cats-and-dogs-scs,代码行数:17,代码来源:BackendClient.java

示例6: createStory

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "fallbackCreateStory", ignoreExceptions = IllegalArgumentException.class)
public String createStory(String username, StoryRequest storyRequest) {
    Assert.notNull(storyRequest, "createStory input is null");

    Story story = new Story.Builder()
            .userId(username)
            .geolocation(storyRequest.getGeolocation())
            .title(storyRequest.getTitle())
            .story(storyRequest.getStory())
            .groupId(storyRequest.getGroupId())
            .build();

    storyRepository.save(story);

    return Constants.OK;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:18,代码来源:StoryServiceImpl.java

示例7: deleteStory

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "fallbackDeleteStory", ignoreExceptions = IllegalArgumentException.class)
public String deleteStory(String storyId, String userId) {
    Assert.hasLength(storyId, "deleteStory input was null or empty");

    Story story = storyRepository.findById(storyId);
    if(!userId.equals(story.getUserId()))
        throw new UnauthorizedUserException("Unauthorized user for this action");

    storyRepository.delete(storyId);
    return Constants.OK;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:13,代码来源:StoryServiceImpl.java

示例8: retrieveGroupIds

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@Override
@CachePut(cacheNames = "RetrieveGroupIds", key = "#username")
@HystrixCommand(fallbackMethod = "retrieveGroupIdsFallback", ignoreExceptions = IllegalArgumentException.class)
public List<String> retrieveGroupIds(String username) {
    Assert.hasLength(username, "retrieveGroupIds input is empty or null");
    if (!userRepository.exists(username)) {
        logger.warn("No user with id={} was found.", username);
        return new ArrayList<>();
    }

    List<String> followingGroupIds = userRepository.getGroupIdsByUsername(username).getFollowingGroupIds();
    return followingGroupIds;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:14,代码来源:AdministrativeServiceImpl.java

示例9: getStoriesOfGroup

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@Override
@CachePut(cacheNames = "HotStoriesOfGroup", key = "#groupId")
@HystrixCommand(fallbackMethod = "hotStoriesOfGroupFallback", ignoreExceptions = IllegalArgumentException.class)
public List<Story> getStoriesOfGroup(String groupId) {
    Assert.hasLength(groupId, "Hot stories of group input was null or empty");
    return storyRepository.findHotStoriesOfGroup(groupId);
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:8,代码来源:HotStoriesService.java

示例10: createUser

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "createUserFallback", ignoreExceptions = IllegalArgumentException.class)
public String createUser(UserRequest userRequest) {
    Assert.notNull(userRequest, "createUser input is null");

    if (userRepository.exists(userRequest.getUsername())) {
        logger.warn("User with id={} is already registered.", userRequest.getUsername());
        return Constants.NOK;
    }
    authClient.createUser(generateRegistrationUser(userRequest));

    User user = new User.Builder()
            .gender(userRequest.getGender())
            .name(userRequest.getName())
            .surname(userRequest.getSurname())
            .username(userRequest.getUsername())
            .build();
    userRepository.save(user);

    return Constants.OK;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:22,代码来源:AdministrativeServiceImpl.java

示例11: addFollowing

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "addFollowingFallback", ignoreExceptions = IllegalArgumentException.class)
public String addFollowing(String username, String followingUsername) {
    Assert.hasLength(followingUsername, "addFollowing input is empty");

    User user = userRepository.findByUsername(username);
    if (user == null) {
        logger.warn("No user with id={} was found.", username);
        return Constants.NOK;
    }
    if (!userRepository.exists(followingUsername)) {
        logger.warn("No user with id={} was found", followingUsername);
        return Constants.NOK;
    }
    if (user.getFollowingIds().contains(username)) {
        logger.warn("User with id={} is already following {}", username, followingUsername);
        return Constants.NOK;
    }

    user.addFollowingId(followingUsername);
    userRepository.save(user);

    return Constants.OK;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:25,代码来源:AdministrativeServiceImpl.java

示例12: removeFollowing

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "removeFollowingFallback", ignoreExceptions = IllegalArgumentException.class)
public String removeFollowing(String username, String followingUsername) {
    Assert.hasLength(username, "removeFollowing input is empty or null");
    Assert.hasLength(followingUsername, "removeFollowing input is empty or null");

    User user = userRepository.findByUsername(username);
    if (user == null) {
        logger.warn("No user with id={} was found.", username);
        return Constants.NOK;
    }

    user.removeFollowingId(followingUsername);
    userRepository.save(user);

    return Constants.OK;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:18,代码来源:AdministrativeServiceImpl.java

示例13: test

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "testFallback")
@GetMapping("/test/{v}")
public String test(@PathVariable("v") Long v){
    try{
        Thread.sleep(v);
    }catch(Exception e){

    }
    return "normal test response";
}
 
开发者ID:carycui,项目名称:parkingcloud,代码行数:11,代码来源:UserController.java

示例14: getComments

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "defaultComments")
public List<Comment> getComments(Image image) {
	return restTemplate.exchange(
		"http://COMMENTS/comments/{imageId}",
		HttpMethod.GET,
		null,
		new ParameterizedTypeReference<List<Comment>>() {
		},
		image.getId()).getBody();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:11,代码来源:CommentHelper.java

示例15: hystrixMethod

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "fallback")
@GetMapping
String hystrixMethod(){
    if (RandomUtils.nextInt(10) > 5) {
        return "Bingo!";
    }
    throw new RuntimeException();
}
 
开发者ID:kchrusciel,项目名称:Spring-Boot-Examples,代码行数:9,代码来源:HystrixController.java


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