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


Java HystrixCommand类代码示例

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


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

示例1: testCommandToPublisher

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
@Test
public void testCommandToPublisher() throws Exception {
    // Given
    HystrixCommand<InputStream> command = new InputStreamTestCommand();
    final Publisher<CommandHelperTestData> publisher = CommandHelper.toPublisher(CommandHelperTestData.class, mapper,
            command);
    final List<CommandHelperTestData> receivedData = new ArrayList<>();

    // When
    Flux.from(publisher).subscribe(receivedData::add);

    // Then
    assertEquals(3, receivedData.size());
    assertEquals("1", receivedData.get(0).getValue());
    assertEquals("2", receivedData.get(1).getValue());
    assertEquals("3", receivedData.get(2).getValue());
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:18,代码来源:CommandHelperTest.java

示例2: updateColumn

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
@RequestMapping(value = "/api/datasets/{datasetId}/column/{columnId}", method = POST, consumes = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Update a dataset.", consumes = APPLICATION_JSON_VALUE, //
        notes = "Update a data set based on content provided in POST body with given id. For documentation purposes, body is typed as 'text/plain' but operation accepts binary content too.")
@Timed
public void updateColumn(@PathVariable(value = "datasetId") @ApiParam(value = "Id of the dataset to update") final String datasetId,
                         @PathVariable(value = "columnId") @ApiParam(value = "Id of the column to update") final String columnId,
                         @ApiParam(value = "content") final InputStream body) {

    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating or updating dataset #{} (pool: {})...", datasetId, getConnectionStats());
    }

    final HystrixCommand<Void> creation = getCommand(UpdateColumn.class, datasetId, columnId, body);
    creation.execute();

    LOG.debug("Dataset creation or update for #{} done.", datasetId);
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:18,代码来源:DataSetAPI.java

示例3: execute

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
@Override
public HystrixCommand<T> execute(EndpointCall<R> call, Object[] args) {
	return new HystrixCommand<T>(hystrixMetadata()) {
		@Override
		protected T run() throws Exception {
			return delegate.execute(call, args);
		}

		protected T getFallback() {
			return fallback == null ? super.getFallback() : doFallback();
		}

		private T doFallback() {
			HystrixCommandFallback hystrixCommandFallback = Optional.ofNullable(fallback)
					.map(f -> new HystrixCommandFallback(endpointMethod, args, fallback))
						.orElse(null);

			HystrixCommand<T> value = hystrixCommandFallback.run();
			return value.execute();
		};
	};
}
 
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:23,代码来源:HystrixCommandEndpointCallExecutable.java

示例4: bottle

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
/**
 * [SLEUTH] TraceCommand
 */
@Override
public void bottle(Wort wort, String processId, String testCommunicationType) {
    log.info("I'm in the bottling service");
    log.info("Process ID from headers {}", processId);
    String groupKey = "bottling";
    String commandKey = "bottle";
    HystrixCommand.Setter setter = HystrixCommand.Setter
            .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
            .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
    TestConfigurationHolder testConfigurationHolder = TestConfigurationHolder.TEST_CONFIG.get();
    new TraceCommand<Void>(tracer, traceKeys, setter) {
        @Override
        public Void doRun() throws Exception {
            TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder);
            log.info("Sending info to bottling service about process id [{}]", processId);
            bottlerService.bottle(wort, processId);
            return null;
        }
    }.execute();
}
 
开发者ID:spring-cloud-samples,项目名称:brewery,代码行数:24,代码来源:Bottler.java

示例5: mailTo

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
@RequestMapping(value = "/api/mail", method = PUT)
@ApiOperation(value = "Send feedback to Talend")
@Timed
public void mailTo(@RequestBody MailDetails mailDetails) {
    if (mailDetails.isEmpty()) {
        throw new TDPException(APIErrorCodes.UNABLE_TO_GET_MAIL_DETAILS);
    }
    try {

        final HystrixCommand<Void> sendFeedback = getCommand(MailToCommand.class, mailDetails);
        sendFeedback.execute();

    } catch (Exception e) {
        throw new TDPException(APIErrorCodes.UNABLE_TO_SEND_MAIL, e);
    }

}
 
开发者ID:Talend,项目名称:data-prep,代码行数:18,代码来源:MailServiceAPI.java

示例6: create

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
/**
 * Create a dataset from request body content.
 *
 * @param name           The dataset name.
 * @param contentType    the request content type used to distinguish dataset creation or import.
 * @param dataSetContent the dataset content from the http request body.
 * @return The dataset id.
 */
@RequestMapping(value = "/api/datasets", method = POST, produces = TEXT_PLAIN_VALUE)
@ApiOperation(value = "Create a data set", produces = TEXT_PLAIN_VALUE, notes = "Create a new data set based on content provided in POST body. For documentation purposes, body is typed as 'text/plain' but operation accepts binary content too. Returns the id of the newly created data set.")
@Timed
public Callable<String> create(
        @ApiParam(value = "User readable name of the data set (e.g. 'Finance Report 2015', 'Test Data Set').") @RequestParam(defaultValue = "", required = false) String name,
        @ApiParam(value = "An optional tag to be added in data set metadata once created.") @RequestParam(defaultValue = "", required = false) String tag,
        @ApiParam(value = "Size of the data set, in bytes.") @RequestParam(defaultValue = "0") long size,
        @RequestHeader(CONTENT_TYPE) String contentType, @ApiParam(value = "content") InputStream dataSetContent) {
    return () -> {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating dataset (pool: {} )...", getConnectionStats());
        }
        try {
            HystrixCommand<String> creation = getCommand(CreateDataSet.class, name, tag, contentType, size, dataSetContent);
            return creation.execute();
        } finally {
            LOG.debug("Dataset creation done.");
        }
    };
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:29,代码来源:DataSetAPI.java

示例7: update

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
@RequestMapping(value = "/api/datasets/{id}", method = POST, produces = TEXT_PLAIN_VALUE)
@ApiOperation(value = "Update a dataset.", produces = TEXT_PLAIN_VALUE, //
        notes = "Update a data set based on content provided in POST body with given id. For documentation purposes, body is typed as 'text/plain' but operation accepts binary content too.")
@Timed
public Callable<String> update(@ApiParam(value = "Id of the data set to update / create") @PathVariable(value = "id") String id,
                     @ApiParam(value = "content") InputStream dataSetContent) {
    return () -> {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating or updating dataset #{} (pool: {})...", id, getConnectionStats());
        }
        HystrixCommand<String> creation = getCommand(UpdateDataSet.class, id, dataSetContent);
        String result = creation.execute();
        LOG.debug("Dataset creation or update for #{} done.", id);
        return result;
    };
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:17,代码来源:DataSetAPI.java

示例8: commandKeyIsRequestLineSetterFactory

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
@Bean
public SetterFactory commandKeyIsRequestLineSetterFactory() {
	return new SetterFactory() {
		@Override public HystrixCommand.Setter create(Target<?> target,
			Method method) {
			String groupKey = SETTER_PREFIX + target.name();
			RequestMapping requestMapping = method
				.getAnnotation(RequestMapping.class);
			String commandKey =
				SETTER_PREFIX + requestMapping.method()[0] + " " + requestMapping
					.path()[0];
			return HystrixCommand.Setter
				.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
				.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
		}
	};
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:18,代码来源:FeignClientTests.java

示例9: testHystrixSetterFactory

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
@Test
public void testHystrixSetterFactory() {
	HystrixCommand<List<Hello>> command = this.hystrixSetterFactoryClient
		.getHellosHystrix();
	assertNotNull("command was null", command);
	String setterPrefix = TestHystrixSetterFactoryClientConfig.SETTER_PREFIX;
	assertEquals(
		"Hystrix command group name should match the name of the feign client with a prefix of "
			+ setterPrefix, setterPrefix + "localapp5",
		command.getCommandGroup().name());
	assertEquals(
		"Hystrix command key name should match the request method (space) request path with a prefix of "
			+ setterPrefix, setterPrefix + "GET /hellos",
		command.getCommandKey().name());
	List<Hello> hellos = command.execute();
	assertNotNull("hellos was null", hellos);
	assertEquals("hellos didn't match", hellos, getHelloList());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:19,代码来源:FeignClientTests.java

示例10: itShouldCreateDeviceCertificateSuccessfully

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
@Test
public void itShouldCreateDeviceCertificateSuccessfully() {
    DeviceCertClient sut = Clients.simpleDeviceCertClient(BASE_ENDPOINT);

    CreateDeviceCertificateRequestDto request = CreateDeviceCertificateRequestDto.builder()
            .devicePublicKey(ANY_PUBLIC_KEY)
            .build();

    HystrixCommand<CreateDeviceCertificateResponseDto> deviceCertificateRequest = sut
            .createDeviceCertificate(DEMO_APP_ID, DEMO_API_KEY, request);

    CreateDeviceCertificateResponseDto deviceCertificateResponse = deviceCertificateRequest.execute();

    assertThat(deviceCertificateResponse, is(notNullValue()));
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:16,代码来源:DeviceCertClientIT.java

示例11: itShouldCreateDeviceCertificateSuccessfully

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
@Test
public void itShouldCreateDeviceCertificateSuccessfully() throws JsonProcessingException {
    CreateDeviceCertificateResponseDto deviceCertificate = CreateDeviceCertificateResponseDtoObjectMother.random();
    String deviceCertificateAsJson = Clients.defaultObjectMapper.writeValueAsString(deviceCertificate);

    MockClient mockClient = new MockClient()
            .add(HttpMethod.POST, "/api/v1/device_certificates", Response.builder()
                    .status(HttpStatus.CREATED.value())
                    .reason(HttpStatus.CREATED.getReasonPhrase())
                    .headers(Collections.<String, Collection<String>>emptyMap())
                    .body(deviceCertificateAsJson, Charsets.UTF_8));

    Target<DeviceCertClient> mockTarget = new MockTarget<DeviceCertClient>(DeviceCertClient.class);

    DeviceCertClient sut = Clients.simpleFeignBuilder()
            .client(mockClient)
            .build()
            .newInstance(mockTarget);

    CreateDeviceCertificateRequestDto request = CreateDeviceCertificateRequestDto.builder()
            .build();

    HystrixCommand<CreateDeviceCertificateResponseDto> deviceCertificateRequest = sut
            .createDeviceCertificate(RANDOM_APP_ID, RANDOM_API_KEY, request);

    CreateDeviceCertificateResponseDto deviceCertificateResponse = deviceCertificateRequest.execute();

    assertThat(deviceCertificateResponse, is(notNullValue()));
    assertThat(deviceCertificateResponse.getDeviceCertificate(), is(deviceCertificate.getDeviceCertificate()));
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:31,代码来源:DeviceCertClientTest.java

示例12: itShouldFetchAccessCertificatesSuccessfully

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
@Test
public void itShouldFetchAccessCertificatesSuccessfully() throws JsonProcessingException {
    GetAccessCertificatesResponseDto accessCertificatesResponseDto = GetAccessCertificatesResponseDtoObjectMother.random();
    String accessCertificatesResponseDtoAsJson = Clients.defaultObjectMapper.writeValueAsString(accessCertificatesResponseDto);

    MockClient mockClient = new MockClient()
            .add(HttpMethod.GET, String.format("/api/v1/device/%s/access_certificates", RANDOM_DEVICE_SERIAL), Response.builder()
                    .status(HttpStatus.OK.value())
                    .reason(HttpStatus.OK.getReasonPhrase())
                    .headers(Collections.<String, Collection<String>>emptyMap())
                    .body(accessCertificatesResponseDtoAsJson, Charsets.UTF_8));

    Target<AccessCertClient> mockTarget = new MockTarget<AccessCertClient>(AccessCertClient.class);

    AccessCertClient sut = Clients.simpleFeignBuilder()
            .client(mockClient)
            .build()
            .newInstance(mockTarget);

    HystrixCommand<GetAccessCertificatesResponseDto> accessCertificatesRequest = sut
            .fetchAccessCertificates("", "", RANDOM_DEVICE_SERIAL);

    GetAccessCertificatesResponseDto accessCertificatesResponse = accessCertificatesRequest.execute();

    assertThat(accessCertificatesResponse, is(notNullValue()));
    assertThat(accessCertificatesResponse, is(accessCertificatesResponseDto));
    assertThat(accessCertificatesResponse.getAccessCertificates(), hasSize(accessCertificatesResponseDto.getAccessCertificates().size()));
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:29,代码来源:AccessCertClientTest.java

示例13: setter

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
private static Setter setter() {
    HystrixCommandGroupKey groupkey = HystrixCommandGroupKey.Factory.asKey("rpc");
    HystrixCommandKey commandkey = HystrixCommandKey.Factory.asKey("say");
    HystrixThreadPoolKey threadpoolkey = HystrixThreadPoolKey.Factory.asKey("hello-1");
    HystrixThreadPoolProperties.Setter threadproperties = HystrixThreadPoolProperties.Setter()//
                    .withCoreSize(20).withKeepAliveTimeMinutes(5).withMaxQueueSize(1000).withQueueSizeRejectionThreshold(100);

    HystrixCommandProperties.Setter commandproperty = HystrixCommandProperties.Setter()//
                    .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD)//
                    .withFallbackEnabled(true).withFallbackIsolationSemaphoreMaxConcurrentRequests(100)//
                    .withExecutionIsolationThreadInterruptOnFutureCancel(true)//
                    .withExecutionIsolationThreadInterruptOnTimeout(true)//
                    .withExecutionTimeoutEnabled(true).withExecutionTimeoutInMilliseconds(1000);
    return HystrixCommand.Setter.withGroupKey(groupkey).andCommandKey(commandkey)//
                    .andThreadPoolKey(threadpoolkey).andThreadPoolPropertiesDefaults(threadproperties)//
                    .andCommandPropertiesDefaults(commandproperty);
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:18,代码来源:HelloDegrade.java

示例14: setter

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
private static Setter setter() {
    HystrixCommandGroupKey groupkey = HystrixCommandGroupKey.Factory.asKey("rpc");
    HystrixCommandKey commandkey = HystrixCommandKey.Factory.asKey("say");
    HystrixThreadPoolKey threadpoolkey = HystrixThreadPoolKey.Factory.asKey("hello-1");
    HystrixThreadPoolProperties.Setter threadproperties = HystrixThreadPoolProperties.Setter()//
                    .withCoreSize(20).withKeepAliveTimeMinutes(5).withMaxQueueSize(1000).withQueueSizeRejectionThreshold(100);

    HystrixCommandProperties.Setter commandproperty = HystrixCommandProperties.Setter()//
                    .withCircuitBreakerEnabled(true).withCircuitBreakerForceClosed(false)//
                    .withCircuitBreakerForceOpen(false).withCircuitBreakerErrorThresholdPercentage(50)//
                    .withCircuitBreakerRequestVolumeThreshold(20)//
                    .withCircuitBreakerSleepWindowInMilliseconds(5000);
    return HystrixCommand.Setter.withGroupKey(groupkey).andCommandKey(commandkey)//
                    .andThreadPoolKey(threadpoolkey).andThreadPoolPropertiesDefaults(threadproperties)//
                    .andCommandPropertiesDefaults(commandproperty);
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:17,代码来源:HelloBreaker.java

示例15: create

import com.netflix.hystrix.HystrixCommand; //导入依赖的package包/类
@Override
public HystrixCommand.Setter create(Target<?> target, Method method) {
  String groupKey = target.name();
  String commandKey = Feign.configKey(target.type(), method);
  return HystrixCommand.Setter
      .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
      .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:9,代码来源:SetterFactory.java


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